Help with fourier transform

조회 수: 2 (최근 30일)
aurc89
aurc89 2014년 9월 18일
댓글: aurc89 2014년 9월 19일
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

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 9월 18일
편집: Geoff Hayes 2014년 9월 18일
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');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by