N=128;
n=0:N-1;
t=0.01*n;
x=2*sin(4*pi*t)+5*cos(16*pi*t);
subplot(2,1,1);stem(n,x,*.*);title(*signal x(n)*);grid;
X=fft(x,N);
magx=abs(X(1:1:N/2+1));k=[0:1:N/2];w=2*pi/N*k;
subplot(2,1,2);plot(w/pi,magx);title(*FFT N=128*);
xlabel(*频率(单位:pi)*);ylabel(*|X|*);grid
t=0:0.002:0.8;
x=sin(2*pi*40*t)+sin(2*pi*100*t);
y=x+1.5*randn(1,length(t));
Y=fft(y,512);
P=Y.*conj(Y)/512;
n=0:N-1;
t=0.01*n;
x=2*sin(4*pi*t)+5*cos(16*pi*t);
subplot(2,1,1);stem(n,x,*.*);title(*signal x(n)*);grid;
X=fft(x,N);
magx=abs(X(1:1:N/2+1));k=[0:1:N/2];w=2*pi/N*k;
subplot(2,1,2);plot(w/pi,magx);title(*FFT N=128*);
xlabel(*频率(单位:pi)*);ylabel(*|X|*);grid
t=0:0.002:0.8;
x=sin(2*pi*40*t)+sin(2*pi*100*t);
y=x+1.5*randn(1,length(t));
Y=fft(y,512);
P=Y.*conj(Y)/512;