Help me undersandand Frequency Vector and index vector in fourier transform

I have strated learning and I am new to Matlab and fourier transform I am Struggling to understand the concept of the frequency vector and index vector in this code below. I will be grateful if someone can explain what is frequency vector (Fv) and index vector (Iv) and what the code for both at Fv, Iv and FTs_plot is doing.
L = numel(t); % Vector Length
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTs = fft(s)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
FTs_plot = abs(FTs(Iv))/max(abs(FTs(Iv))); % Normalised Fourier Transform

 Accepted Answer

That is my code, so I will do my best to explain it.
The frequency vector ‘Fv’ here defines the frequencies for a one-sided Fourier transform, going from 0 Hz (d-c) to the Nyquist frequency. The length is determined by half the length of the original signal vector (+1 since it begins at 0). (Since the time vector is always a vector and not a matrix, and the signal could be a matrix, it is easier to use the time vector to determine the length of the signal.) The length of the two-sided Fourier transform (most easily appreciated after using fftshift on it) is the same as the length of the original signal vector (unless the length is increased by zero-padding it, that being a separate discussion).
The index vector ‘Iv’ just makes plotting and other references to the one-sided fft result easier. It is equal to the number of elements in the frequency vector, so the lengths match when plotted or otherwise processed.
With respect to ‘FTS_plot’, I am not certain what this code refers to (with this, I will have posted 13495 Answers, and I do not remember all of them), however it appears that it was intended to plot the normalised fft, so that the highest value is 1 and everything else is between 0 and 1. That is not how I usually plot fft results, so there must have been a specific reason for it.
If you have any further questions about my code here, I will do my best to address them.

4 Comments

Hi Star. I appreciate your response thanks. This is samll part of your code i took from this forum. The full code is as follow
D = load('time_domain.txt');
t = D(:,1);
s = D(:,2);
L = numel(t); % Vector Length
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTs = fft(s)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
FTs_plot = abs(FTs(Iv))/max(abs(FTs(Iv))); % Normalised Fourier Transform
figure
plot(Fv, FTs_plot)
grid
xlim([0 0.5])
I have few other questions if you don't mind answering.
1. Why did we include o HZ (DC ) in the fourier transform? many of tutorials i have been following on the internet recommends removing DC before performing FFT.
2. why do halve the Length of the signal in the Fv?
3. Is the FTs_plot simply normalising the mangtitudes of frequency components with respect to the highest frequency magnitude in the signal (i.e fundamental frequency magnitude)?
Thanks in advance for your time.
1. That varies, depending on the signal. A signal with a mean at or near 0 does not have to have the mean value of the signal (the d-c component) removed from it first. I always include it because it is part of the signal.
2. To plot or otherwise process) a one-sided Fourier transform.
3. Yes. (I thought I explained that in my original post.)

Sign in to comment.

More Answers (0)

Asked:

on 25 May 2020

Commented:

on 27 May 2020

Community Treasure Hunt

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

Start Hunting!