I want to generate a signal which frequency are obtained. For example,I want the frequency domain similiar to this one: enter image description here So I use the following code:

fs =44100; 
t = 0:1/fs:4; 
f = 800 + 500*sin(2*pi*t); 
x = sin(2*pi*f);

But using Adobe Audition to visualize its spectrogram. enter image description here

It looks different from my hope. So how can I generate a signal if already have freqency?

  • $\begingroup$ your code is plain wrong; why is there a sine in your f formula? $\endgroup$ Aug 16, 2016 at 14:20

1 Answer 1


Your code is wrong because when you want to get a signal whose frequency changes with time, then the argument of the sine you generate is given by the integral of the function you want to generate in frequency (see https://en.wikipedia.org/wiki/Chirp). That's why, in your case, your f function should be:

$f(t)=\int_0^t800+500\sin{2\pi t}=\phi_0 + 800t -\frac{500}{2\pi} \cos(2\pi t)$

If you set the zero phase $\phi_0=0$, then you would obtain the signal you are looking for. Apart from that, take into account that if you just want that signal in the positive part of the spectrum of your double sided spectrum, then you should do $e^{if(t)}$, because if you just take the sine of $f(t)$ then the signal would be replicated in your negative side of the spectrum.

  • $\begingroup$ Thank you!Reading your answer,I know how to do it.fs =44100; t = 0:1/fs:4; f= 800 + 300*sin(2*pi*t); x = sin(cumsum(f)/fs*2*pi); spectrogram(x,512,256,512,fs,'yaxis'); $\endgroup$
    – partida
    Aug 17, 2016 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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