繁体   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