Signal and System
Signal and System
• Session: 2022-2026
• Semester: 5th
MIT-MUST MIRPUR
2
Lab.No Experiment
19.
3
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:
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
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:
Code:
import numpy as np
import matplotlib.pyplot as plt
plt.show()
6
7
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
# 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
OUTPUT:
9
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:
Code:
t = -7:1:7;
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:
Code:
Output:
12
Objective:
To generate and visualize a discrete-time ramp signal for understanding linear signal behavior
in discrete systems.
Procedure:
Code:
Output:
14
Objective:
To simulate the addition of two signals for understanding signal superposition principles.
Procedure:
Code:
% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)
% Display legend
legend('Signal Addition');
Output:
16
Objective:
To simulate signal subtraction for analyzing differences between two signals.
Procedure:
Code:
% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)
% Display legend
legend('Signal Subtraction');
Objective:
To simulate multiplication of two signals for amplitude modulation effects.
Procedure:
Code:
% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)
% Display legend
legend('Signal Multiplication');
Output:
20
Objective:
To simulate the division of two signals for exploring ratio behavior in signal analysis.
Procedure:
Code:
% Generate signals
signal1 = sin(0.1 * pi * n); % First signal (sine wave)
signal2 = cos(0.1 * pi * n); % Second signal (cosine wave)
% Display legend
legend('Signal Division');
Objective:
To create and display matrices for basic linear algebra operations.
Procedure:
Code:
% Display matrix A
disp('Matrix A:');
disp(matrix_a);
% Display matrix B
disp('Matrix B:');
disp(matrix_b);
Output
23
Objective:
To perform matrix operations and demonstrate linear transformations.
Procedure:
Code:
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);
% Amplitude Modulation
y = x .* cos(2 * pi * Fc * t);
figure(3);
plot(t, y, 'g', 'LineWidth', 1.5);
title('Amplitude Modulation');
xlabel('Time (sec)');
ylabel('Amplitude');
legend('AM Signal');
grid on;
Output:
26
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:
Output:
28
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
% 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;
OUTPUT:
31
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
% 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
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
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:
% 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
% 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;
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
OUTPUT: