设(x_1(t)=sinc(10t)), (x_2(t)=rect(10t)), (x_3(t)=cos(100pi t)), (x_4(t)=cos(100pi t+10cos(2*pi t))),利用Matlab仿真求(x_1(t)),(x_2(t)),(x_3(t)),(x_4(t))的傅氏变换。
rect =@(x) (abs(x)<=0.5);
T=50;
dt=0.0001;
fs=1/dt;
t=[-T/2:dt:T/2];
x1=sinc(10*t);
x2=rect(10*t);
x3=cos(100*pi*t);
x4=cos(100*pi*t+10*cos(2*pi*t));
[X1,f]=t2f(x1,fs);
[X2,f]=t2f(x2,fs);
[X3,f]=t2f(x3,fs);
[X4,f]=t2f(x4,fs);
figure(1)
plot(f,[X1;X2])
axis([-50,50,-0.05,0.25])
figure(2)
plot(f,[X3;X4])
axis([-80,80,-8,28])
调用的时域到频域变换函数t2f如下所示:
function [S,f]=t2f(s,fs)
Ts=1/fs;
N=length(s);
if rem(N,2)~=0
N=N+1;
s=[s,0];
end
f=[-N/2:(N/2-1)]*fs/N;
T=N*Ts;
tmp1=fft(s)*Ts;
tmp2=N*ifft(s)*Ts;
S(1:N/2)=tmp2(N/2+1:-1:2);
S(N/2+1:N)=tmp1(1:N/2);
S=S.*exp(j*pi*f*T);