Fourier transform of a function
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone, I come to you with a question on the fourier transform of a function.
I am trying to obtain the fourier transform of the signal of the position of an object depending on the time.
For now here is my signal (on the two image the top graph) and the fourier transform I obtain from the code I write below the images (taken from a previous question found in this site, quoted from Star Strider's answer).


function fourier_transform(z,h)
%z is 10 000
%h changes a lot depending on the result
figure;
subplot(211);
plot(z,h);
n = length(z);
Ts = 1; % Sampling Interval (one measure every one seconds for 10 000 seconds)
Fs = 1/Ts; % Sampling Frequency (samples)
Fn = Fs/2; % Nyquist Frequency
nfft = 2^nextpow2(n);
Hn = h-mean(h); % Remove Constant Offset > might not be necessary
ft = fft(Hn,nfft)/n;
Fv = linspace(0, 1, fix(n/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
subplot(212);
plot(Fv, abs(ft(Iv))*2)
The result obtained seem really wrong. Did I make a mistake in my code?
Thank you in advance for your help
JdC
0 Commenti
Risposta accettata
Star Strider
il 7 Mar 2022
The only problem I see is in the ‘Fv’ calculation.
It should be:
Fv = linspace(0, 1, (nfft/2)+1)*Fn; % Frequency Vector
Apparently, my original code (that I thank you for quoting) did not use ‘nfft’ as calculated here. (If it did, not calculating ‘Fv’ correctly was my error, and I apologise for it.)
.
2 Commenti
Star Strider
il 7 Mar 2022
As always, my pleasure!
No worries — I just recognised my code (there’s a lot of it out there). No specific citation necessary, however I like to be cerrtain that my posted code works correctly.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!