Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Linear and Exponential Chirp Functions

300 views
Skip to first unread message

telefunkenvf14

unread,
Jun 29, 2010, 8:40:13 AM6/29/10
to
Group:

A while back I needed an exponential chirp function and was only able
to track down a linear version by Will Robertson. Hopefully someone
will find these useful.

linearChirp::usage = "linearChirp[f0_, f1_, t_, T_] generates a linear
chirp signal with initial frequency f0 and ending frequency f1 at time
T seconds; t represents the time index variable."

expChirp::usage = "expChirp[f0_, f1_, t_, T_] generates an exponential
chirp signal with initial frequency f0 and ending frequency f1 at time
T seconds; t represents the time index variable."

Attributes[linearChirp] = {NumericFunction}
linearChirp[f0_, f1_, t_, T_] :=Sin[2*Pi*t*(f0 + ((f1 - f0)/T*t)/2)]

Attributes[expChirp] = {NumericFunction}
expChirp[f0_, f1_, t_, T_] :=Sin[(2*f0*(-1 + (f1/f0)^(t/T))*Pi*T)/
Log[f1/f0]]

------------------------------------ Example Uses
------------------------------------------
(*Just gives you the function; plug a value in for t to get the
function value*)
linearChirp[10, 30, t, 1]

(*Compare plots... change the 10 to a 1 to see more of a difference*)
Plot[linearChirp[10, 30, t, 1], {t, 0, 1}]
Plot[expChirp[10, 30, t, 1], {t, 0, 1}]

(*Create a 40 second expChirp with starting frequency 20Hz, ending
frequency 400Hz. Evaluate[] forces the function to evaluate first---
speeds things up. Note that SampleDepth and SampleRate are overkill
for this example; my goal was to avoid digital shenanigans later.*)

Play[Evaluate@expChirp[20, 400, t, 40], {t, 0, 40}, SampleDepth -> 24,
SampleRate -> 44100]]

-RG


0 new messages