I am getting incorrect FFT values

16 Ansichten (letzte 30 Tage)
uzzi
uzzi am 7 Feb. 2023
Kommentiert: Star Strider am 8 Feb. 2023
Hello,
The values (S) are oscillating around 50 but when i did FFT, I only got at 1.86. I don't know what is wrong with my code. Can someone help me?
%FFT
T=0.01; %cuz the time interval is 0,01. You can see in "t"
Fs=1/T;
t=readtable('t.txt');
S=table2array(readtable('S.txt'));
L=numel(S);
%plot(t,S)
grid on
grid minor
f=Fs*(0:(L/2))/L;
Y=fft(S-mean(S));
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
Warning: Integer operands are required for colon operator when used as index.
P1(2:end-1) = 2*P1(2:end-1);
[pks,locs] = findpeaks(P1, 'MinPeakProminence' ,0.05)
pks = 0.1245
locs = 16
plot(f,P1)
title('Amplitude Spectrums of Aggregat frequency')
xlabel('f (Hz)')
ylabel('Amplitude')
%xlim([0 150])
for k = 1:numel(locs)
xline(f(locs(k)), '-r' , sprintf( 'f = %.2f' ,f(locs(k))))
end

Akzeptierte Antwort

Star Strider
Star Strider am 7 Feb. 2023
The 1.86 value is correct. Look at the time domain plot —
%FFT
T=0.01; %cuz the time interval is 0,01. You can see in "t"
Fs=1/T;
t=readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1287695/t.txt');
S=table2array(readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1287700/S.txt'));
DT = datetime(t.Var1)
DT = 805×1 datetime array
2021-09-30 10:00:35.280 2021-09-30 10:00:35.290 2021-09-30 10:00:35.300 2021-09-30 10:00:35.310 2021-09-30 10:00:35.320 2021-09-30 10:00:35.330 2021-09-30 10:00:35.340 2021-09-30 10:00:35.350 2021-09-30 10:00:35.360 2021-09-30 10:00:35.370 2021-09-30 10:00:35.380 2021-09-30 10:00:35.390 2021-09-30 10:00:35.400 2021-09-30 10:00:35.410 2021-09-30 10:00:35.420 2021-09-30 10:00:35.430 2021-09-30 10:00:35.440 2021-09-30 10:00:35.450 2021-09-30 10:00:35.460 2021-09-30 10:00:35.470 2021-09-30 10:00:35.480 2021-09-30 10:00:35.490 2021-09-30 10:00:35.500 2021-09-30 10:00:35.510 2021-09-30 10:00:35.520 2021-09-30 10:00:35.530 2021-09-30 10:00:35.540 2021-09-30 10:00:35.550 2021-09-30 10:00:35.560 2021-09-30 10:00:35.570
tv = second(DT) - second(DT(1));
T = mean(diff(tv))
T = 0.0100
L=numel(S)
L = 805
[pks,locs] = findpeaks(S, 'MinPeakProminence',0.10);
ApproxFreq = 1/mean(diff(tv(locs)))
ApproxFreq = 1.9886
figure
plot(tv,S)
hold on
plot(tv(locs), pks, '^r')
hold off
grid on
grid minor
The frequency calculated from the time differences of the peaks is slightly different, however quite similar.
.
  5 Kommentare
uzzi
uzzi am 8 Feb. 2023
Bearbeitet: uzzi am 8 Feb. 2023
Hello Star strider,
Can I ask some suggestions from you? The FFT analysis can only be done with the frequency (a derived quantity) which is determined on the basis of zero crossings. But my data for frequency has no signal form like zero crossing because it is got from measurement. So, I can't perform FFT analysis with my signal.
Are there any kind of methods to do analysis with the measurement values?
Star Strider
Star Strider am 8 Feb. 2023
You can always ask questions, and I will do my best to answer them.
The Fourier transform is based on matching the frequencies in the signal with frequencies calculated in the transform. The more closely they match, the higher the coefficient returned by the Fourier transform. (The integral transform involved in calculating the Fourier series is more complicated than that, however that will do for the purposes of this discussion.) It has nothing to do with zero-crossings, and everything to do with the oscillations in the signal, without regard to the signal base line.
The frequency approximation technique I used (deriving the frequency from the distance between the peaks, or the period of the signal), is a simple (and imprecise) calculation intended to demonstrate that the frequency estimated by the fft was essentially the same as the frequency calculated by taking the mean value of the peak periods, nothing else. It also has nothing to do with zero-crossings, although I could have done something similar to that by using the mean of the signal and then calculating the crossings of that value.
There are methods to estimate the frequency and amplitude of the various signal components that do not directly involve the Fourier transform, however they are more complicated. Most of them (that I am familiar with) involve doing a linear or non-linear regression of the signal, and estimating the parameters of that model. The Fourier transform is simpler, more efficient, and more precise.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by