MATLAB中快速傅立叶变换(FFT)练习

实例:将高斯脉冲从时域转换到频域

实例来自Matlab FFT的example,第二部分的频域步骤还不是很懂,我再学习学习后添加注释。

1. 高斯脉冲生成
% Define signal parameters and a Gaussian pulse, y.
Fs = 100; %定义高斯脉冲的频率,
x = -0.5:1/Fs:0.5; %定义高斯脉冲的x轴间隔为10ms,也就是0.01s
L = length(x); %计算有多少个时间间隔

y = 1/(4*sqrt(2*pi*0.01))*(exp(-x.^2/(2*0.01))); %生成高斯脉冲的幅值(即y轴)

% Plot the pulse in the time domain.
plot(x, y)
title('Gaussian Pulse in Time Domain')
xlabel('Time (t)')
ylabel('X(t)')
2. 时域图

3. 频域图参数计算

% To use the fft function to convert the signal to the frequency domain, 
% first identify a new input length that is the next power of 2 from the original signal length. 
% This will pad the signal y with trailing zeros in order to improve the performance of fft.
n = 2^nextpow2(L); %???

%Convert the Gaussian pulse to the frequency domain.
y_fft = fft(y, n); 

%Define the frequency domain and plot the unique frequencies.
f = Fs*(0:(n/2))/n; %???
P = abs(y_fft/n).^2; %???

plot(f, P(1:n/2 + 1))
title('Gaussian Pulse in Frequency Domain')
xlabel('Frequency (f)')
ylabel('|P(f)|^2')

4. 频域图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值