clc;close all;clear all;
f0=10; fs=100; %采样率 t=1/fs:1/fs:2; %共两秒钟,共200个采样点。采样间隔T=1/100
y1=sin(2*pi*f0*t);
y2=square(2*pi*f0*t);
noise=rand(1,200);
z1=y1+noise;
z2=y2+noise;
fft_y1=fft(y1); dft200_y1=fft(y1,200); dft100_y1=fft(y1,100);
figure;
subplot(311);plot(abs(fft_y1));xlabel('frez');ylabel('|e^j^\omega/|');title('fft_y1');
subplot(312);plot(abs(dft200_y1));xlabel('\omega/\pi');ylabel('dft200_y1');title('200点 DFT y1');
subplot(313);plot(abs(dft100_y1));xlabel('\omega/\pi');ylabel('dft100_y1');title('100点 DFT y1');
%----------------------------------------------------------------------------------------
fft_noise=fft(noise); dft200_noise=fft(noise,200); dft100_noise=fft(noise,100);
figure;
subplot(311);plot(abs(fft_noise));xlabel('frez');ylabel('|e^j^\omega/|');title('fft_noise');
subplot(312);plot(abs(dft200_noise));xlabel('\omega/\pi');ylabel('dft200_noise');title('200点 DFT noise');
subplot(313);plot(abs(dft100_noise));xlabel('\omega/\pi');ylabel('dft100_noise');title('100点 DFT noise');
==========================================================================================
fft_z1=fft(z1); dft200_z1=fft(z1,200); %dft变换,2*pi上平均采200个点 dft100_z1=fft(z1,100);
figure;
subplot(311);plot(abs(fft_z1)); xlabel('frez');ylabel('fft_z1');title('z1_fft');
subplot(312);plot(abs(dft200_z1)); xlabel('\omega/\pi');ylabel('dft200_z1');title('200点 DFT z1');
subplot(313);plot(abs(dft100_z1)); xlabel('\omega/\pi');ylabel('dft100_z1');title('100点 DFT z1');