1MATLAB仿真实验傅里叶变换与信号频谱图本实验将简要介绍如何利用FFT函数描绘指定信号的频谱图像。一、相关函数1、FFT函数离散傅里叶(Fourier)变换函数。【语法】Y=fft(X)Y=fft(X,n)Y=fft(X,[],dim)Y=fft(X,n,dim)相关函数:IFFT(x)逆傅里叶变换。【例1】画出函数y(t)的图像。t=0:0.001:0.6;x=sin(2*pi*50*t)+sin(2*pi*120*t);y=x+2*randn(size(t));plot(1000*t(1:50),y(1:50))title('SignalCorruptedwithZero-MeanRandomNoise')xlabel('time(milliseconds)')205101520253035404550-8-6-4-20246SignalCorruptedwithZero-MeanRandomNoisetime(milliseconds)050100150200250300350400450500020406080100120140Frequencycontentofyfrequency(Hz)例1图像例2图像【例2】画出函数y(t)的傅里叶变换图像。Y=fft(y,512);Pyy=Y.*conj(Y)/512;f=1000*(0:256)/512;plot(f,Pyy(1:257))title('Frequencycontentofy')xlabel('frequency(Hz)')2、CONJ函数复数的共轭。如果Z是一个复数(组),则conj(Z)=real(Z)-i*imag(Z)其中real(Z)、imag(Z)分别代表Z的实部和虚部。二、频谱图像生成程序1、()sin(100)fttp=的频谱图【程序】t=0:.001:.25;x=sin(2*pi*50*t)y=x;Y=fft(y,256);Pyy=Y.*conj(Y)/256;f=1000/256*(0:127);plot(f,Pyy(1:128));title('Powerspectraldensity');xlabel('Frequency(Hz)');3【图像】00.050.10.150.20.25-1-0.8-0.6-0.4-0.200.20.40.60.810501001502002503003504004505000102030405060PowerspectraldensityFrequency(Hz)(a)时域图f(t)(b)频域图F(ω)图1Sin(100πt)的频谱图为便于处理,这里只画出信号频谱的正实部,虚部隐去。2、()2sin(100)fttpp=+的频谱图【程序】t=0:.001:.25;x=2*sin(2*pi*50*t+pi)y=x;Y=fft(y,256);Pyy=Y.*conj(Y)/256;f=1000/256*(0:127);plot(f,Pyy(1:128));title('Powerspectraldensity');xlabel('Frequency(Hz)');【图像】400.050.10.150.20.25-2-1.5-1-0.500.511.52050100150200250300350400450500050100150200250PowerspectraldensityFrequency(Hz)(a)时域图f(t)(b)频域图F(ω)图22Sin(100πt+π)的频谱图3、()sin(100)2sin(280)ftttpp=+的频谱图【程序】t=0:.001:.25;x=sin(2*pi*50*t)+2*sin(2*pi*140*t)y=x;Y=fft(y,256);Pyy=Y.*conj(Y)/256;f=1000/256*(0:127);plot(f,Pyy(1:128));title('Powerspectraldensity');xlabel('Frequency(Hz)');【图像】00.050.10.150.20.25-3-2-10123050100150200250300350400450500050100150200250PowerspectraldensityFrequency(Hz)(a)时域图f(t)(b)频域图F(ω)图3Sin(100πt)+2Sin(280πt)的频谱图54、()(100)(280)ftSintCostpp=g的频谱图调制信号sin(100)tp,载波cos(280)tp。【程序】t=0:.001:.25;x=sin(2*pi*50*t).*cos(2*pi*140*t)y=x;Y=fft(y,256);Pyy=Y.*conj(Y)/256;f=1000/256*(0:127);plot(f,Pyy(1:128));title('Powerspectraldensity');xlabel('Frequency(Hz)');【图像】00.050.10.150.20.25-1-0.8-0.6-0.4-0.200.20.40.60.810501001502002503003504004505000246810121416PowerspectraldensityFrequency(Hz)(a)时域图f(t)(b)频域图F(ω)0501001502002503003504004505000102030405060PowerspectraldensityFrequency(Hz)0501001502002503003504004505000102030405060PowerspectraldensityFrequency(Hz)图(c)Cos(280πt)频谱图图4Sin(100πt)Cos(280πt)的频谱图64、带有随机噪声的信号频谱若传输信号为()sin(100)sin(280)ftttpp=+,在传输过程中由于信道噪声的干扰,波形变得杂乱无章。利用频域变换可以分辨出两种频率成份。【程序】t=0:.001:.25;x=sin(2*pi*50*t)+sin(2*pi*140*t)y=x+2*randn(size(t));%plot(y(1:50))%title('Noisytimedomainsignal')Y=fft(y,256);Pyy=Y.*conj(Y)/256;f=1000/256*(0:127);plot(f,Pyy(1:128));title('Powerspectraldensity');xlabel('Frequency(Hz)');【图像】00.050.10.150.20.25-3-2-1012305101520253035404550-6-4-20246Noisytimedomainsignal(a)时域图f(t)(无干扰)(b)时域图(噪声干扰)70501001502002503003504004505000102030405060PowerspectraldensityFrequency(Hz)(c)频谱图F(ω)图4受噪声干扰的Sin(100πt)+Sin(280πt)的频谱图比较图4(b)(c)两图可以看出,由于受到噪声干扰,图(b)几乎很难分辨出信号图像,但是经过傅里叶变换后,其频谱图中有两个频域分量(50Hz、140Hz)非常清晰。这说明,频谱的确能够帮助我们分析信号的成份,便于对信号进行处理。