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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x

0 C0 b# I! c# l4 G上篇:
MATLAB —— 信号处理工具箱之fft的介绍和相关案例分析介绍了MATLAB信号处理工具箱中的信号变换 fft 并分析了一个案例,就是被噪声污染了的信号的频谱分析。  O, c: u( j8 G8 W1 h. M* o

. K+ J8 ^4 v' @0 q. q$ I这篇博文继续分析几个小案例:
6 U9 r( u1 g$ R
8 e2 e- y( s1 w2 j' a' z& xGaussian Pulse
8 |* w5 s1 [  u+ ~
这个案例是将高斯脉冲从时域变换到频域,高斯脉冲的信息在下面的程序中都有注释:. _' |* n9 h" P
6 o7 q2 v- w# g5 q7 g* K" \. G
  • 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)|')

  • 3 i7 f1 b5 H: z3 C5 u/ l& p
        
* }6 k& B( L& p: x8 e, k' Y* ] 3 U- i5 _% x; q. [/ V2 N
高斯脉冲在时域的图像:
5 _, {" ?8 Y% @# M6 x; m3 l8 G0 w  L% i! w

6 \2 V$ Q0 }  U3 [3 u5 z0 g$ C
$ `- D- v1 u$ M$ K; m高斯脉冲在频域的图像:" c9 `  S- Q) u. W

/ v. t" Z/ L* j
; `! |" n7 f, p7 l  A4 o: ^. G

, R- S8 L: \( t# @7 R* T/ e
2 N8 \" X( f8 j% F5 ]+ V& C# S7 m- N+ E4 @0 n. f
Cosine Waves

: j" ]) ~# Q2 z- c% G& a7 }  G) e0 S" ]9 n" e; W
这个例子比较简单,就是不同频率的余弦波在时域以及频域的比较:" r$ B1 z4 }. s4 W

3 s9 T, \. H6 ~" j% r/ e8 x
  • 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.

  • 8 m( Q6 O. h: V( U
  • 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.

  •   e5 G6 _( ^) u" c3 O. B
  • 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
  • , b& M- ~( @& j7 G/ j: Q, W
  • X = [x1; x2; x3];
  • % Plot the first 100 entries from each row of X in a single figure in order and compare their frequencies.

  • 2 B0 c, N; H) i2 M; ?
  • 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

  • 0 X7 e' D/ t- Y$ Y8 q5 m7 n! o/ i
  • % 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.

  • % F3 ?- f) C! _# Q. d  U$ `
  • n = 2^nextpow2(L);
  • % Specify the dim argument to use fft along the rows of X, that is, for each signal.

  • 9 T+ S- i- [2 s  W/ m3 c! l
  • dim = 2;
  • % Compute the Fourier transform of the signals.
  • ! j) f0 J2 Y4 O
  • Y = fft(X,n,dim);
  • % Calculate the double-sided spectrum and single-sided spectrum of each signal.
  • ' \6 m5 X- [# v+ 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.
  • . Y  Q) k1 @/ {1 C
  • 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'])
  • end1 S  _1 a1 c$ ]" c
           
: ?- A% k/ d) p3 G+ c) h " P- k& _4 f2 \* @! U# q
下图是频率为50Hz,150Hz以及300Hz的余弦波在时域的图像:* \0 U) \; g" f. i) o! r" }/ w

  J  M- O0 ^$ `! z) H / r2 ~* A2 z4 b

4 U5 J% y. V$ p6 o# E3 Y下图分别为其fft:; U+ p& `3 W5 C& q6 a
8 e  L) a" a, ?

3 _" E0 R' R5 Q, x4 Q3 X
, ^% v, c  y  D( ^从频域图中可以清晰的看到它们的频率成分位于何处。
# S0 |- L& z: q! F
; w, h4 w" }* G9 u( l$ J7 l- I
' a- _/ L( i) F; D0 @8 Z0 \
  • 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-7-19 14:45 , Processed in 0.109375 second(s), 26 queries , Gzip On.

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

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

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