I want to help someone with a homework in signal processing, and the courses he provided are some slides, without clear definitions in them. I am required in solving a problem to represent the amplitude spectrum and the phase spectrum of a given signal. I searched the internet and didn't found the definitions of these two. I want to create a Matlab script for these, but if I don't know the definitions I cannot do that. Please give me the definitions for these.

  • Amplitude spectrum
  • Phase spectrum

If there is a Matlab command, or some other program which plots these spectrums directly, I would be very interested. Thank you.

  • $\begingroup$ See e.g. this. $\endgroup$ – user276 Nov 1 '11 at 14:02
  • $\begingroup$ mathworks.com/help/toolbox/control/ref/bode-plot.html $\endgroup$ – datageist Nov 1 '11 at 14:04
  • 1
    $\begingroup$ Do you mean a discrete signal or a periodic signal (you said both with an "or" in there)? If you're wanting amplitude/phase plots of a continuous-time signal (that might be periodic), then you'll use different methods than if you have a discrete-time signal. $\endgroup$ – Jason R Nov 1 '11 at 14:20
  • $\begingroup$ I meant for a discrete signal or discrete periodic signal. $\endgroup$ – Beni Bogosel Nov 1 '11 at 14:29

Beni I think you want something like this:

samplingFrequency = 1000; % / Hz 
signalFrequency = 50;     % / Hz
signalLength = 500;
signal = cos(2*pi*signalFrequency./ samplingFrequency .*[0:1:signalLength - 1]);
[hh ff] = freqz(signal, 1, 2048, samplingFrequency);
ylabel('Amplitude in log scale');
xlabel('Frequency / Hz');
plot(ff, angle(hh)); 
xlabel('Frequency / Hz');

You do have MATLAB correct?... if you do try it and let me know how else I can help.

enter image description here enter image description here enter image description here

Well, a couple things. First off, remember, since this is a digital signal, it means of course that it was sampled at some frequency $samplingFrequency= 128 or 127$ in your case. The physical frequency of your signal in this case seems to be $signalFrequency = 21$.

The ratio of $\frac{signalFrequency}{samplingFrequency}$ is equal to the $f_0$ in your case. This is called the 'digital frequency'.

For your problem it sounds like he also wants you to fix the fft size, (change the 2048 in my code to 128) and the rest of the numbers as I described and run the code. Does he mention how long he wants your signal to be?

  • $\begingroup$ Thank you for your answer and your time, but I would like something like this: jhu.edu/signals/spectra/ampscale.html I want to create separate graphs for amplitude(magnitude) spectrum and phase spectrum. $\endgroup$ – Beni Bogosel Nov 1 '11 at 20:30
  • $\begingroup$ @BeniBogosel If you run the code it will give you the plots. I edited the answer to include them for you. $\endgroup$ – Spacey Nov 1 '11 at 20:36
  • $\begingroup$ Ok. Thank you, I've got those polts. One of my problems says to calculate the amplitude and phase spectrum for the signal $x(n)=\cos(2\pi f_0 n)$ in $N=128$ points for $f_0=21/128$ and $f_0=21/127$ and explain the differences. That means that signal length is 128, sampling sequence is 1, and frequency is $f_0$? $\endgroup$ – Beni Bogosel Nov 1 '11 at 20:59
  • $\begingroup$ @BeniBogosel I edited the end of the answer since it was too long to type here. Have a look and tell me how else I can help. $\endgroup$ – Spacey Nov 1 '11 at 21:57
  • $\begingroup$ Thank you. It looks a bit different. I will study this problem more tomorrow. Thank you very much for your help. :) $\endgroup$ – Beni Bogosel Nov 1 '11 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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