0% found this document useful (0 votes)
26 views23 pages

Signal Adn System

The document is a lab report for the BSc Information Engineering Technology course at Mirpur University, detailing various experiments in Signals and Systems. It includes objectives, procedures, and source code for experiments such as generating sine and cosine waves, unit step signals, and signal manipulation simulations. The report is submitted by Ammad Ali and covers a range of signal processing techniques using NumPy and Matplotlib.

Uploaded by

Ammad Ali
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)
26 views23 pages

Signal Adn System

The document is a lab report for the BSc Information Engineering Technology course at Mirpur University, detailing various experiments in Signals and Systems. It includes objectives, procedures, and source code for experiments such as generating sine and cosine waves, unit step signals, and signal manipulation simulations. The report is submitted by Ammad Ali and covers a range of signal processing techniques using NumPy and Matplotlib.

Uploaded by

Ammad Ali
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/ 23

Page 1

Mirpur University of Science and Technology (MUST)


MirpurAzad Jammu & Kashmir

BSc Information Engineering Technology

Lab Report: Signal And Systems

• Submitted By: Ammad Ali

• Submitted to: Engr. Adnan Ashraf

• Roll No: FA22-IET-001

• Session: 2022-2026

• Course Code: IET-354L

• Semester: 5th

MIT-MUST MIRPUR
Page 2

List of Experiments Signals and System Lab:

Lab.No Experiment

01. Sine Wave Generator

02. Cosine Wave Plotter

03. Sine and Cosine Wave Explorer

04. Continuous-Time Unit Step Signal Plotter

05. Discrete-Time Unit Step Signal Plotter

06. Discrete-Time Ramp Signal Plotter

07. Signal Addition Simulator

08. Signal Subtraction Simulator

09. Signal Multiplication Simulator

10. Signal Division Simulator

11 Matrix Creation and Display

12. Time Domain Signal Manipulation and Amplitude Modulation Simulator

13. Matrix Operations: Division, Multiplication, and Element-wise Multiplication

14. Decomposition of a Signal into Even and Odd Components


Page 3

LAB 01: Sine Wave Generator:

Objective:
To generate and visualize a sine wave using NumPy and Matplotlib, illustrating the influence
of frequency, amplitude, and sampling rate on signal characteristics.

Procedure:

1. Import NumPy for data computation and Matplotlib for visualization.


2. Define parameters: frequency, amplitude, sampling rate, and duration.
3. Generate a time array using np.linspace.
4. Calculate the sine wave using the formula:
sine_wave=amplitude×sin⁡(2π×frequency×t)\text{sine\_wave} = \text{amplitude}
\times \sin(2 \pi \times \text{frequency} \times t)
5. Plot the sine wave with appropriate labels, title, and legend.
6. Display the plot with a grid for clarity.

Source Code:

import numpy as np
import matplotlib.pyplot as plt

# Define parameters
frequency = 10 # Frequency in Hz
amplitude = 1 # Amplitude of the sine wave
sampling_rate = 1000 # Sampling points per second
duration = 2 # Duration in seconds

# Generate time values


t = np.linspace(0, duration, int(sampling_rate * duration))

# Generate sine wave values


sine_wave = amplitude * np.sin(2 * np.pi * frequency * t)

# Plot the sine wave


plt.figure(figsize=(10, 6))
plt.plot(t, sine_wave, label=f'Sine Wave (f = {frequency} Hz)',
color='blue')

plt.title('Sine Wave with Frequency Control')


plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.legend()

plt.figtext(0.15, 0.85, 'Roll No: FA22-IET-001', fontsize=12,


color='red')
plt.show()
Page 4
Page 5

LAB 02: Cosine Wave Plotter:

Objective:
To generate and visualize a cosine wave using NumPy and Matplotlib, demonstrating the
impact of frequency, amplitude, and sampling rate on the waveform.

Procedure:

1. Import NumPy for numerical operations and Matplotlib for plotting.


2. Define parameters: frequency, amplitude, sampling rate, and duration.
3. Generate a time array using np.linspace.
4. Calculate the cosine wave using the formula:
cosine_wave=amplitude×cos⁡(2π×frequency×t)\text{cosine\_wave} =
\text{amplitude} \times \cos(2 \pi \times \text{frequency} \times
t)cosine_wave=amplitude×cos(2π×frequency×t)
5. Plot the cosine wave with appropriate labels, title, and legend.
6. Display the plot with a grid for better readability.

Code:
import numpy as np
import matplotlib.pyplot as plt

# Define the range of x values


x = np.linspace(0, 2 * np.pi, 1000) # 0 to 2π with 1000 points

# Define the cosine wave


y = np.cos(x)

# Plot the cosine wave


plt.figure(figsize=(8, 5)) # Set the figure size
plt.plot(x, y, label='cos(x)', color='r') # Plot the cosine wave in red

# Add title and labels


plt.title('Cosine Wave', fontsize=16)
plt.xlabel('x (radians)', fontsize=12)
plt.ylabel('cos(x)', fontsize=12)

# Add grid and legend


plt.grid(True, linestyle='--', alpha=0.6)
plt.legend(fontsize=12)

plt.figtext(0.15, 0.85, 'Roll No: FA22-IET-001', fontsize=12, color='blue')

plt.show()
Page 6
Page 7

LAB 03: Sine and Cosine Wave Explorer:

Objective:
To develop a program that generates and visualizes both sine and cosine waves using NumPy
and Matplotlib, enabling exploration of waveform properties influenced by frequency,
amplitude, and sampling rate.

Procedure:

1. Import NumPy for mathematical calculations and Matplotlib for data visualization.
2. Define parameters: frequency, amplitude, sampling rate, and duration.
3. Generate a time array using np.linspace.
4. Compute sine and cosine wave values using the formulas:
sine_wave=amplitude×sin⁡(2π×frequency×t)\text{sine\_wave} = \text{amplitude} \times
\sin(2 \pi \times \text{frequency} \times t)sine_wave=amplitude×sin(2π×frequency×t)
cosine_wave=amplitude×cos⁡(2π×frequency×t)\text{cosine\_wave} = \text{amplitude}
\times \cos(2 \pi \times \text{frequency} \times
t)cosine_wave=amplitude×cos(2π×frequency×t)
5. Plot both sine and cosine waves with distinct colors, labels, and styles.
6. Add titles, axis labels, a grid, and a legend to enhance readability.
7. Display the plot to explore waveform behavior.

Code:
import numpy as np
import matplotlib.pyplot as plt

# Roll Number: FA22-IET-001

# Define parameters
frequency = 5 # Frequency in Hz
amplitude = 1 # Amplitude of the waves
sampling_rate = 1000 # Sampling points per second
duration = 2 # Duration in seconds

# Generate time values


t = np.linspace(0, duration, int(sampling_rate * duration))

# Generate sine and cosine wave values


sine_wave = amplitude * np.sin(2 * np.pi * frequency * t)
cosine_wave = amplitude * np.cos(2 * np.pi * frequency * t)

# Plot both sine and cosine waves


plt.figure(figsize=(10, 6))
plt.plot(t, sine_wave, label=f'Sine Wave (f = {frequency} Hz)',
color='blue')
plt.plot(t, cosine_wave, label=f'Cosine Wave (f = {frequency} Hz)',
color='red', linestyle='--')

# Add title and labels


plt.title('Sine and Cosine Wave Explorer')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.legend()

# Display roll number


Page 8

plt.figtext(0.15, 0.85, 'Roll No: FA22-IET-001', fontsize=12, color='red')

# Display the plot


plt.show()
Page 9

LAB 04: Continuous-Time Unit Step Signal Plotter:

Objective:
To create a program that generates and visualizes a continuous-time unit step signal using
NumPy and Matplotlib, illustrating the characteristics of step functions commonly used in
signal processing.

Procedure:

1. Import NumPy for data generation and Matplotlib for plotting.


2. Define a time range using np.linspace to simulate continuous time.
3. Create a unit step signal, where values are 0 for negative time and 1 for time ≥ 0.
4. Plot the unit step signal with appropriate labels and title.
5. Add grid lines for clarity and display the plot.

Code:
import numpy as np
import matplotlib.pyplot as plt

# Roll Number: FA22-IET-001

# Define time range


t = np.arange(-7, 8, 1)

# Define unit step function (Heaviside function)


ut = np.heaviside(t, 1)

# Plot the unit step function


plt.figure(figsize=(8, 5))
plt.subplot(2, 1, 1)
plt.plot(t, ut, marker='o', linestyle='-', color='blue')
plt.axis([-10, 10, -1, 2])
plt.xlabel('Time')
plt.ylabel('u(t)')
plt.title('Unit Step Function')
plt.grid(True)

# Display roll number


plt.figtext(0.15, 0.85, 'Roll No: FA22-IET-001', fontsize=12, color='red')

# Show the plot


plt.show()
Output:
Page 10

LAB 05: Discrete-Time Unit Step Signal Plotter:

Objective:
To implement a program for generating and visualizing a discrete-time unit step signal using
NumPy and Matplotlib, demonstrating the characteristics of step functions in discrete-time
systems for signal analysis.

Procedure:

1. Import NumPy and Matplotlib for data handling and plotting.


2. Define a discrete set of time values.
3. Create a unit step signal where values are 0 for time indices less than 0 and 1 for time indices
greater than or equal to 0.
4. Use a stem plot to clearly differentiate discrete points.
5. Add appropriate labels, title, and grid lines to enhance visualization.

Code:
import numpy as np
import matplotlib.pyplot as plt

# Define discrete time range


n = np.arange(-10, 11, 1) # Discrete time indices from -10 to 10

# Generate discrete-time unit step signal


unit_step = np.where(n >= 0, 1, 0)

# Plot the discrete-time unit step signal


plt.figure(figsize=(10, 6))
plt.stem(n, unit_step, linefmt='b-', markerfmt='bo', basefmt='k-') #
Removed 'use_line_collection'

# Add title and labels


plt.title('Discrete-Time Unit Step Signal')
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.axhline(0, color='gray', linewidth=0.8) # X-axis
plt.axvline(0, color='gray', linewidth=0.8) # Y-axis

# Display the plot


plt.show()
Page 11

Output:
Page 12

LAB 6: Discrete-Time Ramp Signal Plotter

Objective:
To generate and visualize a discrete-time ramp signal for understanding linear signal behavior
in discrete systems.

Procedure:

1. Define a discrete-time range using np.arange.


2. Create ramp values by setting each time step as its corresponding amplitude.
3. Use a stem plot to visualize the ramp signal.

Code:

import numpy as np
import matplotlib.pyplot as plt

n = np.arange(-10, 11, 1)
ramp_signal = np.where(n >= 0, n, 0)

plt.figure(figsize=(10, 6))
plt.stem(n, ramp_signal, linefmt='blue', markerfmt='bo', basefmt='black')
plt.title('Discrete-Time Ramp Signal')
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.axhline(0, color='gray')
plt.axvline(0, color='gray')
plt.show()

Output:
Page 13

LAB 7:Signal Addition Simulator

Objective:
To simulate the addition of two signals for understanding signal superposition principles.

Procedure:

1. Generate two signals.


2. Add corresponding points to create the combined signal.
3. Plot all signals for comparison.

Code:

import numpy as np
import matplotlib.pyplot as plt

n = np.arange(-10, 11, 1)
signal1 = np.sin(0.1 * np.pi * n)
signal2 = np.cos(0.1 * np.pi * n)
added_signal = signal1 + signal2

plt.figure(figsize=(10, 6))
plt.stem(n, added_signal, label='Signal Addition', linefmt='purple',
markerfmt='ro', basefmt='gray')
plt.legend()
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()

Output:
Page 14

LAB 8: Signal Subtraction Simulator

Objective:
To simulate signal subtraction for analyzing differences between two signals.

Procedure:

1. Generate two signals.


2. Subtract corresponding points.
3. Plot the signals and their difference.

Code:

import numpy as np
import matplotlib.pyplot as plt
subtracted_signal = signal1 - signal2
plt.figure(figsize=(10, 6))
plt.stem(n, subtracted_signal, label='Signal Subtraction', linefmt='red',
markerfmt='go', basefmt='gray')
plt.legend()
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()

Output:
Page 15

LAB 9: Signal Multiplication Simulator

Objective:
To simulate multiplication of two signals for amplitude modulation effects.

Procedure:

1. Generate two signals.


2. Multiply corresponding points.
3. Plot the resulting signal.

Code:

import numpy as np
import matplotlib.pyplot as plt
multiplied_signal = signal1 * signal2
plt.figure(figsize=(10, 6))
plt.stem(n, multiplied_signal, label='Signal Multiplication',
linefmt='green', markerfmt='mo', basefmt='gray')
plt.legend()
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()

Output:
Page 16

LAB 10: Signal Division Simulator


Objective:
To simulate the division of two signals for exploring ratio behavior in signal analysis.

Procedure:

1. Generate two signals.


2. Divide corresponding points, handling division by zero.
3. Plot the result.

Code:

import numpy as np
import matplotlib.pyplot as plt
divided_signal = np.divide(signal1, signal2, out=np.zeros_like(signal1),
where=signal2 != 0)
plt.figure(figsize=(10, 6))
plt.stem(n, divided_signal, label='Signal Division', linefmt='orange',
markerfmt='co', basefmt='gray')
plt.legend()
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()

Output:
Page 17

LAB 11: Time Domain Signal Manipulation and Amplitude Modulation Simulator

Objective:
To perform amplitude modulation by varying the amplitude of a carrier signal with a
modulating signal.

Procedure:

1. Define a carrier and modulating signal.


2. Apply amplitude modulation:
modulated_signal=carrier×(1+modulator)\text{modulated\_signal} = \text{carrier} \times (1
+ \text{modulator})modulated_signal=carrier×(1+modulator)
3. Plot the carrier, modulator, and modulated signals.

Code:

import numpy as np
import matplotlib.pyplot as plt
modulator = np.sin(0.05 * np.pi * n)
carrier = np.sin(0.2 * np.pi * n)
modulated_signal = carrier * (1 + modulator)

plt.figure(figsize=(10, 6))
plt.stem(n, modulated_signal, label='Amplitude Modulation', linefmt='blue',
markerfmt='ro', basefmt='gray')
plt.legend()
plt.xlabel('n (Discrete Time)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()

Output:
Page 18

LAB 12: Matrix Creation and Display

Objective:
To create and display matrices for basic linear algebra operations.

Procedure:

1. Define matrices using np.array().


2. Display the matrices.

Code:

import numpy as np
import matplotlib.pyplot as plt

# Define a 2x2 matrix A


matrix_a = np.array([[1, 2], [3, 4]])
# Define a 2x2 matrix B
matrix_b = np.array([[5, 6], [7, 8]])

# Display matrix A
print("Matrix A:\n", matrix_a)
# Display matrix B
print("Matrix B:\n", matrix_b)

Output
Page 19

LAB 13: Matrix Operations: Division, Multiplication, and Element-wise


Multiplication

Objective:
To perform matrix operations and demonstrate linear transformations.

Procedure:

1. Multiply matrices using np.dot().


2. Perform element-wise operations.

Code:

import numpy as np
import matplotlib.pyplot as plt

# Define two matrices (this step assumes matrix_a and matrix_b are already
defined)
# Example matrices for demonstration:
matrix_a = np.array([[1, 2], [3, 4]])
matrix_b = np.array([[5, 6], [7, 8]])

# Matrix multiplication using dot product (standard matrix multiplication)


matrix_mult = np.dot(matrix_a, matrix_b)
# Element-wise multiplication (corresponding elements of both matrices are
multiplied)
element_mult = matrix_a * matrix_b
# Element-wise division (corresponding elements of matrix_a are divided by
matrix_b)
element_div = np.divide(matrix_a, matrix_b)

# Displaying results of each matrix operation


print("Matrix Multiplication:\n", matrix_mult) # Prints the result of
standard matrix multiplication
print("Element-wise Multiplication:\n", element_mult) # Prints the result
of element-wise multiplication
print("Element-wise Division:\n", element_div) # Prints the result of
element-wise division

Output:
Page 20

LAB 14: Time Domain Signal Manipulation and Amplitude Modulation Simulator:
Objective:
To simulate and visualize time domain signal manipulation (delay and advance) and amplitude
modulation using MATLAB.

Procedures:
1. Clear all variables and close all figures.
2. Define the parameters (amplitude and frequency) for the signal (x1).
3. Generate the signal (x1) using the sinusoidal function.
4. Plot the delayed signal (x1) by 2 intervals.
5. Plot the advanced signal (x1) by 2 intervals.
6. Define the carrier frequency (Fc) and sampling frequency (Fs).
7. Generate a time array (t) based on the sampling frequency (Fs).
8. Generate a sine wave (x) with the time duration of 't'.
9. Perform amplitude modulation on the sine wave (x) using the ammod function. Plot the
amplitude modulated signal (y).
Code:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import Hilbert

a = 4 # Amplitude
f = 3 # Frequency
t = np.arange(0, 1.01, 0.01) # Time range
x1 = a * np.sin(2 * np.pi * f * t)

# Plot delayed signal


plt.figure(1)
plt.plot(t + 2, x1, label='Delayed Signal', color='blue')
plt.xlabel('Time (s)')
plt.ylabel('Signal')
plt.title('Delayed Signal')
plt.legend()
plt.grid(True)

# Plot advanced signal


plt.figure(2)
plt.plot(t - 2, x1, label='Advanced Signal', color='red')
plt.xlabel('Time (s)')
plt.ylabel('Signal')
plt.title('Advanced Signal')
plt.legend()
plt.grid(True)

# Define carrier frequency and sampling frequency


Fc = 300 # Changed carrier frequency
Fs = 4000 # Sampling frequency

# Define time duration


t = np.arange(0, 1, 1 / Fs)

# Generate sine wave


x = np.sin(2 * np.pi * f * t)

# Amplitude Modulation
Page 21

y = x * np.cos(2 * np.pi * Fc * t)

# Plot amplitude modulation


plt.figure(3)
plt.plot(t, y, label='AM Signal', color='green')
plt.title('Amplitude Modulation')
plt.xlabel('Time (sec)')
plt.ylabel('Amplitude')
plt.legend()
plt.grid(True)
plt.show()

Output:
Page 22

LAB 15: Decomposition of a Signal into Even and Odd Components

Objective:
To decompose a signal into its even and odd parts for symmetry analysis.

Procedure:

1. Define a signal.
2. Compute even and odd components.
3. Plot all signals.

Code:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-5, 6)
signal = np.sin(x)
even_part = (signal + np.flip(signal)) / 2
odd_part = (signal - np.flip(signal)) / 2

plt.figure(figsize=(10, 6))
plt.stem(x, signal, label='Original Signal')
plt.stem(x, even_part, label='Even Component', linefmt='blue',
markerfmt='bo')
plt.stem(x, odd_part, label='Odd Component', linefmt='red', markerfmt='ro')
plt.legend()
plt.grid(True)
plt.show()

Output:
Page 23

You might also like