Discussion:
Making an audio chirp
(too old to reply)
Wonky
2006-10-12 06:39:02 UTC
Permalink
I need an audio chirp, 20Hz-20kHz, 48000 samples/sec, 10 seconds. I
tried
t=0:1/48000:10;
x=linspace(20,20000,length(t));
s=sin(2*pi.*x*t); # generate the chirp
sm=(s*((2^15)-1))+(2^15); # use 16 bit signed integers, rather than
floats

That produced a chirp at 48000 samples/sec, for 10 seconds; fft of the
whole thing indicated success, but piecewise fft revealed that it
increased linearly in frequency to 24kHz after 6 seconds, then fell
back to about 8200Hz. It appears to be a chirp from 20Hz to about
42kHz. I tried replacing the "linspace..." line with
x=(1998*t) + 20;
since that produces a linearly increasing quantity from 20 to 20000,
but it made no difference (I compared the result of linspace(...) and
this; the maximum variation was less than 10^-12).

Can anyone see what I've done wrong, and/or suggest a better way to
achieve what I want?

TIA
fishcustard
Wonky
2006-10-12 06:43:34 UTC
Permalink
Post by Wonky
...
s=sin(2*pi.*x*t); # generate the chirp
Sorry, that should, of course, be

s=sin(2*pi*x.*t); # generate the chirp

Wonky
Salomon Janhunen
2006-10-12 16:30:12 UTC
Permalink
Post by Wonky
Can anyone see what I've done wrong, and/or suggest a better way to
achieve what I want?
It appears you have a problem with aliasing. I suggest using
1/4 of your sampling rate as the maximum frequency.

Perhaps a much slower frequency increase rate would also
help (as I gather the Nyquist limit for your signal would be
about 24000 Hz).
Pierre Asselin
2006-10-12 16:37:49 UTC
Permalink
Post by Wonky
I need an audio chirp, 20Hz-20kHz, 48000 samples/sec, 10 seconds. I
tried
t=0:1/48000:10;
x=linspace(20,20000,length(t));
s=sin(2*pi.*x*t); # generate the chirp
You want s= sin(2*pi*phi), where dphi/dt is the time-dependent frequency
that you want. I get
phi(t)= phi0 + ( f1*(t-t0)^2 - f0*(t1-t)^2 ) / (t1-t0)
(Done with arrays s, phi of course.)
Post by Wonky
It appears to be a chirp from 20Hz to about 42kHz.
I would guess 20 Hz to 39.98 kHz.
--
pa at panix dot com
Tom
2006-10-13 15:45:35 UTC
Permalink
Post by Wonky
I need an audio chirp, 20Hz-20kHz, 48000 samples/sec, 10 seconds. I
tried
t=0:1/48000:10;
x=linspace(20,20000,length(t));
s=sin(2*pi.*x*t); # generate the chirp
sm=(s*((2^15)-1))+(2^15); # use 16 bit signed integers, rather than
floats
That produced a chirp at 48000 samples/sec, for 10 seconds; fft of the
whole thing indicated success, but piecewise fft revealed that it
increased linearly in frequency to 24kHz after 6 seconds, then fell
back to about 8200Hz. It appears to be a chirp from 20Hz to about
42kHz. I tried replacing the "linspace..." line with
x=(1998*t) + 20;
since that produces a linearly increasing quantity from 20 to 20000,
but it made no difference (I compared the result of linspace(...) and
this; the maximum variation was less than 10^-12).
Can anyone see what I've done wrong, and/or suggest a better way to
achieve what I want?
TIA
fishcustard
help chirp (GNU Octave 2.1.50 on Windoz)
Tom

Continue reading on narkive:
Loading...