Understanding the FFT options

I was able to use the FFT function in MATLAB but I do not understand what it just did. My data has 48,000 time steps of 0.0063 seconds for each one, meaning my sampling frequency should be 160 per second.
The first thing I did was generate my data via:
%% Run this command first
%% Read a binary output file
% Read file
outbfile = '5MW_Land_DLL_WTurb.outb';
[Channels, ChanName, ChanUnit, FileID, DescStr] = ReadFASTbinary(outbfile);
time = Channels(:,1);
%%Change the plot number to reflect the parameter in channel names matrix generated from above command.
% Plot Channel 34
iChan=29
figure()
plot(time, Channels(:,iChan))
xlabel('Time (s)')
ylabel([ChanName(iChan) ChanUnit(iChan)])
Now, as per the documentation of fft:
Specify the parameters of a signal with a sampling frequency of 1 kHz and a signal duration of 1.5 seconds.
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
Why is this code needed? What is it doing? Should I set the Fs to be 160 to match my data?
Next I do :
y = fft(Channels(:,iChan));
and now the documentation has me do :
Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
Define the frequency domain f and plot the single-sided amplitude spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, longer signals produce better frequency approximations.
f = Fs*(0:(L/2))/L;
plot(f,P1)
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")
ylabel("|P1(f)|")
Sorry to ask, but what the HECK is going on here? What is this idea of a 2 sided spectrum?
What is this f=Fs*(0:(L/2))/L doing?
Thank you. I know nothing of programing or MATLAB so this is all new to me. Why do I even need the variable f=Fs*(0:(L/2))/L?
I dont mean to be that guy, but I am going to be that guy because that is how I learn. I appreciate everything.

Réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 15 Août 2023

0 votes

Here are a couple of correcttions to be made in your code:
...
Fs = 160; % Sampling frequency
T = 1/Fs; % Sampling period
L = 48000; % Length of signal
t = (0:L-1)*T; % Time vector
f=Fs*(0:(L/2))/L; % Frequency, [Hz]. It is a single-sided and thus, *(0:L/2)/L
...

6 commentaires

Matt Thomas
Matt Thomas le 15 Août 2023
intersting. so what is actually going on though? what is the idea behind using
f=Fs*(0:(L/2))/L;
what is this specifically doing for my data?
thank you very much for this help
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 15 Août 2023
Déplacé(e) : Voss le 15 Août 2023
f=Fs*(0:(L/2))/L; computes the frequency values for your data.
Walter Roberson
Walter Roberson le 15 Août 2023
fft() returns first the results for positive frequencies, and then the results for negative frequencies. For real data, the results for the negative frequencies are the conjugate of the results for the corresponding positive frequency. The total length, 0 frequency, positive frequencies, negative frequencies, must exactly equal the original length -- so the length of the output for the positive frequencies is within 1 of "half the original length". Where L is the original length, L/2 is the number of bins of positive frequencies. Each bin has phase and magnitude, so the "information content" of the L/2 bins is the same as the original information content.
The two different conventions are either to move the 0 frequency to the centre and draw everything, or else to draw only from 0 to the end of the positive frequencies, 0:L/2 bins.
Matt Thomas
Matt Thomas le 15 Août 2023
this is fasinating to me. thank you for this help. I wish my dang dyslexia wouldnt get in the way of things haha
Image Analyst
Image Analyst le 15 Août 2023
You might want to look at fftshift, which will put the zero frequency ("DC") in the middle of the array so that when plotted, it looks more normal. Otherwise the zero is at the first and last element so the plot typically looks like a half peak in the beginning (representing the positive frequencies), then lower values through the majority of the middle of the array, and then the left half of the peak (representing the negative frequencies) on the far right end of the array.
So if you're doing filtering (erasing/zeroing out array elements) you need to be careful of where your zero frequency is in the vactor.
Matt Thomas
Matt Thomas le 15 Août 2023
thank you for this. i will look into that. i highly appreciate everything from this place

Connectez-vous pour commenter.

Tags

Question posée :

le 15 Août 2023

Commenté :

le 15 Août 2023

Community Treasure Hunt

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

Start Hunting!

Translated by