From help-request at octave dot org Tue Apr 11 12:29:26 2006 Subject: Re: square waves From: NZG To: help at octave dot org Cc: Paul Kienzle , Doug Stewart Date: Tue, 11 Apr 2006 12:24:16 -0500 > What is wrong with the following? Nothing at all, it's quite elegant actually. thank you. NZG > axis([-0.1 1.1 -1.1 1.1]) > t=[0:0.001:1]; > > # A 7 Hz square wave sampled at 1kHz with a .25 duty cycle > plot(t,square(2*pi*t*7,0.25)) > > # A 7 Hz sine wave > plot(t,sin(2*pi*t*7)) > > If you are using really coarse sampling then you are probably better > off using a stem plot: > > t=[0:0.01:1];stem(t,square(2*pi*t*7,0.25)) > > Stairs is misleading because of the aliasing. > > t=[0:0.01:1];stairs(t,square(2*pi*t*7,0.25)) > > If you just want to plot the edges, then you can use e.g., > > f=7;duty=0.25; > t=[[0:1/f:1];[0:1/f:1]+duty/f](:); > stairs(t,(-1).^[0:length(t)-1]) > > - Paul > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------