clear;
close all;
clc;
N=50;
w=boxcar(N);
W=fft(w,256);
figure(1)
subplot(2,1,1);
stem([0:N-1],w);
subplot(2,1,2);
plot([-128:127],abs(fftshift(W)))
N=input('窗函数长度=');
L=512;
f1=100;f2=120;fs=600;
ws=2*pi*fs;
t=(0:N-1)*(1/fs);
x=cos(2*pi*f1*t)+cos(2*pi*f2*t);
figure(2)
subplot(211);stem(t,x);
W=fft(x,L);
f=((-L/2:L/2-1)*(2*pi/L)*fs)/(2*pi);% f=((-L/2:L/2-1)*(1/L)*fs);
subplot(212);
plot(f,abs(fftshift(W)))
L=512;
f1=100;f2=120;fs=600;
ws=2*pi*fs;
t=(0:N-1)*(1/fs);
x=cos(2*pi*f1*t)+cos(2*pi*f2*t);
wh=hamming(N)';
x=x.*wh;
figure(3)
subplot(211);stem(t,x);
W=fft(x,L);
f=((-L/2:L/2-1)*(2*pi/L)*fs)/(2*pi);
subplot(212);
plot(f,abs(fftshift(W)))
L=512;
f1=100;f2=150;fs=600;
ws=2*pi*fs;
t=(0:N-1)*(1/fs);
x=cos(2*pi*f1*t)+0.15*cos(2*pi*f2*t);
figure(4)
subplot(211);stem(t,x);
W=fft(x,L);
f=((-L/2:L/2-1)*(2*pi/L)*fs)/(2*pi);
subplot(212);
plot(f,abs(fftshift(W)))
L=512;
f1=100;f2=150;fs=600;
ws=2*pi*fs;
t=(0:N-1)*(1/fs);
x=cos(2*pi*f1*t)+0.15*cos(2*pi*f2*t);
wh=hamming(N)';
x=x.*wh;
figure(5)
subplot(211);stem(t,x);
W=fft(x,L);
f=((-L/2:L/2-1)*(2*pi/L)*fs)/(2*pi);
subplot(212);
plot(f,abs(fftshift(W)))