计算电磁学葛书的源谱分析.m

来自「计算电磁学书上的试验程序」· M 代码 · 共 41 行

M
41
字号
clear all;
f1=37;
f2=50;
ts=40;
fs=500;
t=0:1/fs:ts;
t0=5
tt=5;
%y=sin(2*pi*f1*t)+sin(2*pi*f2*t)+exp(-t).*cos(2*pi*100*t);
%y=exp(-t);%.*cos(2*pi*100*t);
%for i=1:length(t)
 %   nt=i*1/fs;
%if  nt<0.2|nt>0.8
%    y(i)=0;
%else
 %   y(i)=1;
 %end
 %end
%y=exp(-4*pi*(t-t0).^2/tt^2);%高斯脉冲
y=(t-t0)/tt.*exp(-4*pi.*(t-t0).^2/tt^2);
%****************************************************************************************
%for i=1:length(t)     %%升余弦脉冲
%   nt=i*1/fs;
%if  nt<tt
%    y(i)=0.5*(1-cos(2*pi*nt/tt));
%else
 %   y(i)=0;
 %end
 %end
%*******************************************************************************************
n=length(y);
r=fft(y)/n;
r=fftshift(r);
f=linspace(-fs/2,fs/2,n);
subplot(2,1,1);plot(t,y);axis([0 8/3*tt -0.5 0.5]);
subplot(2,1,2);plot(f,abs(r));
axis([0 3/tt 0 0.01])
%set(gca,'XTick',-fs/2:50:fs/2');
%axis tight;grid on;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?