Generating a rect FUNCTION
Generating a rect FUNCTION
(OP)
Hello,
I'd like to generate a function:
x(t) = rect[(t-1)/2]
therefore,
x(t) = 1; 0<=t<=2
x(t) = 0; otherwise
I've tried sampling using a for loop, but I can't seem to create a graphable collection of points ( I always end up with one point). What's the solution?
Here's a sample of my code:
clc;
w = -10:0.05:10;
t = -4:0.01:4;
x = 0;
X = 2*sinc(w/pi).*exp(-j*w);
%plot (w, X);
%xlabel('w');
%ylabel('X(w)');
if 0<=t<=2
x = 1;
else
x = 1;
end
plot (t,x);
This code gives me a straight line at 1 within my window.
I'd like to generate a function:
x(t) = rect[(t-1)/2]
therefore,
x(t) = 1; 0<=t<=2
x(t) = 0; otherwise
I've tried sampling using a for loop, but I can't seem to create a graphable collection of points ( I always end up with one point). What's the solution?
Here's a sample of my code:
clc;
w = -10:0.05:10;
t = -4:0.01:4;
x = 0;
X = 2*sinc(w/pi).*exp(-j*w);
%plot (w, X);
%xlabel('w');
%ylabel('X(w)');
if 0<=t<=2
x = 1;
else
x = 1;
end
plot (t,x);
This code gives me a straight line at 1 within my window.





RE: Generating a rect FUNCTION
...
else
x = 0;
end
...
This change makes no difference in the output.
RE: Generating a rect FUNCTION
x = t>=0 & t <=2;
plot(t,x)
That should do it
M
--
Dr Michael F Platten
RE: Generating a rect FUNCTION