I have a time domain signal and want to convert to frequency domain using FFT. I would be very grateful if someone could help me plot frequency vs normalised FFT amplitude. I have attached my time domain file and a photo of how i would like my plot to be. Any help would be much appreciated.

 Réponse acceptée

Star Strider
Star Strider le 10 Sep 2019

0 votes

To normalise it to a maximum value of 1, divide the Fourier transformed data by the maximum of the Fourier transformed data:
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])

6 commentaires

Ambika Soram
Ambika Soram le 10 Sep 2019
how do I change the x-axis from 0 to 500?
There are several ways. One is to re-scale the sampling interval, then set xlim appropriately:
L = numel(t); % Vector Length
Ts = mean(diff(t)); % Sampling Interval
Ts = Ts/1000; % Sampling Interval Re-Scaled
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 500])
Another is to change the x-tick labels:
figure
plot(Fv, FTs_plot)
grid
xt = get(gca, 'XTick');
xtv = linspace(min(xt), max(xt), max(xt)*10);
set(gca, 'XTick',xtv, 'XTickLabel',xt*50)
xlim([0 0.505])
That affects only the plot, leaving the rest of the code unchanged.
Ambika Soram
Ambika Soram le 14 Sep 2019
Thanks a lot for the help.
Star Strider
Star Strider le 14 Sep 2019
As always, my pleasure!
Asrith Pyla
Asrith Pyla le 20 Avr 2021
@Star Strider I have a time series signal which has to be obtained in the frequency domain. In the above case, I see that for obtaining the x axes limits between 0 and 500 you have rescaled the sampling interval. Why should one has to rescale the sampling interval for changing the x axes bounds from [0, 0.5] to [0, 500]? I require my output between 1khz and 350khz [1000, 350000]. What should my sampling interval be?
Star Strider
Star Strider le 20 Avr 2021
I used the xlim call to ‘zoom’ the plot to show detail.
The sampling interval is created by the instrumentation, although you can use the resample functtion to change it or to regularize a signal with inconsistent sampling intervals so it can be used with other signal processing techniques, such as discrete filters. The sampling frequency is the inverse of the samplilng interval, and the highest frequency that that can be uniquely represented is the Nyquist frequency that is one-half of the sampling frequency.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by