3

I'm trying to plot a phase spectrum of sine wave with Matlab. Below I attach code, I can't attach diagrams due to the lack of reputations. As magnitude spectrum seems to be good, the phase spectrum seems to be uncorrect, it's like a noise. Do you have any idea why?

clear all;

fs=8000;
l=1000;
t=1/fs*(1:l);

x1=sin(2*pi()*1000*t);
spec_x1=fft(x1,1000);
magnitude=2*abs(spec_x1)/l;
phase=angle(spec_x1)*180/pi;

figure
plot(fs/2*linspace(0,1,500),magnitude(1:500));
title('Magnitude spectrum');
xlabel('F[Hz]');
ylabel('Magnitude');

figure
plot(fs/2*linspace(0,1,500),phase(1:500));
title('Phase spectrum');
xlabel('F[Hz]');
ylabel('Phase [degrees]');
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
Pawel
  • 29
  • 1
  • 3

1 Answers1

2

Phase of a frequency component is ill-defined (and meaningless) when the magnitude is so low. Try randomly changing the phase for each spectral component, convert back to time-domain (with ifft), and you'll still recover a sinusoid.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • thanks a lot. that was a problem. I have one question more: I made signal which is a sum of four sinusoids: `x1=sin(2*pi()*1000*t); x2=sin(2*pi()*2000*t); x3=cos(2*pi()*3000*t); x4=sin(2*pi()*3500*t); x5=x1+x2+x4+x3;` When I plotted a magnitude spectrum of x5, I received four peaks. Three of them have the same value=1, but the fourth one (for 3500Hz) has a value something about 0.65. What's the reason? Shouldn't they have the same values as the amplitudes of sinusoids are the same? – Pawel Sep 26 '13 at 13:10
  • As you rise the sinusoid frequency towards 4000 Hz (Nyquist rate), the representation of the sinusoid is less accurate, which causes a "smearing" of the energy in a wider range of spectral components. Note that, as the peak gets lower, nearby components have increasing amplitudes. The total energy of the sinusoid is the same, but it gets over more frequencies as a result of its less accurate representation. If you `plot (t,x4)` and zoom in you'll see that inaccuracy. In other words, part of the sinuosoid is transformed into noise, and you see that noise spectrum in the frequency plot. – Luis Mendo Sep 26 '13 at 15:09