Question: from numpy.fft import fft , ifft from numpy import real, imag #fft - - > computes fft of a list or numpy array #ifft -

from numpy.fft import fft, ifft
from numpy import real, imag
#fft --> computes fft of a list or numpy array
#ifft -> computes inverse fft of list or numpy array
# Create a list
lst0=[1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1]
# Compute its fft
fft_lst0= fft(lst0)
print(f'FFT of {lst0} is
\t {fft_lst0}')
# Compute iverse fft
ifft_lst0= ifft(fft_lst0)
print(f'After ifft: {ifft_lst0}')
# Check that all the imaginary parts are tiny in the ifft result
# Note that they will not be zero due to floating point error
assert(all([abs(imag(x))<=1E-10 for x in ifft_lst0])), 'Something went wrong -- we should not have complex parts to the ifft result'
# Extract the real parts
print('Note that we can suppress the vanishingly small complex cofficients')
fix_ifft_lst0=[real(x) for x in ifft_lst0]
print(f'After converting back to float: {fix_ifft_lst0}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!