Reputation: 5823
I am trying to produce a swept square or triangle wave. The chirp
function produces a swept cosine wave; is there a way to do this with the square or sawtooth waves? My approach right now, at least for something like a square wave, is
V = A*chirp(t,f0,t1,f1, 'linear', -90); %#change the cosine wave to a sine wave
V(V<0) = -A;
V(V>0) = A;
I can do the same type of thing with a triangle wave, but it's a little more annoying.
Generally speaking, is there a more straightforward way?
Upvotes: 1
Views: 1171
Reputation: 283733
The swept-frequency is the same as evaluating a function
function(2 * pi * integral(f(t) dt))
where f(t)
, the time-varying frequency, is linear with time.
Just write the equation for a line in two-points form:
f(t) = f0 + (t - t0) * (f1 - f0) / (t1 - t0)
and integrate:
function(phase0 + 2*pi*f0*t + pi * (t - t0)**2 * (f1 - f0) / (t1 - t0))
The simplest form of this is when t0 = f0 = phase0 = 0
, then you get:
function(k * t**2)
Upvotes: 2