Consider the following sound:

sound = ExampleData[{"Sound", "ViolinScale"}]

One may perform a FFT:

sound = ExampleData[{"Sound", "ViolinScale"}]
sampleRate = sound[[1, 2]];
fft = Fourier[samples];

I have a few very basic questions:

Am I right that the (modulus of) frequency corresponding to nth term is omega[n_]=(n-1)/Length[fft] sampleRate, where $n \in (1,\text{Length[fft]/2})$?

Also, am I right that the signal may be restored using fft as






signal[t_] = 1/Sqrt[Length[fft]]*(a0+Sum[(an[n]*Exp[2*Pi*omega[n]*t]+aMn[n]Exp[-2*Pi*omega[n]*t]),{n,1,Length[fft]/2-1}]+amax*Exp[2*Pi*omegamax*t])

where t denotes time in seconds, fft[[1]] is the zeroth frequency amplitude, and an, aMn are amplitudes corresponding to $\omega_{+n}$, $\omega_{-n}$, and the maximal frequency amplitude is $a_{\text{max}}$?


You have an odd number of data points, but you treat it like an even number.

Here is a working example that works for even or odd number of data points. First we need some simple test data. (Feel free to change the number of data points):

(*some test data*)
n = 10;
dat = Table[Exp[-x^2] Sin[4 x], {x, -Pi, Pi, 2 Pi/(n - 1)}];

Then we Fourier transform:

fft = Fourier[dat];

Finally we create the Fourier series and plot the result:

(*fourier synthese*)
tab = Table[
   Exp[ -2 Pi I If[i <= (n + 1)/2, (i - 1), -(n + 1 - i)] (x - 1)/n], {i, n}] ;
fun[x_] = (tab.fft + 
      fft[[1 + n/2]] (E^(-I \[Pi] (-1 + x)) - E^(I \[Pi] (-1 + x)))/2,0])/Sqrt[n];

Plot[fun[x], {x, 0, n}, PlotRange -> All, Epilog -> Point[Transpose[{Range[n], dat}]]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.