Implementation of Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) in Python: Full Source Code in Python

Implementation of Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) in Python: Full Source Code in Python
Implementation of Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) in Python: Full Source Code in Python

What is DFT?
  1. It stands for Discrete Fourier Transform.
  2. In the frequency domain, the DFT is used to examine discrete-time finite-duration signals.
  3. It is a numerical variant of Fourier transforms.

What is IDFT?
  1. It stands for Inverse Discrete Fourier Transform.
  2. It is used to convert the frequency domain signal to the time domain signal.

Code: 
import math
print()
x=[]
x=input("Enter the signal values = ").split(',')
fori in range(4):
x[i]=int(x[i])

mat=[]
fori in range(4):
 mat.append([])
for j in range(4):
 val=complex(int(math.cos((2*math.pi*i*j)/4)),-1*int(math.sin((2*math.pi*i*j)/4)))
 mat[i].append(val)

ans=[]
fori in range(4):
 sum=0
 for j in range(4):
  sum=sum+(mat[i][j]*x[j])
  ans.append(sum)
print()
print("The resultant discrete fourier transform =",ans)

imat=[]
fori in range(4):
 imat.append([])
for j in range(4):
 val=complex(int(math.cos((2*math.pi*i*j)/4)),1*int(math.sin((2*math.pi*i*j)/4)))
 imat[i].append(val)

ans1=[]
fori in range(4):
 sum=0
for j in range(4):
 sum=sum+(imat[i][j]*ans[j])
 ans1.append(sum/4)
print()
print("The resultant inverse discrete fourier transform =",ans1)





Post a Comment

0 Comments