📄 example4_1.m
字号:
%==========================================================================
% 傅里叶变换 程序名:CTFT
% 本程序是采用数值积分的方法计算实信号的傅里叶变换。
% 对信号的要求是:
% 1、信号是时限信号,或者信号在时间t大于某一数值时,信号的值已经衰减到等于
% 或接近于零;
% 2、信号的频谱中不能含有冲激成分,因为计算机无法表现和处理冲激信号。
%==========================================================================
% 下段程序为初始化
%==========================================================================
clear;close all
p=0.01;
t=-5:p:5;
x=input('input the expression of signal x(t):');
W1=4*pi; %确定信号的频率范围
N=512;
k=-N:N; %对信号的角频率进行采样的点数为2N+1点
W=k*W1/N; %计算频率的采样间隔
%==========================================================================
% 下段程序计算信号的傅里叶变换,包括幅度谱和相位谱计算
%==========================================================================
X=x*exp(-j*t'*W)*p; %进行傅里叶数值积分运算(矩阵运算)
X1=abs(X); %求模——幅度谱
phi=57.3*angle(X); %求相位谱
%==========================================================================
% 下段程序绘制图形
%==========================================================================
subplot(2,1,1);plot(t,x);grid on;
xlabel('t');ylabel('the curve of x(t)');
title('The time function x(t)');
subplot(2,2,3);plot(W,X1);grid on;axis([-4*pi,4*pi,-0.2*max(X1),1.2*max(X1)])
xlabel('w');
title('The magnitude spectrum ');
%ylabel('幅度谱——F(w)');
subplot(2,2,4);
plot(W,phi,'r');grid on;axis([-4*pi,4*pi,-200,200])
xlabel('w');title('The phase spectrum');
%===========================================================================
figure(2)
subplot(221)
plot(t,x),grid on
axis([-5,5,-0.1,1.1]);title('The time function x(t) ');xlabel('Time t')
subplot(2,2,2);plot(W,X);grid on;axis([-4*pi,4*pi,-0.4*max(X),1.2*max(X)])
xlabel('Frequency w');title('The magnitude spectrum ');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -