How to fit points using fft

505 Views Asked by At

Say I got a data of several points, for example:

[  6.32308617   5.33624905   0.46463384   2.70682874  18.76600741
  14.37138067   1.89334222  12.20420302  15.22460287   6.16349825]

Assume they are Y coordinates, and the corresponding X coordinates are:[0 1 2 3 4 5 6 7 8 9] plot them would be like that: Plot

Then I did a fft to the former data(which I assumed represents Y) using the fft() function in python numpy, which give me the list of complex number below:

[ 83.45383224 +0.00000000e+00j -15.21808989 +1.36388455e+01j
   5.87603709 +1.99268945e+01j  -5.84740275 -2.95182061e+01j
   4.13321389 +5.39872362e+00j   1.88951278 -3.37507799e-14j
   4.13321389 -5.39872362e+00j  -5.84740275 +2.95182061e+01j
   5.87603709 -1.99268945e+01j -15.21808989 -1.36388455e+01j]

And I want to generate a formula to fit the points. I thought these complex number represents $C_n$ in :

$s(x)=\sum_{n=-\infty}^{+\infty}C_ne^i$

but what is $i$ ? How can I construct a formula that could fit the plot? If that complex form is difficult to explain, how about a triangle form?

P.S. the purpose of the question is not to fit curve or something, but to generate formula through discrete data, I thought fft should be the way to do that

1

There are 1 best solutions below

2
On BEST ANSWER

It is $s(x)=\sum_{n=-\infty}^{+\infty}C_n e^{2i\pi nf_0x}$ with on your case : $f_0$ is $1/10$ (10 is the total length of the signal in your time unit).

FTT function gives $n*[C_0, C_1, C_2, C_3, C_4, C_5+C_{-5}, C_{-4}, C_{-3}, C_{-2}, C_{-1} ]$ Where n=10 (number of sample).

To compute it, you have to add zeros on your coefficients. As example, in Matlab :

Y=fft(y); 
Y2=[Y(1:5) Y(6)/2 zeros(1,9) Y(6)/2 Y(7:end)]*2; 
y2=ifft(Y2); 
plot(0:9,y,0:.5:9.5,y2)