Home > Software design >  Why does my IDFT Computation differ from the value np.fft.ifft?
Why does my IDFT Computation differ from the value np.fft.ifft?

Time:11-15

I am trying to validate a simple IDFT routine I wrote -

###############################################################
#My IDFT Routines
###############################################################
def simple_idft(data_f):
    data_t_r = []
    data_t_i = []
    for ii in range(0,len(data_f)):
      tmp_r=0.00
      tmp_i=0.00
      scale = 1.00/len(data_f)
      for jj in range(0,len(data_f)):
        tmp_r  = data_f[jj].real*math.cos(2.00*math.pi*ii*jj/len(data_f)) - data_f[jj].imag*math.sin(2.00*math.pi*ii*jj/len(data_f))
        tmp_i  = data_f[jj].real*math.sin(2.00*math.pi*ii*jj/len(data_f))   data_f[jj].imag*math.cos(2.00*math.pi*ii*jj/len(data_f))
      tmp_r *=scale
      tmp_i *=scale
      data_t_r.append(tmp_r)
      data_t_i.append(tmp_i)
   return data_t_r, data_t_i
    

def rms_idft(data_t_r, data_t_i):
    rms = []
    for ii in range(0,len(data_t_r)):
        rms.append(math.sqrt(data_t_r[ii]**2   data_t_i[ii]**2))
    return rms

def do_idft(data_t):
    data_t_r, data_t_i = simple_idft(data_t)
    rms = rms_idft(data_t_r, data_t_i)
    return(rms)

against the numpy IDFT routine -

################################################################
#Transform OFDM Data to time domain
################################################################
def IDFT(OFDM_data):
    return np.fft.ifft(OFDM_data)

I seem to get very different results when I run these (64 point data) -

OFDM_time = IDFT(OFDM_data)
print ("Number of OFDM samples in time-domain before CP: ", len(OFDM_time))
print(OFDM_time)
plt.plot(OFDM_time)
plt.show()

NUMPY

rms = []
rms = do_idft(OFDM_data)
plt.plot(rms,label='raj')
plt.legend()
plt.show()

enter image description here

Can you see any error in my algorithm ?

CodePudding user response:

Okay I found the problem... The plotting of the Numpy IDFT routine output is wrong, rather it should be -

################################################################
#Transform OFDM Data to time domain
################################################################
def IDFT(OFDM_data):
    return np.fft.ifft(absOFDM_data)

OFDM_time = IDFT(OFDM_data)
print ("Number of OFDM samples in time-domain before CP: ", len(OFDM_time))
print(OFDM_time)
plt.plot(abs(OFDM_time))  **##need to take the absolute val**
plt.show()

enter image description here

  • Related