Reputation: 154
I want to generate a periodic square wave (Signal/Pulse) in Octave/Matlab with the following properties:
So far I have this:
T = 1/10;
t = linspace(0,T,1001);
y = square(2*pi*50*t);
plot(t,y);
axis([0 0.1 -1.5 1.5]);
That produces this result:
As you may see the amplitude is not correct but since I am a total newbie, I have no idea how to fix it. The period is correct but I'm still not sure what is this average value in the graphical point of view...
Upvotes: 0
Views: 8467
Reputation: 1544
this should be pretty fast and straightforward to write, checkout my implementation.
function y=square(t)
% License: public domain
t=t*(1/(pi));
y=ones(size(t));
y(find(bitand(abs(floor(t)),1)))=-1;
a test script:
t = -0.02:.001:.0625;
y = 0.5*square(2*pi*30*t);
plot(t,y,'-o')
Upvotes: 1