Pawel
Pawel

Reputation: 29

Phase spectrum of sine wave with Matlab

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]');

Upvotes: 3

Views: 5577

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

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.

Upvotes: 2

Related Questions