0
$\begingroup$

I'm trying to create a chirp/swept signal that has it's frequency going down exponentially using matlab/octave. I can't use the built in chirp function because I'm trying to create a chirp/swept signal based on an equation/formula. I tried creating some code below but as you see from the spectrogram the frequency does not end at the correct frequency, and the frequency doesn't go down exponentially.

clear all,clc
freq1=20; %start freq
freq2=200; %end freq
fs=44100;
dur=1; %duration of signal in seconds

t = linspace(0,2*pi,fs*dur);

f=freq1:(freq2-freq1)/length(t):freq2-(freq2-freq1)/length(t); 
%20:(200-20)/lenght(t) :200-(200-20)/length(t)

data=sin(f.*t); %build signal
data=(data/max(abs(data))*.8); %normalize signal
wavwrite([data'] ,fs,32,strcat('/tmp/del.wav')); %export file
plot(t,data)

Here's a spectrogram plot spectrogram plot

My goal:

1) create a signal based on a given equation/formula where the frequency is exponentially decaying (based on the formula 1/exp)

2) be able to type in the starting and ending frequency along with it's duration in seconds example startfreq=20; endfreq=200; durseconds=2;

The spectrogram plot should look something like this if the start frequency is 200hz ending at 20hz.

Any ideas?

what the spectrogram should look like

$\endgroup$

closed as off-topic by Dilip Sarwate, Peter K. Mar 19 '14 at 0:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions requesting working code written to a specification are off-topic as they are unlikely to benefit anyone else. Instead, describe the problem you're solving and where you're stuck." – Peter K.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This is too close to asking for software designed to a specification. $\endgroup$ – Peter K. Mar 19 '14 at 0:03
4
$\begingroup$

Frequency is the derivative of phase, so you need to start with the expression for frequency, which in your case is
$f=200\exp(-\alpha*t)$

At time $t=0$ this will have the frequency of 200, but we need to solve for $\alpha$ so that the frequency at time $t=2$ is 20. Solving for $\alpha$ gives $\alpha=1.1513$. To get the correct expression for the phase you need to integrate the above expression for the phase i.e. solve

$f =\frac{1}{2\pi}\frac{d\phi}{dt}$

The following matlab code generates this signal.

fs=500; %sampling frequency
t=(0:2*fs)/fs; %Time vector
alpha=1.1513;
sig = exp(-j*2*pi*200/alpha*exp(-alpha*t));

Note that just because the instantaneous frequency behaves this way doesn't mean the spectrogram will follow it exactly. It will get better if you have a higher time-bandwidth product.

$\endgroup$
  • $\begingroup$ thanks so much..I'm trying to work the problem but I'm a little confused. How did you get? $$\alpha$$. I couldn't figure out how you got 1.1513. $$\left[ \alpha={{\log \left({{200}\over{f}}\right)}\over{t}} \right] {\tt }$$ $\endgroup$ – Rick T Feb 18 '14 at 0:01
  • 1
    $\begingroup$ @RickT Your other requirement was for the frequency to be 20 at time $t=2$, substituting those numbers into the equation for $f$ gives $20=200\exp(-\alpha*2)$. Solving for $\alpha$ gives $\alpha=-\frac{1}{2}\ln (20/200)$. $\endgroup$ – David Feb 18 '14 at 13:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.