title: Python - Inverse Fourier Transform
body: <h1>Problem</h1>
  
  <p>I am trying to remove a frequency from a set of data obtained from an audio file. </p>
  
  <p>To simplify down my problem, I have created the code below which creates a set of waves and merges them into a complex wave. Then it finds the fourier transform of this complex wave and inverses it. </p>
  
  <p>I am expecting to see the original wave as a result since there should be no data loss, however I receive a very different wave instead.</p>
  
  <h1>Code:</h1>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import random
  
  #Get plots
  fig, c1 = plt.subplots()
  c2 = c1.twinx()
  
  fs = 100 # sample rate 
  f_list = [5,10,15,20,100] # the frequency of the signal
  
  x = np.arange(fs) # the points on the x axis for plotting
  
  # compute the value (amplitude) of the sin wave for each sample
  wave = []
  for f in f_list:
      wave.append(list(np.sin(2*np.pi*f * (x/fs))))
  
  #Adds the sine waves together into a single complex wave
  wave4 = []
  for i in range(len(wave[0])):
      data = 0
      for ii in range(len(wave)):
          data += wave[ii][i]
      wave4.append(data)
  
  #Get frequencies from complex wave
  fft = np.fft.rfft(wave4)
  fft = np.abs(fft)
  
  #Note: Here I will add some code to remove specific frequencies
  
  #Get complex wave from frequencies
  waveV2 = np.fft.irfft(fft)
  
  #Plot the complex waves, should be the same
  c1.plot(wave4, color="orange")
  c1.plot(waveV2)
  plt.show()
  </code></pre>
  
  <h1>Results: (Orange is created wave, blue is original wave)</h1>
  
  <p><a href="https://i.stack.imgur.com/P3xak.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3xak.png" alt="Results"></a></p>
  
  <h1>Expected results:</h1>
  
  <p>The blue and orange lines (the original and new wave created) should have the exact same values</p>