簡體   English   中英

MATLAB 中 FFT 結果的幅度和相位

[英]Amplitude and Phase of result of FFT in MATLAB

我試圖從fft function 結果中提取幅度和相位值,得到 Matlab。 我實現了如下腳本

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

當我檢查幅度和相位值的結果時,當然,它們在我指定的特定頻率處顯示峰值。 但是,其他頻率也有幅度。 當然,它們的值非常非常小,但是因為這個問題,相位譜並沒有給我一個清晰的結果。 為什么其他頻率也有幅度值?

我做了一個沒有移位的余弦 function。 所以我認為相位值應該顯示零值,但事實並非如此。 為什么會出現這個問題?

由於涉及浮點運算,這些值不會完全為零。 您生成了一個幅度為 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');

幅度和相位頻譜

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM