0
$\begingroup$

I am trying to test reconstruction of signal from IFFT. Below is the python program. I break the signal into overlapping windows and do FFT after multiplication with window function. Then I apply IFFT to the FFT output and then overlap-add to reconstruct the original signal. My problem is the reconstructed signal's amplitude is almost 10 times the input. Why is this so ? How can I scale it ?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

winsize=512
shift=16

aircutrawdata=pd.read_csv('input.csv',sep=',',skiprows=8000,skipfooter=3500).values
#%%
vibaxisdata=aircutrawdata[:,8]
data_len=len(vibaxisdata)
window_func=np.hanning(winsize)
fftdata=np.zeros((0,int(winsize/2)))
rec_frame=np.zeros(len(aircutrawdata))
for frame in range(0, data_len, shift):
# =============================================================================
#     if frame>0:
#          break
# =============================================================================
    kiri=vibaxisdata[frame:frame+winsize]
    if len(kiri) != winsize:
        break
    windata = window_func * kiri
    fftframe=np.fft.fft(windata,n=winsize)
    ifft_frame=np.real(np.fft.ifft(fftframe,n=winsize))
    rec_frame[frame:frame+winsize]+=ifft_frame

fig,(ax1,ax2)=plt.subplots(nrows=2,ncols=1)
ax1.plot(vibaxisdata,color='b')
ax2.plot(rec_frame,color='r')
plt.show()

The wave on the top is the original input and the wave at the bottom is the reconstructed signal. You can see that the signal is rather faithfully reconstructed except the amplitude. It is almost ten times the original. Is that how it is supposed to be ?

enter image description here

$\endgroup$
0
$\begingroup$

I tested your code with a random sequence as input.

Use 50% overlap to get unit gain i.e shift = winsize/2. If not then you have to compensate for adding the signal multiple times because of the overlap. I found the gain to be roughly winsize/(2*shift)

$\endgroup$
0
$\begingroup$

It's because you are probably adding back overlapping portions together, which adds same signal $N$ times where it seems $N \approx 10$ in your case. To test your algorithm use a zero overlapping case and see that IFFT produces the signal without a gain factor.

$\endgroup$

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.