Re: Problem generating Fourier Series from FFT
- From: NZTideMan <mulgor@xxxxxxxxx>
- Date: 14 May 2007 14:57:23 -0700
On May 15, 7:44 am, redger...@xxxxxxxxx wrote:
I'm having trouble making a fourier series by calculating the
coefficients using the FFT. I'm just trying to select a few of the
harmonics to use to reconstruct the waveform that is input into fft.
The amplitudes are ok, but there seems to be an extra wavelength
inside the same domain as x when comparing the fourier series to just
using ifft.
Here's the algorithm that produces the odd behavior
y % signal
N = length(y)
x = 1:1:N % wave form is an edge from an image, so it's all in pixels
for the fourier analysis
yfft = fft(y)/N
Nq = ceil(N/2)
% Build the fourier series
f = zeros(size(y))
for j = 1:Nq
a_n = 2*imag(yfft(j))
b_n = 2*real(yfft(j))
f = f + b_n*cos(2*pi*x*j/N) + a_n*sin(2*pi*x*j/N)
end
then, plotting f vs x, and comparing with plotting ifft(yfft) vs x,
there's an extra wavelength in f (frequency higher than it should be),
and I can't figure out why?
(NOTE, I left out the code for only using certain harmonics since that
works fine with the ifft approach anyways)
If any body has any ideas, I'd really appreciate it, thanks
But the first freq in the DFT is zero. It is the mean.
You have displaced the frequencies backwards by 1 element.
You need to start at 2 not 1 in your loop.
.
- Follow-Ups:
- Re: Problem generating Fourier Series from FFT
- From: NZTideMan
- Re: Problem generating Fourier Series from FFT
- References:
- Problem generating Fourier Series from FFT
- From: redgerm21
- Problem generating Fourier Series from FFT
- Prev by Date: Re: Creating a matrix of strings
- Next by Date: Replacing FOR LOOP
- Previous by thread: Problem generating Fourier Series from FFT
- Next by thread: Re: Problem generating Fourier Series from FFT
- Index(es):
Relevant Pages
|