0

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

omegamax=omega[Length[fft]/2+1];

a0=fft[[1]];

amax=fft[[Length[fft]/2+1]];

an[n_]:=fft[[n+1]]

aMn[n_]:=fft[[Length[fft]-1+n]]

signal[t_] = 1/Sqrt[Length[fft]](a0+Sum[(an[n]Exp[2Piomega[n]t]+aMn[n]Exp[-2Piomega[n]t]),{n,1,Length[fft]/2-1}]+amaxExp[2Piomegamaxt])

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}}$?

John Taylor
  • 5,701
  • 2
  • 12
  • 33
  • 1
    You might consider this question and answer: https://mathematica.stackexchange.com/q/33574/1783 And to invert the FFT , the simplest method would be to use InverseFourier. – bill s May 03 '21 at 22:22

1 Answers1

1

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 + 
     If[EvenQ[n], 
      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

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57