【 MATLAB 】信号处理工具箱之 fft 案例分析

举报
李锐博恩 发表于 2021/07/15 06:25:06 2021/07/15
【摘要】 上篇博文:【 MATLAB 】信号处理工具箱之fft简介及案例分析介绍了MATLAB信号处理工具箱中的信号变换 fft 并分析了一个案例,就是被噪声污染了的信号的频谱分析。 这篇博文继续分析几个小案例: Gaussian Pulse 这个案例是将高斯脉冲从时域变换到频域,高斯脉冲的信息在下面的程序中都有注释: clcclearclose all% Convert a ...

上篇博文:【 MATLAB 】信号处理工具箱之fft简介及案例分析介绍了MATLAB信号处理工具箱中的信号变换 fft 并分析了一个案例,就是被噪声污染了的信号的频谱分析。

这篇博文继续分析几个小案例:

Gaussian Pulse

这个案例是将高斯脉冲从时域变换到频域,高斯脉冲的信息在下面的程序中都有注释:


  
  1. clc
  2. clear
  3. close all
  4. % Convert a Gaussian pulse from the time domain to the frequency domain.
  5. %
  6. % Define signal parameters and a Gaussian pulse, X.
  7. Fs = 100; % Sampling frequency
  8. t = -0.5:1/Fs:0.5; % Time vector
  9. L = length(t); % Signal length
  10. X = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01)));
  11. % Plot the pulse in the time domain.
  12. figure();
  13. plot(t,X)
  14. title('Gaussian Pulse in Time Domain')
  15. xlabel('Time (t)')
  16. ylabel('X(t)')
  17. % To use the fft function to convert the signal to the frequency domain,
  18. % first identify a new input length that is the next power of 2 from the original signal length.
  19. % This will pad the signal X with trailing zeros in order to improve the performance of fft.
  20. n = 2^nextpow2(L);
  21. % Convert the Gaussian pulse to the frequency domain.
  22. %
  23. Y = fft(X,n);
  24. % Define the frequency domain and plot the unique frequencies.
  25. f = Fs*(0:(n/2))/n;
  26. P = abs(Y/n);
  27. figure();
  28. plot(f,P(1:n/2+1))
  29. title('Gaussian Pulse in Frequency Domain')
  30. xlabel('Frequency (f)')
  31. ylabel('|P(f)|')

高斯脉冲在时域的图像:

高斯脉冲在频域的图像:

Cosine Waves

这个例子比较简单,就是不同频率的余弦波在时域以及频域的比较:


  
  1. clc
  2. clear
  3. close all
  4. % Compare cosine waves in the time domain and the frequency domain.
  5. %
  6. % Specify the parameters of a signal with a sampling frequency of 1kHz and a signal duration of 1 second.
  7. Fs = 1000; % Sampling frequency
  8. T = 1/Fs; % Sampling period
  9. L = 1000; % Length of signal
  10. t = (0:L-1)*T; % Time vector
  11. % Create a matrix where each row represents a cosine wave with scaled frequency.
  12. % The result, X, is a 3-by-1000 matrix. The first row has a wave frequency of 50,
  13. % the second row has a wave frequency of 150, and the third row has a wave frequency of 300.
  14. x1 = cos(2*pi*50*t); % First row wave
  15. x2 = cos(2*pi*150*t); % Second row wave
  16. x3 = cos(2*pi*300*t); % Third row wave
  17. X = [x1; x2; x3];
  18. % Plot the first 100 entries from each row of X in a single figure in order and compare their frequencies.
  19. figure();
  20. for i = 1:3
  21. subplot(3,1,i)
  22. plot(t(1:100),X(i,1:100))
  23. title(['Row ',num2str(i),' in the Time Domain'])
  24. end
  25. % For algorithm performance purposes, fft allows you to pad the input with trailing zeros.
  26. % In this case, pad each row of X with zeros so that the length of each row is the next higher power of 2 from the current length.
  27. % Define the new length using the nextpow2 function.
  28. n = 2^nextpow2(L);
  29. % Specify the dim argument to use fft along the rows of X, that is, for each signal.
  30. dim = 2;
  31. % Compute the Fourier transform of the signals.
  32. Y = fft(X,n,dim);
  33. % Calculate the double-sided spectrum and single-sided spectrum of each signal.
  34. P2 = abs(Y/L);
  35. P1 = P2(:,1:n/2+1);
  36. P1(:,2:end-1) = 2*P1(:,2:end-1);
  37. % In the frequency domain, plot the single-sided amplitude spectrum for each row in a single figure.
  38. figure();
  39. for i=1:3
  40. subplot(3,1,i)
  41. plot(0:(Fs/n):(Fs/2-Fs/n),P1(i,1:n/2))
  42. title(['Row ',num2str(i),' in the Frequency Domain'])
  43. end

下图是频率为50Hz,150Hz以及300Hz的余弦波在时域的图像:

下图分别为其fft:

从频域图中可以清晰的看到它们的频率成分位于何处。

 

 

 

 

 

 

文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。

原文链接:reborn.blog.csdn.net/article/details/83060448

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。