微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MATLAB中FFT结果的幅度和相位

如何解决MATLAB中FFT结果的幅度和相位

我尝试从 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

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

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

解决方法

由于涉及浮点运算,这些值不会完全为零。您生成了幅度为 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,2);
plot(f,phase_single_side);
xlabel('Frequency');
ylabel('Phase');
hold on;
plot(f(four_hertz_bin),four_hertz_phase,'ro');

Amplitude and Phase Spectrum

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。