Understanding the FFT options

11 views (last 30 days)
Matt Thomas
Matt Thomas on 15 Aug 2023
Commented: Matt Thomas on 15 Aug 2023
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.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 15 Aug 2023
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 Comments
Image Analyst
Image Analyst on 15 Aug 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 on 15 Aug 2023
thank you for this. i will look into that. i highly appreciate everything from this place

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!