【问题标题】:Amplitude and Phase of result of FFT in MATLABMATLAB中FFT结果的幅度和相位
【发布时间】:2021-05-25 00:20:43
【问题描述】:

我尝试从 Matlab 中的 fft 函数结果中提取幅度和相位值。我实现了如下脚本

clear;
sf = 100; %sampling frequency
si = 1/sf; dt=si; %time sampling interval
L = 10; %Length of signal
t = linspace(0,L,L/dt+1);%(0:L-1)*dt; %time vector
t(end)=[];

fr = 4 %frequency
data = cos(2*pi*fr*t);
df = sf/length(data3); %frequency increment
f = linspace(0,length(data3)/2,length(data3)/2)*df; %frequency
fft_result =fft(data)/length(data);
spec_fft = abs(fft_result); %amplitude
pha_fft = angle(fft_result); %phase

当我检查幅度和相位值的结果时,当然,它们在我指定的特定频率处显示峰值。但是,其他频率也有幅度。当然,它们的值非常非常小,但是因为这个问题,相位谱并没有给我一个清晰的结果。为什么其他频率也有幅度值?

我做了一个没有移位的余弦函数。所以我认为相位值应该显示零值,但事实并非如此。为什么会出现这个问题?

【问题讨论】:

    标签: matlab fft phase amplitude


    【解决方案1】:

    由于涉及到浮点运算,这些值不会完全为零。您生成了一个幅度为 1 的 4 Hz 余弦。单边幅度和相位谱显示幅度为 1,相位为 0 弧度在 4 Hz 箱:

    clear;
    sf = 100; %sampling frequency
    si = 1/sf; dt=si; %time sampling interval
    L = 10; %Length of signal
    t = linspace(0,L,L/dt+1);%(0:L-1)*dt; %time vector
    t(end)=[];
    
    fr = 4; %frequency
    data = cos(2*pi*fr*t);
    df = sf/length(data); %frequency increment
    N = length(data);
    f = ((0:(N/2))/ N) * sf; %frequency
    fft_result =fft(data)/N;
    spec_fft = abs(fft_result); %amplitude
    % single sided amplitude
    amp_single_side = spec_fft(1:N/2+1);
    amp_single_side(2:end-1) = 2*amp_single_side(2:end-1);
    % single sided phase
    phase_single_side = angle(fft_result(1:N/2+1));
    
    four_hertz_bin = find(f == 4);
    four_hertz_amp = amp_single_side(four_hertz_bin);
    four_hertz_phase = phase_single_side(four_hertz_bin);
    
    figure;
    subplot(2,1,1);
    plot(f, amp_single_side)
    xlabel('Frequency');
    ylabel('Amplitude');
    hold on;
    plot(f(four_hertz_bin), four_hertz_amp, 'ro');
    subplot(2,1,2);
    plot(f, phase_single_side);
    xlabel('Frequency');
    ylabel('Phase');
    hold on;
    plot(f(four_hertz_bin), four_hertz_phase, 'ro');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-07
      • 2012-05-05
      • 2022-11-15
      • 2020-08-25
      • 1970-01-01
      • 2017-09-28
      • 1970-01-01
      • 2015-11-16
      相关资源
      最近更新 更多