例 1-1%周期信号(方波)的展开,fb_jinshi
mclose all;clear all;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));for m=-N:N ft = ft + Fn(m+N+1)*exp(j*2*pi*m*fs*t);end plot(t,ft)例 1-2利用 FFT 计算信号的频谱并与信号的真实频谱的抽样比较
脚本文件 T2F
m 定义了函数 T2F,计算信号的傅立叶变换
function [f,sf]= T2F(t,st)%This is a function using the FFT function to calculate a signal's Fourier%Translation%Input is the time and the signal vectors,the length of time must greater%than 2%Output is the frequency and the signal spectrumdt = 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 [t st]=F2T(f,sf)%This function calculate the time si