简体   繁体   English

MATLAB 中 FFT 结果的幅度和相位

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

I tried to extract amplitude & phase values from the fft function result in the Matlab.我试图从fft function 结果中提取幅度和相位值,得到 Matlab。 I implemented the script as below我实现了如下脚本

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

When I checked the results of amplitude and phase values, of course, they showed peak values at a specific frequency that I specified.当我检查幅度和相位值的结果时,当然,它们在我指定的特定频率处显示峰值。 But, other frequencies also have amplitude.但是,其他频率也有幅度。 Of course, their values are very very small, but because of this problem, the phase spectrum didn't show me a clear result.当然,它们的值非常非常小,但是因为这个问题,相位谱并没有给我一个清晰的结果。 Why other frequencies also have amplitude values?为什么其他频率也有幅度值?

And I made a cosine function that is not shifted.我做了一个没有移位的余弦 function。 So I think the phase value should show the zero value, but it wasn't.所以我认为相位值应该显示零值,但事实并非如此。 Why this problem occurred?为什么会出现这个问题?

These values won't be exactly zero due to the floating point operations involved.由于涉及浮点运算,这些值不会完全为零。 You generated a 4 Hz cosine with amplitude of 1. Taking the single-sided amplitude and phase spectrum shows an amplitude of 1, and a phase of 0 radians at the 4 Hz bin:您生成了一个幅度为 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