Why inverse fft doesnt match with original signal

  fft, python, scipy

I have an audio wav file which has some vocals recorded. I have used scipy.read to digitize the wav file. I have calculated the FFT and then i get the inverse FFT from it.
When i plot the original signal and inverse FFT overlapped. They match exactly.
But when i plot the datasets of the original signal and the inverse FFT, they dont match at all.
I observed that this is happening only with a file having vocals, the same with an instrumental recording works fine.

Below is the code i have tried:

import scipy.io.wavfile as wavfile
import scipy
import scipy.fftpack as fftpack
from matplotlib import pyplot as plt
import pandas as pd
import csv
import numpy as np
fs_rate, signal = wavfile.read("Sa.wav")
print ("Frequency sampling", fs_rate," Hz")
l_audio = len(signal.shape)
print ("Channels", l_audio,"Audio data shape",signal.shape,"l_audio",l_audio)
if l_audio == 2:
    signal = signal.sum(axis=1) / 2
N = signal.shape[0]
length = N / fs_rate
print ("Duration of audio wav file in secs", length,"Samples chosen",signal.shape[0])
time =np.linspace(0, length, signal.shape[0])
sampling_interval=time[1]-time[0]

inverse_fft_amplitude = scipy.ifft(scipy.fft(signal)) 
plt.xlabel('Time[s]')
plt.ylabel('Amplitude')
plt.plot(time, signal, 'blue', time, inverse_fft_amplitude , 'red')
plt.legend(('Original Signal', 'Reconstructed Signal using Inverse FFT'))
# They match exactly same

#Getting the data points for original signal
df = pd.DataFrame({"Time" : time, "Amplitude" : signal})
df.to_csv("OriginalData.csv", header=None, index=False)

#Getting the data points for inverse FFT signal
df = pd.DataFrame({"Time" : time, "Amplitude" : abs(inverse_fft_amplitude)})
df.to_csv("ReconstructedDataSet.csv",  header=None,index=False)

Overlapping of Original signal and Inverse FFT
enter image description here

Overlapping original signal and inverse FFT data sets
enter image description here

Source: Python Questions

LEAVE A COMMENT