0% found this document useful (0 votes)
7 views14 pages

( - COMM401 - ) 3 - Lab 7 (Lab Manual)

The document outlines Lab 7 of the Signals & Systems Theory course, focusing on the Fourier Transform and its application using the SciPy library in Python. It explains the continuous time Fourier Transform, provides code examples for generating time and frequency domain signals, and discusses the effects of adding noise to signals. The lab tasks involve calculating the Fourier Transform of specific signals and their noisy counterparts.

Uploaded by

yusuf tarek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

( - COMM401 - ) 3 - Lab 7 (Lab Manual)

The document outlines Lab 7 of the Signals & Systems Theory course, focusing on the Fourier Transform and its application using the SciPy library in Python. It explains the continuous time Fourier Transform, provides code examples for generating time and frequency domain signals, and discusses the effects of adding noise to signals. The lab tasks involve calculating the Fourier Transform of specific signals and their noisy counterparts.

Uploaded by

yusuf tarek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Signals & Systems Theory

(COMM401)
Lab 7- The Fourier Transform

Prepared by: Eng. Ghadir Mostafa


Supervised By: Prof. Dr. Ahmed El-Mahdy

Faculty of Information Engineering & Technologhy


Department of Communication Engineering 1
Continuous Time Fourier Transform
Fourier Transform is getting (transforming) the representation of the time domain
signal in the frequency domain:
F.T.
𝑥 𝑡 𝑋 𝑗𝜔
Where:
• 𝑥 𝑡 is the representation of the signal in time domain (how the signal changes
with time)
• 𝑋 𝑗𝜔 is the representation of the signal in frequency domain (how the signal
changes with frequency)
Note:
 𝑥 𝑡 can either be a periodic signal or an aperiodic signal.

2
Continuous Time Fourier Transform
If 𝒙 𝒕 is aperiodic signal:

1) Analysis Equation: (To get Fourier Transform)

𝑋 𝑗𝜔 = න 𝑥 𝑡 𝑒 −𝑗𝜔𝑡 𝑑𝑡
−∞

2) Inverse Fourier Transform:



1
𝑥 𝑡 = න 𝑋 𝑗𝜔 𝑒 𝑗𝜔𝑡 𝑑𝜔
2𝜋
−∞

3
SciPy Library
SciPy is an open-source library used for solving
mathematical, scientific, engineering, and technical
problems. It allows users to manipulate the data and
visualize the data using a wide range of high-level
Python commands. SciPy is built on the Python NumPy
extention.

SciPy vs. Numpy:


 SciPy module in Python is a fully-featured version of
Linear Algebra while Numpy contains only a few
features.
 Most new Data Science features are available in
Scipy rather than Numpy.

4
SciPy Library
scipy.fft.fft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None)
This function computes the 1-D n-point discrete Fourier Transform (DFT) with the
efficient Fast Fourier Transform (FFT) algorithm and returns a complex nd-array.
 Parameters:
1. x: Input array, can be complex.
2. n: an optional integer, denotes the length of the transformed axis of the output. If n is
smaller than the length of the input, the input is cropped. If it is larger, the input is
padded with zeros. If n is not given, the length of the input along the axis specified by
axis is used.
3. axis: an optional integer, denotes the axis over which to compute the FFT. If not given,
the last axis is used.

5
SciPy Library
scipy.fft.fft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None)
 Parameters:
4. norm: {“backward”, “ortho”, “forward”}, an optional normalization mode. Default is
“backward”, meaning no normalization on the forward transforms and scaling by 1/n on
the ifft. “forward” instead applies the 1/n factor on the forward transform. For
norm="ortho", both directions are scaled by 1/sqrt(n).
5. overwrite_x: an optional boolean, If True, the contents of x can be destroyed; the default
is False.
6. workers: an optional integer, denotes the maximum number of workers to use for
parallel computation.

6
Fourier Transform
𝑥 𝑡 = 𝐴1 sin 2𝜋𝑓1 𝑡 + 𝐴2 sin 2𝜋𝑓2 𝑡
Where 𝐴1 = 25 𝑉, 𝐴2 = 2 𝑉, 𝑓1 = 60 𝐻𝑧, 𝑓2 = 300 𝐻𝑧
A. Find the Fourier Transform of the signal x(t) which is sampled at Nyquist rate

𝑓𝑁𝑦𝑞 = 2 × 𝐵 such that 𝐵 = 1024 𝐻𝑧 is the signal bandwidth.

7
Time Domain Signal x(t)
import numpy as np
import matplotlib.pyplot as plt
from scipy import pi
from scipy.fftpack import fft

B= 1024
N = 2*B #Nyquist Rate
time = np.linspace(0, 1, N)
freq1 = 60
magnitude1 = 25
freq2 = 300
magnitude2 = 2

waveform1 = magnitude1 * np.sin (2 * pi * freq1 * time)


waveform2 = magnitude2 * np.sin (2 * pi * freq2 * time)
time_data = waveform1 + waveform2
plt.plot (time [0:100], time_data [0:100])
plt.title ('Time Domain Signal')
plt.xlabel ('Time')
plt.ylabel ('Amplitude')
plt.show ()

8
Frequency Domain Signal

frequency = np.linspace (0.0, B, np.int(N/2))


freq_data = fft(time_data) #Complex Signal
y = 2/N * np.abs (freq_data [0:np.int(N/2)])
plt.plot(frequency, y)
plt.title('Frequency domain Signal')
plt.xlabel('Frequency in Hz')
plt.ylabel('Amplitude')
plt.show()

#Notes:

1. freq_data [0:np.int(N/2)]: Takes the first N/2 elements (same size as the
frequency vector)
2. np.abs(): Takes the absolute of the complex signal to allow for plotting
3. 2/N : Multiplying by 2 because the spectrum returned by fft is symmetric about
the DC component (f=0). Since they are showing the single-sided amplitude
spectrum, the amplitude of each point is going to be doubled to account for the
contributions of data on the other side of the spectrum. Then dividing by N
because each point of the FFT transform is the result of a sum over a time
interval of N samples.

9
Fourier Transform
B. Now add a noise signal to 𝑥 𝑡 and find the corresponding Fourier Transform
of the noisy signal.
The noise signal is Gaussian with a mean 𝜇 = 0 and a standard deviation 𝜎 = 5.

Note: The standard deviation is a measure of how far the signal fluctuates from
the mean.

10
Time Domain Signal x(t)
import numpy as np
import matplotlib.pyplot as plt
from scipy import pi
from scipy.fftpack import fft

B= 1024
N = 2*B #Nyquist Rate
time = np.linspace(0, 1, N)
freq1 = 60
magnitude1 = 25
freq2 = 300
magnitude2 = 2
noise = np.random.normal (0,5, N) #takes the mean and standard deviation
waveform1 = magnitude1 * np.sin (2 * pi * freq1 * time)
waveform2 = magnitude2 * np.sin (2 * pi * freq2 * time)
time_data = waveform1 + waveform2 + noise
plt.plot (time [0:100], time_data [0:100])
plt.title ('Time Domain Signal')
plt.xlabel ('Time')
plt.ylabel ('Amplitude')
plt.show ()

11
Frequency Domain Signal
(Same Code as previous part)
frequency = np.linspace (0.0, B, np.int(N/2))
freq_data = fft(time_data) #Complex Signal
y = 2/N * np.abs (freq_data [0:np.int(N/2)])
plt.plot(frequency, y)
plt.title('Frequency domain Signal')
plt.xlabel('Frequency in Hz')
plt.ylabel('Amplitude')
plt.show()

#Notes:

 Even though the signal had noise


added, the frequency spectrum can
still be reconstructed, and the
frequency components remain
unchanged
 If 𝜎 is huge, the frequency
components are no longer
retrievable.

12
Task
𝑥 𝑡 = 𝐴1 cos 2𝜋𝑓1 𝑡 + 𝐴2 sin 2𝜋𝑓2 𝑡
Where 𝑓1 = first 3 digits of your ID and 𝑓2 = last 2 digits of your ID, 𝐴1 = your
age and 𝐴2 = your age/2.

A. Find the Fourier Transform of the signal x(t) which is sampled at Nyquist rate

𝑓𝑁𝑦𝑞 = 2 × 𝐵 such that 𝐵 = 1024 𝐻𝑧 is the signal bandwidth.


B. Now add a noise signal to 𝑥 𝑡 and find the corresponding Fourier Transform
of the noisy signal. The noise signal is Gaussian with a mean 𝜇 = 0 and a
random value for the noise standard deviation 𝜎.

13
Thank you
Good Luck =)

14

You might also like