0% found this document useful (0 votes)
5 views39 pages

Signal and System

This document is a lab report for the BSc Information Engineering Technology course at Mirpur University of Science and Technology, detailing various experiments conducted in the Signals and Systems lab. It includes objectives, procedures, and sample code for generating and visualizing different types of signals such as sine, cosine, unit step, and ramp signals. The report is submitted by Ammad Ali and covers experiments from generating basic waveforms to signal operations like addition, subtraction, and multiplication.

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)
5 views39 pages

Signal and System

This document is a lab report for the BSc Information Engineering Technology course at Mirpur University of Science and Technology, detailing various experiments conducted in the Signals and Systems lab. It includes objectives, procedures, and sample code for generating and visualizing different types of signals such as sine, cosine, unit step, and ramp signals. The report is submitted by Ammad Ali and covers experiments from generating basic waveforms to signal operations like addition, subtraction, and multiplication.

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/ 39

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
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

15. Continuous-Time Ramp Signal

16. Time-Frequency Analysis of Multiple Signals:

17. Time-Frequency Analysis of Common Waveforms:

18 Rectangular Function and its Fourier Transform (Sinc Function):

19.
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()
4
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()
6
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


8

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

# Display the plot


plt.show()

OUTPUT:
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:
t = -7:1:7;

% Define unit step function (Heaviside function)


ut = double(t >= 0);

% Create a new figure with a specified position


figure('Position', [100, 100, 800, 500]);

% Plot the unit step function


subplot(2, 1, 1);
plot(t, ut, 'bo-', 'LineWidth', 1.5);
axis([-10 10 -1 2]);
xlabel('Time');
ylabel('u(t)');
title('Unit Step Function');
grid on;

% Display roll number


text(0.15, 0.85, 'Roll No: FA22-IET-001', ...
'FontSize', 12, 'Color', 'red');

% Show the plot


hold off;
Output:
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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate discrete-time unit step signal


unit_step = double(n >= 0); % Heaviside function: 1 for n >= 0, 0
otherwise

% Plot the discrete-time unit step signal


figure('Position', [100, 100, 800, 600]);
stem(n, unit_step, 'b', 'LineWidth', 1.5, 'MarkerFaceColor', 'b'); % Stem
plot with blue color

% Add title and labels


title('Discrete-Time Unit Step Signal');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;
hold on;

% Add X and Y axis lines at n = 0


plot([min(n) max(n)], [0 0], 'k', 'LineWidth', 0.8); % X-axis line
plot([0 0], [min(unit_step) max(unit_step)], 'k', 'LineWidth', 0.8); % Y-
axis line

% Display the plot


hold off;
11

Output:
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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate discrete-time ramp signal


ramp_signal = max(n, 0); % Ramp function: n for n >= 0, 0 for n < 0

% Plot the discrete-time ramp signal


figure('Position', [100, 100, 800, 600]);
stem(n, ramp_signal, 'b', 'LineWidth', 1.5, 'MarkerFaceColor', 'b'); % Stem
plot with blue color

% Add title and labels


title('Discrete-Time Ramp Signal');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;
hold on;

% Add X and Y axis lines at n = 0


plot([min(n) max(n)], [0 0], 'k', 'LineWidth', 0.8); % X-axis line
plot([0 0], [min(ramp_signal) max(ramp_signal)], 'k', 'LineWidth', 0.8); %
Y-axis line

% Display the plot


hold off;
13

Output:
14

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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)

% Add the two signals


added_signal = signal1 + signal2;

% Plot the added signal


figure('Position', [100, 100, 800, 600]);
stem(n, added_signal, 'ro-', 'LineWidth', 1.5, 'MarkerFaceColor', 'r'); %
Stem plot with red color and circles

% Add title and labels


title('Signal Addition');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Display legend
legend('Signal Addition');

% Show the plot


hold off;
15

Output:
16

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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)

% Subtract the two signals


subtracted_signal = signal1 - signal2;

% Plot the subtracted signal


figure('Position', [100, 100, 800, 600]);
stem(n, subtracted_signal, 'go-', 'LineWidth', 1.5, 'MarkerFaceColor',
'g'); % Stem plot with green color and circles

% Add title and labels


title('Signal Subtraction');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Display legend
legend('Signal Subtraction');

% Show the plot


hold off;
Output:
17
18

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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)

% Multiply the two signals


multiplied_signal = signal1 .* signal2;

% Plot the multiplied signal


figure('Position', [100, 100, 800, 600]);
stem(n, multiplied_signal, 'mo-', 'LineWidth', 1.5, 'MarkerFaceColor',
'm'); % Stem plot with magenta color and circles

% Add title and labels


title('Signal Multiplication');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Display legend
legend('Signal Multiplication');

% Show the plot


hold off;
19

Output:
20

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:

% Define discrete time range


n = -10:1:10; % Discrete time indices from -10 to 10

% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)

% Divide the two signals, handling division by zero by setting it to 0


divided_signal = signal1 ./ signal2;
divided_signal(isnan(divided_signal)) = 0; % Handle division by zero by
setting NaN to 0

% Plot the divided signal


figure('Position', [100, 100, 800, 600]);
stem(n, divided_signal, 'co-', 'LineWidth', 1.5, 'MarkerFaceColor', 'c'); %
Stem plot with cyan color and circles

% Add title and labels


title('Signal Division');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Display legend
legend('Signal Division');

% Show the plot


hold off;
Output:
21
22

LAB 11: 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:

% Define a 2x2 matrix A


matrix_a = [1, 2; 3, 4];

% Define a 2x2 matrix B


matrix_b = [5, 6; 7, 8];

% Display matrix A
disp('Matrix A:');
disp(matrix_a);

% Display matrix B
disp('Matrix B:');
disp(matrix_b);
Output
23

LAB 12: 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:

% Define two matrices


matrix_a = [1, 2; 3, 4];
matrix_b = [5, 6; 7, 8];

% Matrix multiplication using the '*' operator (standard matrix


multiplication)
matrix_mult = matrix_a * matrix_b;

% Element-wise multiplication using the '.*' operator


element_mult = matrix_a .* matrix_b;

% Element-wise division using the './' operator


element_div = matrix_a ./ matrix_b;

% Displaying results of each matrix operation


disp('Matrix Multiplication:');
disp(matrix_mult);

disp('Element-wise Multiplication:');
disp(element_mult);

disp('Element-wise Division:');
disp(element_div);
Output:
24

LAB 13: 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:
clc; clear; close all;

% Define parameters
a = 4; % Amplitude
f = 3; % Frequency
t = 0:0.01:1; % Time range
x1 = a * sin(2 * pi * f * t);

% Plot delayed signal


figure(1);
plot(t + 2, x1, 'b', 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Signal');
title('Delayed Signal');
legend('Delayed Signal');
grid on;

% Plot advanced signal


figure(2);
plot(t - 2, x1, 'r', 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Signal');
title('Advanced Signal');
legend('Advanced Signal');
grid on;

% Define carrier frequency and sampling frequency


Fc = 300; % Changed carrier frequency
Fs = 4000; % Sampling frequency

% Define time duration


t = 0:1/Fs:1;

% Generate sine wave


x = sin(2 * pi * f * t);

% Amplitude Modulation
y = x .* cos(2 * pi * Fc * t);

% Plot amplitude modulation


25

figure(3);
plot(t, y, 'g', 'LineWidth', 1.5);
title('Amplitude Modulation');
xlabel('Time (sec)');
ylabel('Amplitude');
legend('AM Signal');
grid on;
Output:
26

LAB 14: 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:

clc; clear; close all;

% Define discrete-time range


x = -5:1:5;
signal = sin(x);

% Compute even and odd components


even_part = (signal + fliplr(signal)) / 2;
odd_part = (signal - fliplr(signal)) / 2;

% Plot the original signal, even component, and odd component


figure;
stem(x, signal, 'k', 'LineWidth', 1.5, 'DisplayName', 'Original Signal');
hold on;
stem(x, even_part, 'b', 'LineWidth', 1.5, 'DisplayName', 'Even Component');
stem(x, odd_part, 'r', 'LineWidth', 1.5, 'DisplayName', 'Odd Component');
hold off;

% Formatting the plot


xlabel('n (Discrete Time)');
ylabel('Amplitude');
title('Even and Odd Components of a Signal');
legend;
grid on;
27

Output:
28

LAB 15: Fourier Analysis of Common Signals:


Objective:
The objective of this code is to generate and visualize various time-domain signals
(impulse, step, sine, cosine, square, and sawtooth waves) and their corresponding
frequency-domain representations using the Fast Fourier Transform (FFT)
algorithm.

Procedures:
1. Define the sampling frequency (fs), signal duration (T), and time vector
(t).
2. Calculate the number of samples (N) and frequency axis (f).
3. Generate the impulse, step, sine, cosine, square, and sawtooth wave signals
using their respective mathematical formulas.
4. Apply the FFT algorithm to each time-domain signal to obtain their
frequency-domain representations.
5. Use the fftshift function to shift the FFT output to center the zero-
frequency component.
6. Create a figure with multiple subplots to display the time-domain signals
and their corresponding frequency-domain representations.
7. Use the stem and plot functions to visualize the signals in the time and
frequency domains, respectively.
8. Add titles, labels, and grids to the plots for clarity and readability.

Code:
clc; clear; close all;

% Parameters
fs = 1000; % Sampling frequency
T = 2; % Signal duration
t = -T:1/fs:T; % Time vector
N = length(t); % Number of samples
f = (-N/2:N/2-1) * (fs/N); % Frequency axis

% Time-Domain Signals
impulse = (t == 0); % Impulse function
step = (t >= 0); % Step function
sine_wave = sin(2 * pi * 10 * t); % Sine wave with frequency 10 Hz
cosine_wave = cos(2 * pi * 10 * t); % Cosine wave with frequency 10 Hz
square_wave = square(2 * pi * 10 * t); % Square wave with frequency 10 Hz
saw_wave = sawtooth(2 * pi * 10 * t); % Sawtooth wave with frequency 10 Hz

% Fourier Transforms
impulse_FT = fftshift(fft(impulse, N));
step_FT = fftshift(fft(step, N));
29

sine_FT = fftshift(fft(sine_wave, N));


cosine_FT = fftshift(fft(cosine_wave, N));
square_FT = fftshift(fft(square_wave, N));
saw_FT = fftshift(fft(saw_wave, N));

% Plot Results
figure;

% Impulse Signal
subplot(6,2,1);
stem(t, impulse, 'r', 'MarkerFaceColor', 'r');
title('Impulse Signal (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,2);
plot(f, abs(impulse_FT)/N, 'r', 'LineWidth', 1.5);
title('Fourier Transform of Impulse Signal');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Step Signal
subplot(6,2,3);
plot(t, step, 'b', 'LineWidth', 1.5);
title('Step Signal (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,4);
plot(f, abs(step_FT)/N, 'b', 'LineWidth', 1.5);
title('Fourier Transform of Step Signal');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Sine Wave
subplot(6,2,5);
plot(t, sine_wave, 'g', 'LineWidth', 1.5);
title('Sine Wave (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,6);
plot(f, abs(sine_FT)/N, 'g', 'LineWidth', 1.5);
title('Fourier Transform of Sine Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Cosine Wave
subplot(6,2,7);
plot(t, cosine_wave, 'm', 'LineWidth', 1.5);
title('Cosine Wave (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,8);
plot(f, abs(cosine_FT)/N, 'm', 'LineWidth', 1.5);
title('Fourier Transform of Cosine Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Square Wave
subplot(6,2,9);
plot(t, square_wave, 'c', 'LineWidth', 1.5);
title('Square Wave (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');
30

subplot(6,2,10);
plot(f, abs(square_FT)/N, 'c', 'LineWidth', 1.5);
title('Fourier Transform of Square Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Sawtooth Wave
subplot(6,2,11);
plot(t, saw_wave, 'k', 'LineWidth', 1.5);
title('Sawtooth Wave (Time Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,12);
plot(f, abs(saw_FT)/N, 'k', 'LineWidth', 1.5);
title('Fourier Transform of Sawtooth Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Displaying roll number


sgtitle('FA22-IET-001'); % Corrected supertitle

OUTPUT:
31

LAB 16:Time-Frequency Analysis of Multiple Signals:


Objective:
The objective of this code is to generate and visualize various time-domain signals (pulse
train, square wave, triangular wave, sawtooth wave, sine wave, and cosine wave) with
multiple frequencies and their corresponding frequency-domain representations using the
Fast Fourier Transform (FFT) algorithm.

Procedure:
• Define the sampling frequency (fs), signal duration (T), and time vector (t).
• Calculate the number of samples (N) and frequency axis (f).
• Define three frequencies (f1, f2, and f3) for the signals.
• Generate the pulse train, square wave, triangular wave, sawtooth wave, sine wave,
and cosine wave signals using their respective mathematical formulas and the defined
frequencies.
• Apply the FFT algorithm to each time-domain signal to obtain their frequency-
domain representations.
• Use the fftshift function to shift the FFT output to center the zero-frequency
component.
• Create a figure with multiple subplots to display the time-domain signals and their
corresponding frequency-domain representations.
• Use the plot function to visualize the signals in the time and frequency domains,
respectively.
• Add titles, labels, and grids to the plots for clarity and readability.
Code:
clc; clear; close all;

% Define Parameters
fs = 5000; % Sampling Frequency
T = 2; % Duration
t = -T:1/fs:T; % Time Vector
N = length(t); % Number of Samples
f = (-N/2:N/2-1) * (fs/N); % Frequency Axis

% Define Multiple Frequencies


f1 = 5; % Frequency 1 (Hz)
f2 = 15; % Frequency 2 (Hz)
f3 = 30; % Frequency 3 (Hz)

% Generate Time-Domain Signals


pulse_train = square(2 * pi * f1 * t) + square(2 * pi * f2 * t); % Pulse Train
square_wave = square(2 * pi * f1 * t) + square(2 * pi * f3 * t); % Square Wave
tri_wave = sawtooth(2 * pi * f1 * t, 0.5) + sawtooth(2 * pi * f2 * t, 0.5); % Triangular
Wave
saw_wave = sawtooth(2 * pi * f1 * t) + sawtooth(2 * pi * f3 * t); % Sawtooth Wave
sine_wave = sin(2 * pi * f1 * t) + sin(2 * pi * f2 * t) + sin(2 * pi * f3 * t); % Sine Wave
cosine_wave = cos(2 * pi * f1 * t) + cos(2 * pi * f2 * t) + cos(2 * pi * f3 * t); % Cosine
Wave

% Compute Fourier Transforms


32

Pulse_FT = fftshift(fft(pulse_train, N));


Square_FT = fftshift(fft(square_wave, N));
Tri_FT = fftshift(fft(tri_wave, N));
Saw_FT = fftshift(fft(saw_wave, N));
Sine_FT = fftshift(fft(sine_wave, N));
Cosine_FT = fftshift(fft(cosine_wave, N));

% Plot Results
figure;

% Pulse Train
subplot(6,2,1);
plot(t, pulse_train, 'r', 'LineWidth', 1.5);
title('Pulse Train (Time-Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,2);
plot(f, abs(Pulse_FT)/N, 'r', 'LineWidth', 1.5);
title('Fourier Transform of Pulse Train');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Square Wave
subplot(6,2,3);
plot(t, square_wave, 'b', 'LineWidth', 1.5);
title('Square Wave (Time-Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,4);
plot(f, abs(Square_FT)/N, 'b', 'LineWidth', 1.5);
title('Fourier Transform of Square Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Triangular Wave
subplot(6,2,5);
plot(t, tri_wave, 'g', 'LineWidth', 1.5);
title('Triangular Wave (Time-Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,6);
plot(f, abs(Tri_FT)/N, 'g', 'LineWidth', 1.5);
title('Fourier Transform of Triangular Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Sawtooth Wave
subplot(6,2,7);
plot(t, saw_wave, 'm', 'LineWidth', 1.5);
title('Sawtooth Wave (Time-Domain)');
33

xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,8);
plot(f, abs(Saw_FT)/N, 'm', 'LineWidth', 1.5);
title('Fourier Transform of Sawtooth Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Sine Wave
subplot(6,2,9);
plot(t, sine_wave, 'k', 'LineWidth', 1.5);
title('Sine Wave (Time-Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,10);
plot(f, abs(Sine_FT)/N, 'k', 'LineWidth', 1.5);
title('Fourier Transform of Sine Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

% Cosine Wave
subplot(6,2,11);
plot(t, cosine_wave, 'c', 'LineWidth', 1.5);
title('Cosine Wave (Time-Domain)');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(6,2,12);
plot(f, abs(Cosine_FT)/N, 'c', 'LineWidth', 1.5);
title('Fourier Transform of Cosine Wave');
xlabel('Frequency (Hz)'); ylabel('|X(f)|');
grid on;

OUTPUT:
34

LAB 17: Time-Frequency Analysis of Common Waveforms:


Objective
The objective of this code is to generate and visualize various common waveforms
(pulse train, square wave, triangular wave, sawtooth wave, sine wave, and cosine wave)
in the time domain and their corresponding frequency-domain representations using the
Fast Fourier Transform (FFT) algorithm.

Procedures:
a. Define the fundamental period (T), sampling frequency (fs), and time vector
(t).
b. Calculate the number of samples (N) and frequency axis (f).
c. Generate the pulse train, square wave, triangular wave, sawtooth wave, sine
wave, and cosine wave signals using their respective mathematical formulas.
d. Apply the FFT algorithm to each time-domain signal to obtain their
frequency-domain representations.
e. Use the fftshift function to shift the FFT output to center the zero-frequency
component.
f. Create a figure with multiple subplots to display the time-domain signals and
their corresponding frequency-domain representations.
g. Use the plot function to visualize the signals in the time and frequency
domains, respectively.
h. Add titles, labels, and grids to the plots for clarity and readability.
Code:

% Clear the workspace, command window, and close all figures


clc;
clear;
close all;

% Define parameters
T = 2; % Fundamental period (seconds)
fs = 1000; % Sampling frequency (Hz)
t = -T:1/fs:T; % Time vector
N = length(t); % Number of samples
f = (-N/2:N/2-1) * (fs/N); % Frequency axis

% Generate time-domain signals


pulse_train = square(2 * pi * (1/T) * t, 50); % Pulse train (50% duty cycle)
square_wave = square(2 * pi * (1/T) * t); % Square wave
tri_wave = sawtooth(2 * pi * (1/T) * t, 0.5); % Triangular wave
saw_wave = sawtooth(2 * pi * (1/T) * t); % Sawtooth wave
sine_wave = sin(2 * pi * (1/T) * t); % Sine wave
cosine_wave = cos(2 * pi * (1/T) * t); % Cosine wave

% Compute Fourier Transforms


Pulse_FT = fftshift(fft(pulse_train, N));
Square_FT = fftshift(fft(square_wave, N));
35

Tri_FT = fftshift(fft(tri_wave, N));


Saw_FT = fftshift(fft(saw_wave, N));
Sine_FT = fftshift(fft(sine_wave, N));
Cosine_FT = fftshift(fft(cosine_wave, N));

% Plot results
figure;

% Pulse Train
subplot(6, 2, 1);
plot(t, pulse_train, 'r', 'LineWidth', 1.5);
title('Pulse Train (Time-Domain)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(6, 2, 2);
plot(f, abs(Pulse_FT)/N, 'r', 'LineWidth', 1.5);
title('Fourier Transform of Pulse Train');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Square Wave
subplot(6, 2, 3);
plot(t, square_wave, 'b', 'LineWidth', 1.5);
title('Square Wave (Time-Domain)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(6, 2, 4);
plot(f, abs(Square_FT)/N, 'b', 'LineWidth', 1.5);
title('Fourier Transform of Square Wave');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Triangular Wave
subplot(6, 2, 5);
plot(t, tri_wave, 'g', 'LineWidth', 1.5);
title('Triangular Wave (Time-Domain)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(6, 2, 6);
plot(f, abs(Tri_FT)/N, 'g', 'LineWidth', 1.5);
title('Fourier Transform of Triangular Wave');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Sawtooth Wave
subplot(6, 2, 7);
plot(t, saw_wave, 'm', 'LineWidth', 1.5);
title('Sawtooth Wave (Time-Domain)');
xlabel('Time (s)');
36

ylabel('Amplitude');

subplot(6, 2, 8);
plot(f, abs(Saw_FT)/N, 'm', 'LineWidth', 1.5);
title('Fourier Transform of Sawtooth Wave');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Sine Wave
subplot(6, 2, 9);
plot(t, sine_wave, 'c', 'LineWidth', 1.5);
title('Sine Wave (Time-Domain)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(6, 2, 10);
plot(f, abs(Sine_FT)/N, 'c', 'LineWidth', 1.5);
title('Fourier Transform of Sine Wave');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Cosine Wave
subplot(6, 2, 11);
plot(t, cosine_wave, 'k', 'LineWidth', 1.5);
title('Cosine Wave (Time-Domain)');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(6, 2, 12);
plot(f, abs(Cosine_FT)/N, 'k', 'LineWidth', 1.5);
title('Fourier Transform of Cosine Wave');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;

% Adjust layout to prevent overlap


set(gcf, 'Position', get(0, 'ScreenSize'));
37

OUTPUT:
38

LAB 18: Rectangular Function and its Fourier Transform (Sinc Function):
Objective
The objective of this code is to demonstrate the relationship between a rectangular
function in the time domain and its Fourier transform, which is a sinc function, in the
frequency domain.
Procedure:
1. Define the time range (t) from -1 to 1 with a step size of 0.001.
2. Generate a rectangular function (rect) with a width of 1, centered at t=0.
3. Define the frequency range (f) from -10 to 10 with a step size of 0.01.
4. Compute the Fourier transform (X_f) of the rectangular function, which is a
sinc function.
5. Plot the rectangular function in the time domain.
6. Plot the Fourier transform (sinc function) in the frequency domain.
Code:
% Clear workspace and close all figures
clc; clear; close all;

% Define parameters
t = -2:0.001:2; % Extended time range
rect = double(abs(t) <= 0.75); % Rectangular pulse with a wider width

% Define frequency domain parameters


f = -20:0.05:20; % Extended frequency range
X_f = sinc(f); % Fourier transform approximation of rect(t)

% Plot the rectangular function


figure;
subplot(2,1,1);
plot(t, rect, 'LineWidth', 2);
title('Rectangular Function in Time Domain');
xlabel('Time (s)');
ylabel('rect(t)');
grid on;

% Plot the Fourier transform (Sinc function)


subplot(2,1,2);
plot(f, X_f, 'LineWidth', 2);
title('Fourier Transform of Rectangular Function (Sinc)');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
39

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy