简体   繁体   English

用Matlab实现正弦波相位谱

[英]Phase spectrum of sine wave with Matlab

I'm trying to plot a phase spectrum of sine wave with Matlab. 我正在尝试用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]');

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. 尝试随机改变每个光谱分量的相位,转换回时域(使用ifft ),你仍然可以恢复正弦曲线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM