Hello,(adsbygoogle = window.adsbygoogle || []).push({});

Thank you for taking time to read my post.

I have a discrete set of data points that represent an acceleration signal. I want to take the integral of this set of points twice so as to get a function which represents the position over time.

To accomplish this, I have taken the FFT of the acceleration signal . From there I can extract the complex harmonics and plot the signal with reasonable accuracy. This part I can do and it works great. However I keep running into problems whenever I try to integrate the sinusoids. Can you take a look at my below code and see where I might be going wrong?

Inputs:

accel, this is suppose to be the FFT of the signal we want to integrate twice

w, omega = 2 pi f

L, how many harmonics you want to use (example, L=10 would use from n=-10,-9.....0...9,10)

Code (Text):

#feed a set of FFT points.

#will alter the coefficients of the real and complex points so as to

#account for integrating each harmonic twice!

#ideally, you will be able to input the acceleration and the ouput

#will be the trajectory of the position

def int2(accel,w,L):

sinusoids=[]

L=int(L)

period = (2*n.pi)/w

xaxis = n.linspace(0,period,num=len(accel))

position =[]

tempMain = 0;

for i in range(0,(len(accel)-1)):

for j in range(-L,L):

a_ = n.real(accel[j])

b_ = n.imag(accel[j])

n_ = len(accel)

if j!=0:

j2=j

tempMain -= (1/(j2**2))*(a_*n.cos(j*w*xaxis[i])+b_*n.sin(j*w*xaxis[i]))/n_

else:

j2=1

tempMain += ((xaxis[i]*xaxis[i])/(2))*(a_+b_)/n_

position.append(tempMain)

tempMain = 0

#we need to reverse the order of the list. This is bc the

# algorithim that computes the FFT results in the order

#being reversed. This is corrected whenever the IFFT is taken.

position=position[::-1]

return position

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# I Integrating FFT, python code

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - Integrating python code | Date |
---|---|

I Solving an integral | Yesterday at 4:38 PM |

I Integrate a function over a closed circle-like contour around an arbitrary point on a torus | Saturday at 12:51 PM |

A Integrate f(x) = tanh(c*x^b)? Wolfram says not possible ... | Mar 11, 2018 |

I Looking for additional material about limits and distributions | Feb 17, 2018 |

I Why 2 vectors are not the same in matlab? | May 17, 2017 |

**Physics Forums - The Fusion of Science and Community**