[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: square waves
From: |
Paul Kienzle |
Subject: |
Re: square waves |
Date: |
Sat, 8 Apr 2006 06:48:14 -0400 |
On Apr 7, 2006, at 10:12 PM, Doug Stewart wrote:
NZG wrote:
Is there a function for generating square waves in octave?
If you know how many 1s and zeros you need then you can do it this way:
a(100)=0;
b(250)=0;
b=b+1;
c=[a b a b a b a b]
or do some for loops ;-)
You can vectorize the above:
n = 8*350;
x=zeros(1,n);
x(mod([0:n-1],9)>=100) = 1;
Octave-forge has the compatibility functions pulstran and rectpuls
which can do the same thing:
n = 8*350;
x = pulstran([1:n],[101:350:n],'rectpuls',250);
I'm not sure that's any easier though.
See also the function square just added to octave-forge.
- Paul
--
## s = square(t,duty)
##
## Generate a square wave of period 2 pi with limits +1/-1.
##
## If the duty cycle is specified, the square wave is +1 for
## that portion of the time.
##
## on time
## duty cycle = ------------------
## on time + off time
##
function v = square (t,duty)
if nargin == 1,
duty = .5;
elseif nargin != 2,
usage('v = square(t [, duty])');
endif
t /= 2*pi;
v = ones(size(t));
v(t-floor(t) >= duty) = -1;
endfunction
-------------------------------------------------------------
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
-------------------------------------------------------------
- square waves, NZG, 2006/04/07
- Re: square waves, Doug Stewart, 2006/04/07
- Re: square waves,
Paul Kienzle <=
- Re: square waves, NZG, 2006/04/10
- Re: square waves, NZG, 2006/04/10
- Re: square waves, Keith Goodman, 2006/04/10
- Re: square waves, Paul Kienzle, 2006/04/10
- Re: square waves, NZG, 2006/04/11
Message not available