clear all
close all
t=0:pi/300:2*pi-pi/300;
L=length(t);
y(1,1:100)=cos(t(1,1:100)-pi/6);
y(1,101:200)=sqrt(3)*cos(t(1,101:200));
y(1,201:300)=-cos(t(1,201:300)-5*pi/6);
y(1,301:400)=-cos(t(1,301:400)-7*pi/6);
y(1,401:500)=sqrt(3)*cos(t(1,401:500));
y(1,501:600)=cos(t(1,501:600)+pi/6);
yfft=fftshift(abs(fft(y)))*2/L;
f=0:1/(2*pi-pi/300):1/(pi/300);
f=f-0.5/(pi/300)-0.5/(2*pi-pi/300);
plot(t,y)
figure
plot(f,yfft); %频谱图
title('频谱');