基于matlab的计算机仿真_源代码
例 21
%周期信号(方波)的展开,fb_jinshi.m
close 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)
例 24
利用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 spectrum