Lab 5
Lab 5
−∞
1. Write the Fourier Transform of a function which is the difference of two unit functions.
Find its Inverse Fourier Transform as well as plot the graphs.
Code:
import numpy as np
import matplotlib.pyplot as plt
from sympy import *
f = Heaviside(t+1) - Heaviside(t-1)
plot(f, (t,-3,3))
fi = inverse_fourier_transform(F, w, t, noconds=True)
print(fi)
plot(F, (w,-10,10))
sin(2*pi*w)/(pi*w)
Piecewise((-t/Abs(t) + 1, (t > 1) | (t < -1)), (1, True))
f1 = cos(2*pi*t)
f2 = cos(4*pi*t)
f3 = cos(6*pi*t)
plot(f1+f2+f3, (t,-2,2))
t = np.linspace(-1, 1, num=5000)
f1 = np.cos(2 * np.pi * t)
f2 = np.cos(4 * np.pi * t)
f3 = np.cos(6 * np.pi * t)
f = f1 + f2 + f3
F = np.fft.fft(f)
freq = np.fft.fftfreq(len(t), t[1] - t[0])
plt.plot(freq, np.abs(F))
plt.xlim([-10, 10])
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.show()