Re: Problem generating Fourier Series from FFT



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.

.



Relevant Pages

  • Re: Problem generating Fourier Series from FFT
    ... harmonics to use to reconstruct the waveform that is input into fft. ... inside the same domain as x when comparing the fourier series to just ... there's an extra wavelength in f (frequency higher than it should be), ... works fine with the ifft approach anyways) ...
    (comp.soft-sys.matlab)
  • Problem generating Fourier Series from FFT
    ... I'm having trouble making a fourier series by calculating the ... harmonics to use to reconstruct the waveform that is input into fft. ... then, plotting f vs x, and comparing with plotting ifftvs x, ...
    (comp.soft-sys.matlab)
  • Re: Best way to measure precise harmonics?
    ... ostensibly due to a limited-sample FFT. ... containing a fundamental and a bunch of its near harmonics. ... looking for overtones in the spectrum of an excited string, ... the analyzer can resolve them. ...
    (sci.electronics.design)
  • Re: Guitar Tuner - Low frequencies are not working
    ... I started by trying to use the FFT ... at the moment of the attack, the fundamental has barely become established, and octave errors are very possible - so how long are you waiting (over how many FFT windows) before trying to derive the pitch? ... One method is in fact to detect the harmonics, compute their separation, and derive the fundamental as the average of those intervals. ... The high harmonics develop first - especially if you pick close to the bridge. ...
    (comp.dsp)
  • Re: Are harmonics real?
    ... Harmonics in a signal are as real as those mathematics, ... < case of the Fourier transform that's pretty darn real -- you can sum up ... related signals, though not all. ... < The FFT case is a bit problematical, because the FFT is only exact if you ...
    (comp.dsp)