首页 > 解决方案 > Matlab FFT没有显示正确的频率与测量的信号,用正弦信号测试的脚本工作

问题描述

嘿伙计们,我在 FFT Matlab 脚本中获得正确的频率时遇到了一些麻烦。我用正弦信号测试了脚本,它工作得很好。但不知何故,我的测量信号(放入 txt 文件,见下文)并没有给我正确的频率。在第一个图中,我正在绘制我的信号,在那里我用手测量和计算了应该是频率,即 33.333 kHz

% Parameter
td = 100*4e-6;  % Duration of the measurement ( i honestly just put something here)
fs = 250e3;     % samplingfrequency

% Frequency to be detected (measured from data in plot)
freq_soll_20 = 1/(7.2e-5 - (4.4e-5 + 4e-5)/2);
% Samples calc

s_20 = readmatrix('fft_cut_20.txt');
t_20 = 0:1/fs:((length(s_20)-1)*1/fs);

%% ---- Triggerdata
figure(1)
subplot(3,1,1);
plot (t_20, s_20)
grid on;
xlabel('Zeit (ms)');
ylabel('ADC LSB');
title('20um');

h_20=fft(s_20).*1/length(s_20);
f_20=1/td*(0:(length(t_20)-1));

subplot(3,1,2);
stem(f_20,abs(h_20));
grid on;
xlim([min(f_20) max(f_20)]);
xlabel('Frequenz (Hz)');
ylabel('Amplitude');
title('Ausgabe des FFTs');

subplot(3,1,3);
f2_20=f_20-round(max(f_20)/2);
stem(f2_20, fftshift(abs(h_20)));
grid on; 
xlabel('Frequenz (Hz)');
ylabel('Amplitude');
title(['Ausgabe des FFTs nach sortieren mit FFTSHIFT mit soll frequenz:'...
    num2str(freq_soll_20) 'Hz']);

数据是:

11284, 11601, 12033, 12355, 12344, 11985, 11558, 11444, 11807, 12491, 13090, 13199, 12694, 11878, 11290, 11500, 12855

我的 FFT 给了我 1250*10^4 Hz 的频率。我用带有这些参数的正弦测试了这段代码,它工作得很好:

%Parameter
fs = 250000;  % Abtastrate
td = 100*4e-6;    % Dauer der Messung
f1 = 30000;    % Frequenz

% Samples berechnen
t  = 0:(1/fs):td;
s  = sin(2.*pi.*f1.*t);

我错过了什么吗?

标签: matlabfft

解决方案


频率的正确公式是:

f_20=(0:(length(t_20)-1))*fs/length(t_20);

只要对应于总信号持续时间,您的公式f_20=1/td*(0:(length(t_20)-1));就会等效td,正弦波就是这种情况。对于只有 17 个样本的其他信号则不能这样说,而td=100*4e-6250kHz 的采样率对应于 100 个样本。


推荐阅读