Hei Guys I am having some trouble getting the right frequency in my FFT Matlab script. I tested the script with a sinus signal and it workes just fine. but somehow with my measured signal (put in a txt file, see below) doesn't give me the right frequency. In the first plot I am plotting my signal and there I measured and calculated from hand the should be frequency, which is 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']);
the data is:
11284, 11601, 12033, 12355, 12344, 11985, 11558, 11444, 11807, 12491, 13090, 13199, 12694, 11878, 11290, 11500, 12855
my FFT gives me the frequency 1250*10^4 Hz. I tested this code with a sinus with these parameter and it worked just fine:
%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);
Am I missing something?