找回密码
 注册
关于网站域名变更的通知
查看: 480|回复: 1
打印 上一主题 下一主题

MATLAB —— 信号处理工具箱之fft的案例分析

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-11-26 14:06 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
  M! N) V( w8 L! [/ N
上篇:
MATLAB —— 信号处理工具箱之fft的介绍和相关案例分析介绍了MATLAB信号处理工具箱中的信号变换 fft 并分析了一个案例,就是被噪声污染了的信号的频谱分析。
9 f2 Y# X7 Z( Y6 g+ \6 K4 m* ]$ |" L$ a1 T* X) N# Z
这篇博文继续分析几个小案例:' S, C( u. n) c
3 B  r! h7 M, }2 t3 z7 o' s
Gaussian Pulse
* D1 r3 Z" P: n# A% y
这个案例是将高斯脉冲从时域变换到频域,高斯脉冲的信息在下面的程序中都有注释:/ v) R$ Z( Y2 r7 P; I( B* y: ?, [
7 \# R0 b- g0 C% I: {" k: A7 x8 Z
  • clc
  • clear
  • close all
  • % Convert a Gaussian pulse from the time domain to the frequency domain.
  • %
  • % Define signal parameters and a Gaussian pulse, X.
  • Fs = 100;           % Sampling frequency
  • t = -0.5:1/Fs:0.5;  % Time vector
  • L = length(t);      % Signal length
  • X = 1/(4*sqrt(2*pi*0.01))*(exp(-t.^2/(2*0.01)));
  • % Plot the pulse in the time domain.
  • figure();
  • plot(t,X)
  • title('Gaussian Pulse in Time Domain')
  • xlabel('Time (t)')
  • ylabel('X(t)')
  • % 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 X 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(X,n);
  • % Define the frequency domain and plot the unique frequencies.
  • f = Fs*(0: (n/2))/n;
  • P = abs(Y/n);
  • figure();
  • plot(f,P(1:n/2+1))
  • title('Gaussian Pulse in Frequency Domain')
  • xlabel('Frequency (f)')
  • ylabel('|P(f)|')
  • : l+ Q7 w  a9 {$ A0 C
        
* u4 L$ y/ X  l/ p2 |2 N3 C  E+ n
/ W6 y1 D/ T2 j/ Y6 u, K( D高斯脉冲在时域的图像:% ^/ t: F+ ?; `% }# r1 m& Z# N

8 X# R' b: ^! M8 A; V4 a
! b/ P7 T* e" z& t4 Z" y# J$ G) g
7 `4 N; t; `9 r高斯脉冲在频域的图像:# S- e( X7 V6 W2 T

7 R; {  I# G) q7 z! d1 K7 |' z

- b3 h* _; Q2 ?! ?% v# M
" D4 s! ?' y: ~8 z
' E3 Y( A1 @0 x2 y( B3 {3 s3 I* j# A5 \3 K4 B( s/ h! P2 G* Q1 M7 g
Cosine Waves
# a5 F" [( R5 t# E

2 r3 ~8 w% x2 \: K; o$ q9 D2 x这个例子比较简单,就是不同频率的余弦波在时域以及频域的比较:2 x# d* |. ]2 ~( C- k
; z# y9 ?! F7 z
  • clc
  • clear
  • close all
  • % Compare cosine waves in the time domain and the frequency domain.
  • %
  • % Specify the parameters of a signal with a sampling frequency of 1kHz and a signal duration of 1 second.

  • . F" w2 o$ ~3 ^& Z2 Z
  • Fs = 1000;                    % Sampling frequency
  • T = 1/Fs;                     % Sampling period
  • L = 1000;                     % Length of signal
  • t = (0: L-1)*T;                % Time vector
  • % Create a matrix where each row represents a cosine wave with scaled frequency.
  • % The result, X, is a 3-by-1000 matrix. The first row has a wave frequency of 50,
  • % the second row has a wave frequency of 150, and the third row has a wave frequency of 300.

  • ; T) n( F) R  F- l  z) u4 z
  • x1 = cos(2*pi*50*t);          % First row wave
  • x2 = cos(2*pi*150*t);         % Second row wave
  • x3 = cos(2*pi*300*t);         % Third row wave

  • ! l5 j, E+ p& }+ R: S
  • X = [x1; x2; x3];
  • % Plot the first 100 entries from each row of X in a single figure in order and compare their frequencies.
  • * P+ M' d; j$ ^
  • figure();
  • for i = 1:3
  •     subplot(3,1,i)
  •     plot(t(1:100),X(i,1:100))
  •     title(['Row ',num2str(i),' in the Time Domain'])
  • end

  • & a5 B4 z) s3 f/ r
  • % For algorithm performance purposes, fft allows you to pad the input with trailing zeros.
  • % 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.
  • % Define the new length using the nextpow2 function.

  • 6 M; Y: x0 T' O' E- ^, k0 |
  • n = 2^nextpow2(L);
  • % Specify the dim argument to use fft along the rows of X, that is, for each signal.

  • 7 q2 I$ a1 y( H% A
  • dim = 2;
  • % Compute the Fourier transform of the signals.
  • $ m& ~5 i- t8 K
  • Y = fft(X,n,dim);
  • % Calculate the double-sided spectrum and single-sided spectrum of each signal.
  • $ V' h- C) Q$ J% \
  • P2 = abs(Y/L);
  • P1 = P2(:,1:n/2+1);
  • P1(:,2:end-1) = 2*P1(:,2:end-1);
  • % In the frequency domain, plot the single-sided amplitude spectrum for each row in a single figure.
  • / s9 t3 e- F1 L" |9 A
  • figure();
  • for i=1:3
  •     subplot(3,1,i)
  •     plot(0: (Fs/n): (Fs/2-Fs/n),P1(i,1:n/2))
  •     title(['Row ',num2str(i),' in the Frequency Domain'])
  • end+ _8 A3 C' O0 z+ u0 r# l
           ' D5 N. ?+ I' Q% c0 l% z" ^4 Z

7 c! D' H/ t# T& k8 z8 b- y下图是频率为50Hz,150Hz以及300Hz的余弦波在时域的图像:, ~; q9 z8 x7 n8 N+ Z: X

2 u4 r2 L, ^( r+ H8 W
& N0 k5 c) I& I& x# T9 x' x: H" S. O- V( B7 _7 A; h; W
下图分别为其fft:
' U- V  F9 I. j5 X$ X
" h# B7 H, A2 P- K 5 v1 o1 C# L" e

- j% r) x/ _: |+ }: o从频域图中可以清晰的看到它们的频率成分位于何处。& g8 D& S* P! P* c. D; M( D
0 C  N' N5 N" g' \. H4 x; e; g9 c

9 \: g0 v, ^" ^5 i9 t  F3 p4 b
  • TA的每日心情
    开心
    2020-12-3 15:53
  • 签到天数: 38 天

    [LV.5]常住居民I

    2#
    发表于 2019-11-26 16:00 | 只看该作者
    看看,学习一下
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-11-23 19:38 , Processed in 0.156250 second(s), 26 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表