zoukankan      html  css  js  c++  java
  • Matlab FFT使用示例

    %% Parameters
    Tm=5;% Length of signal (s)
    Fd=512;% Sampling frequency (Hz)
    Ak=0.5;% Constant component (Unit)
    A1=1;% The amplitude of the first sinusoid (Unit)
    A2=0.7;% Amplitude of the second sinusoid (Unit)
    F1=13;% Frequency of the first sinusoid (Hz)
    F2=42;% Frequency of the second sinusoid (Hz)
    Phi1=0;% Initial phase of the first sinusoid (Degrees)
    Phi2=37;% The initial phase of the second sinusoid (Degrees)
    An=3*A1;% Noise Dispersion (Unit)
    FftL=1024;% Number of Fourier Spectrum Lines
    %% Generating work arrays
    T=0:1/Fd:Tm;% Time Arrays
    Noise=An*randn(1,length(T));% An array of random noise with a length equal to the array of time
    Signal=Ak+A1*sind((F1*360).*T+Phi1)+A2*sind((F2*360).*T+Phi2);% Signal array (a mixture of 2x sinusoids and a constant component)
    %% Spectral representation of the signal
    FftS=abs(fft(Signal,FftL));% The amplitudes of the Fourier transform of the signal
    FftS=2*FftS./FftL;% Spectrum normalization by amplitude
    FftS(1)=FftS(1)/2;% The normalization of the constant component in the spectrum
    FftSh=abs(fft(Signal+Noise,FftL));% The amplitudes of the Fourier transform of the signal + noise mixture
    FftSh=2*FftSh./FftL;% Spectrum normalization by amplitude
    FftSh(1)=FftSh(1)/2;% The normalization of the constant component in the spectrum
    %% Plotting
    subplot(2,1,1);
    plot(T,Signal);
    title('Signal');
    xlabel('Time (s)');
    ylabel('Amplitude (Unit)');
    subplot(2,1,2);
    plot(T,Signal+Noise);
    title('Signal+Noise');
    xlabel('Time (s)');
    ylabel('Amplitude (Unit)');
    
    F=0:Fd/FftL:Fd/2-1/FftL;% The frequency array of the calculated Fourier spectrum
    figure();
    subplot(2,1,1);
    plot(F,FftS(1:length(F)));%  Plotting of the spectrum of the Fourier signal
    title('Signal spectrum');
    xlabel('Frequency (Hz)');
    ylabel('Amplitude (Unit)');
    subplot(2,1,2);
    plot(F,FftSh(1:length(F)));% Plotting of the Fourier signal spectrum
    title('Signal spectrum');
    xlabel('Frequency (Hz)');
    ylabel('Amplitude (Unit)');
    
  • 相关阅读:
    QuantLib 金融计算——基本组件之 Date 类
    挑选合适的机器学习资料
    【翻译】理解 LSTM 及其图示
    《信任的速度》读后感
    Git分支使用心得
    c# 多线程 创建对象实例
    c# 设计模式之单例模式
    C# 设计模式之空对象模式
    c# 静态构造函数与构造函数的调用先后
    C# 中关于接口实现、显示实现接口以及继承
  • 原文地址:https://www.cnblogs.com/lyuyangly/p/13419858.html
Copyright © 2011-2022 走看看