第1页共35页编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第1页共35页例1-1%周期信号(方波)的展开,fb_jinshi
mcloseall;clearall;N=100;%取展开式的项数为2N+1项T=1;fs=1/T;N_sample=128;%为了画出波形,设置每个周期的采样点数dt=T/N_sample;t=0:dt:10*T-dt;n=-N:N;Fn=sinc(n/2)
*exp(-j*n*pi/2);Fn(N+1)=0;ft=zeros(1,length(t));form=-N:Nft=ft+Fn(m+N+1)*exp(j*2*pi*m*fs*t);endplot(t,ft)例1-2利用FFT计算信号的频谱并与信号的真实频谱的抽样比较
脚本文件T2F
m定义了函数T2F,计算信号的傅立叶变换
function[f,sf]=T2F(t,st)%ThisisafunctionusingtheFFTfunctiontocalculateasignal'sFourier%Translation%Inputisthetimeandthesignalvectors,thelengthoftimemustgreater%than2%Outputisthefrequencyandthesignalspectrumdt=t(2)-t(1);T=t(end);df=1/T;N=length(st);f=-N/2*df:df:N/2*df-df;sf=fft(st);sf=T/N*fftshift(sf);脚本文件F2T
m定义了函数F2T,计算信号的反傅立叶变换
function[tst]=F2T(f,sf)%Thisfunctioncalculatethetimesignalusingifftfunctionfortheinput%signal