Help with fourier transform
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello! I'm using this function to perform a simple Fourier Transform:
function four=FourierDir(t,s,nu)
% number of points in the time domain
N=length(t);
Nf=length(nu);
% sampling step in the time domain
Dt=diff(t);
Dt(N)=Dt(N-1);
four=zeros(1,Nf);
for ii=1:Nf
four(ii)=sum(Dt.*s.*exp(-1i*2*pi.*t.*nu(ii)));
end;
How can I perform the same operation but using the matlab function 'fft' , given the same input parameters t,s,nu? s is the set of data I want to transform along t direction, nu is a vector I define for the number of points.
Thanks for the help
0 commentaires
Réponse acceptée
Geoff Hayes
le 18 Sep 2014
Modifié(e) : Geoff Hayes
le 18 Sep 2014
Suppose the following (I'm assuming that you have done something similar for t, s, and nu)
Fs = 8192; % sampling rate (Hz)
t = 0:1/Fs:1-1/Fs; % time period (seconds)
s = sin(2000*2*pi*t); % 2000 Hz signal
N = 8192; % N-point FFT (block size)
nu = 0:1:N-1; % number of points
We use your Discrete Fourier Transform function (is that what it is?) to get
dftY = FourierDir(t,s,nu);
and plot the results
fHz = 0:Fs/N:(N-1)*Fs/N;
figure;
plot(fHz,abs(dftY),'b');
Note that in the plot, we see the signal frequency at 2000 Hz with a height of 0.5 (not quite the amplitude of the signal).
Now if we do something similar with the MATLAB fft function as
yFft = fft(s,N);
and plot on the same figure
hold on;
plot(fHz,abs(yFft)*(2/N),'g'); % multiply by 2/N since input signal is real
we see that the FFT'd signal has a frequency of 2000 Hz and an amplitude of 1.0 (the 2/N factor gives us the amplitude of the input signal).
So all that is different between the MATLAB fft output and yours is a factor of two. I guess it all depends on what your function, FourierDir, is returning. If we want the fft data to be the same, then we could just do
hold on;
yFft = fft(s,N)*(2/N)/2; % now, yFft should be same as yDft
plot(fHz,abs(yFft),'g');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Discrete Fourier and Cosine Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!