标签:
首先补充:
randn()函数用来产生正态分布的随机数或矩阵
conj()函数用来求负数的共轭:如果Z是一个复数组,那么conj(Z) = real(Z) - i*imag(Z)其中real(Z),imag(Z)分别代表Z的实部和虚部
1.首先看一下频谱分析下,频谱图像展现的特征:
x = sin(2*pi*50*t)的原图和频谱图:
代码:
1 clear;2 clc;3 t = 0:0.001:0.25;4 x = sin(2*pi*50*t);5 %x = 2*sin(2*pi*50*t+pi);6 %x = sin(2*pi*50*t) + 2*sin(2*pi*140*t);7 %x = sin(100*pi*t)+cos(280*pi*t);8 figure(1);9 plot(t,x);10 xlabel(‘t‘); ylabel(‘f(t)‘);11 y =x;12 Y = fft(y,256);13 Pyy = Y.*conj(Y)/256; %计算Y的模的长度14 f = 1000/256*(0:127);15 figure(2);16 plot(f,Pyy(1:128));17 title(‘Power spectral density‘);18 xlabel(‘Frequency (Hz)‘);
View Code
结果图为:
频谱图中,峰值是正好是原函数的周期的频率。 变下初始相位呢?
x = 2*sin(2*pi*50*t+pi);
代码: