0% found this document useful (0 votes)
22 views27 pages

Signal N Systems Lab

The document is a lab manual for Signals and Systems, detailing various experiments using MATLAB (R2023a) to explore concepts such as matrix operations, signal transformations, convolution, Fourier series, and inverse Fourier transforms. Each experiment includes objectives, MATLAB code, and conclusions emphasizing the importance of these concepts in engineering applications. The manual serves as a practical guide for students in the Department of Electronics and Communication Engineering at Malaviya National Institute of Technology Jaipur.

Uploaded by

Siddhi Garg
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)
22 views27 pages

Signal N Systems Lab

The document is a lab manual for Signals and Systems, detailing various experiments using MATLAB (R2023a) to explore concepts such as matrix operations, signal transformations, convolution, Fourier series, and inverse Fourier transforms. Each experiment includes objectives, MATLAB code, and conclusions emphasizing the importance of these concepts in engineering applications. The manual serves as a practical guide for students in the Department of Electronics and Communication Engineering at Malaviya National Institute of Technology Jaipur.

Uploaded by

Siddhi Garg
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/ 27

Signals and Systems Lab

(22ECP106, B Tech II Semester)

Lab Manual

Department of Electronics and Communication Engineering


Malaviya National Institute of Technology Jaipur
Jaipur-India, 302017
Experiment-1
Aim: - Introduction to MATLAB working environment and language fundamentals. To create
matrices and do basic mathematical operations.

Software: - MATLAB (R2023a)

Theory: - MATLAB (an abbreviation of "matrix laboratory") is a proprietary multi-paradigm


programming language and numeric computing environment developed by MathWorks. MATLAB
allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation
of user interfaces, and interfacing with programs written in other languages.

Working environment: -

COMMANDS: -

Commands for Managing a Session

Command Purpose
Clc Clears command window.
clear Removes variables from memory.
exist Checks for existence of file or variable.
global Declares variables to be global.
help Searches for a help topic.
lookfor Searches help entries for a keyword.
quit Stops MATLAB.
who Lists current variables.
whos Lists current variables (long display).

System and file commands

Cd change current directory


Date Display current date
path Display search path
Save Save workspace variable in file

Input and output commands

Command Purpose
disp Displays contents of an array or string.
fscanf Read formatted data from a file.
; Supress screen printing
fprintf Performs formatted writes to screen or file.
input Displays prompts and waits for input.

Array commands
Plotting commands
Command Purpose
axis Sets axis limits.
fplot Intelligent plotting of functions.
grid Displays gridlines.
plot Generates xy plot.
print Prints plot or saves plot to a file.
title Puts text at top of plot.
Xla`bel Adds text label to x-axis.
ylabel Adds text label to y-axis.
axes Creates axes objects.
close Closes the current plot.
close all Closes all plots.
figure Opens a new figure window.
gtext Enables label placement by mouse.
hold Freezes current plot.
legend Legend placement by mouse.
refresh Redraws current figure window.
Set Specifies properties of objects such as axes.
subplot Creates plots in subwindows.
text Places string in figure.
Bar Creates bar chart.
loglog Creates log-log plot.
polar Creates polar plot.
semilogx Creates semilog plot. (logarithmic abscissa).
semilogy Creates semilog plot. (logarithmic ordinate).
Applications: -
 Statistics and machine learning (ML)
This toolbox in MATLAB can be very handy for the programmers. Statistical methods
such as descriptive or inferential can be easily implemented.
 Curve fitting
The curve fitting toolbox helps to analyse the pattern of occurrence of data. After a
particular trend which can be a curve or surface is obtained, its future trends can be
predicted.
 Control systems
Systems nature can be obtained. Factors such as closed-loop, open-loop, its
controllability and observability, Bode plot, Nyquist plot, etc can be obtained.
 Signal Processing
Signals and systems and digital signal processing are taught in various engineering
streams. But MATLAB provides the opportunity for proper visualization of this.
 Deep learning
Its a subclass of machine learning which can be used for speech recognition, financial
fraud detection, medical image analysis.
 Image processing
The most common application that we observe almost every day are bar code scanners,
selfie (face beauty, blurring the background, face detection), image enhancement, etc.

Conclusion: -

MATLAB helps you take your ideas beyond the desktop. You can run your analyses on larger data
sets, and scale up to clusters and clouds. MATLAB code can be integrated with other languages,
enabling you to deploy algorithms and applications within web, enterprise, and production systems.
Experiment-2
Aim: - To study the shifting, time reversal and scaling of a given continous time domain signal.

Software: - MATLAB (R2023a)

MATLAB Code:
clc;
close all;

% the limits of the time for the signal are defined here
delta_t = 0.01;
strtime = -5;
endtime = 5;
t = strtime:delta_t:endtime;
x = zeros(size(t));

% the definition of the mathematical function is defined here


x(t >= -2) = t(t >= -2) + 2;
x(t >= -1) = 1.0;
x(t >= 1) = t(t >= 1);
x(t > 2) = 0.0;

% The plot of original signal with the limits of axes


subplot(5,1,1);
plot(t,x);
axis([-6 6 -3 3]);
grid on
title('original signal')
xlabel('t');
ylabel('x(t)');

% The plot of shifted signal with the limits of axes


subplot(5,1,2);
tnew = t + 3;
plot(tnew,x)
axis([-6 6 -2 2]);
grid on
title('shifted signal')
xlabel('t')
ylabel('x(t-3)')

% The plot of scaled signal with the limits of axes


subplot(5,1,3);
tnew = t/2;
plot(tnew,x)
axis([-6 6 -2 2]);
grid on
title('scaled signal')
xlabel('t')
ylabel('x(2t)')

% The plot of time reversed signal with the limits of axes


subplot(5,1,4);
tnew = -t;
plot(tnew,x)
axis([-6 6 -2 2]);
grid on
title('time reversed signal')
xlabel('t')
ylabel('x(-t)')

% The plot of three transformation of the signal with the limits of axes
subplot(5,1,5);
tnew = -t/2 - 3/2 ;
plot(tnew,x)
axis([-6 6 -2 2]);
grid on
title('all combined')
xlabel('t')
ylabel('x(-2t - 3)')

Output:

Conclusion:
These operations are crucial for analyzing and manipulating signals in various fields such as
communications, control systems, and signal processing. Understanding how each operation affects
the signal can help in designing and interpreting signal transformations effectively.
Experiment-3
Aim: - To compute convolution both in continous and discrete domain.

Software: - MATLAB (R2023a)

MATLAB Code:

clc
clear all;
close all;

%%%%%%%%%%%continous signal code%%%%%%%%%%%%%%%%%%%%%%%%

% definition of the time intervals


delta_t = 0.01;
strtime = -4;
endtime = 4;
t = strtime:delta_t:endtime;

% definition of the input signal


x(t >= -2) = t(t >= -2);
x(t > 2) = 0.0;

% plot of the input signal


figure;
subplot(3,1,1);
plot(t,x)
axis([-6 6 min(x) max(x)]);
grid on
title('input signal x(t)')
xlabel('t')
ylabel('x(t)')

% definition of unit impules response


h(t >= -1) = 2.0;
h(t > 1) = 0.0;

% plot of the unit impulse response


subplot(3,1,2);
plot(t,h)
axis([-6 6 min(h) max(h)]);
grid on
title('impulse response h(t)')
xlabel('t')
ylabel('h(t)')

% computation of output signal based on convolution


y = conv(x,h) * delta_t;
ly = length(x) + length(h) - 1;
tnew = (0: ly - 1) * delta_t + 2*strtime;

% plot of the output signal


subplot(3,1,3);
plot(tnew,y)
axis([-6 6 min(y) max(y)]);
grid on
title('output signal y(t)')
xlabel('t')
ylabel('y(t)')

%%%%%%%%%%%discrete signal code%%%%%%%%%%%%%%%%%%%%%%%%


clear all

% definition of the input signal


n_x = -3:1:4;
x = [4 3 2 1 1 2 3 4];

% plot of the input signal


figure;
subplot(3,1,1);
stem(n_x,x)
axis([-7 7 0 max(x)]);
grid on
title('input signal x[n]')
xlabel('n')
ylabel('x[n]')

% definition of unit impules response


n_h = -1:1:2;
h = [4 3 2 1];

% plot of the unit impulse response


subplot(3,1,2);
stem(n_h,h)
axis([-7 7 0 max(h)]);
grid on
title('impulse response h[n]')
xlabel('n')
ylabel('h[n]')

% computation of output signal based on convolution


n_y = n_x(1)+n_h(1):1: n_x(end)+n_h(end);
y = conv(x,h);

% plot of the output signal


subplot(3,1,3);
stem(n_y,y)
axis([-7 7 0 max(y)]);
grid on
title('output signal y[n]')
xlabel('n')
ylabel('y[n]')
Output:

Conclusion: Convolution, both in continuous and discrete domains, is essential for determining
the output of linear time-invariant systems given an input signal and the system's impulse response.
Mastering this operation is crucial for effective signal analysis and system design in various
engineering applications.
Experiment-4
Aim: - To generate a periodic square wave from it’s Fourier series expansion

Software: - MATLAB (R2023a)

MATLAB Code:

clc;
clear all;
close all;

%scale factor should be varied and observed


T1 = 1; % time duration of the pulse being 1
scalefactor = 4;
T = scalefactor * T1; % Time period of the square wave form
omega = 2*pi/T;

% time duration for which signal is being generated


NumberOfSampesPerT = 100;
t = -1.5*T:T/NumberOfSampesPerT:1.5*T;

% Number of terms to be kept in Fourier series expansion


NumberOfTerms = 100;
k = -NumberOfTerms:1:NumberOfTerms;

%Fourier series coefficients


a = sin(k*omega*T1)./(k*pi);
%zeroth coefficient being set explicitly
a(k==0) = 2*T1/T;

% Plot of the spectral content


figure;
stem(k,a);
axis([min(k) max(k) 1.1*min(a) 1.1*max(a)]);
grid on
title('Fourier Series Coefficients')
xlabel('k')
ylabel('a(k)')

% Computation of the generated square wave form


x = zeros(size(t));
for ind = 1:length(k)
x = x + a(ind)*exp(1i*k(ind)*omega*t);
end
x = real(x);

% Plot of the generated square wave form


figure;
plot(t,x)
axis([min(t) max(t) -0.5 1.5]);
grid on
title('Square Waveform')
xlabel('t')
ylabel('x(t)')
% time duration for which signal is being generated
% Number of samples per period changed
NumberOfSampesPerT = 200;
t = -1.5*T:T/NumberOfSampesPerT:1.5*T;

% computation of the waveform


x = zeros(size(t));
for ind = 1:length(k)
x = x + a(ind)*exp(1i*k(ind)*omega*t);
end
x = real(x);

% Observing Gibb's phenomenon in the generated square wave form


figure;
plot(t,x)
axis([-T/2 T/2 -0.5 1.5]);
grid on
title('Gibbs phenomenon in the Square Waveform')
xlabel('t')
ylabel('x(t)')

Output:
Conclusion: Generating a periodic square wave from its Fourier series expansion demonstrates
the power of Fourier analysis in representing complex periodic signals using a sum of sinusoidal
components. By computing the Fourier series, we can approximate the square wave with increasing
accuracy, highlighting the significance of harmonic components in signal synthesis and analysis in
various engineering and scientific applications.
Experiment-5

Aim: - To generate a periodic Triangular waveform from it’s Fourier series expansion

Software: - MATLAB (R2023a)

MATLAB Code:

clc
clear;

%scale factor should be varied and observed


T1 = 1; % time duration of the pulse being 1
scalefactor = 4;
T = scalefactor * T1; % Time period of the square wave form
omega = 2*pi/T;

% time duration for which signal is being generated


NumberOfSampesPerT = 100;
t = -1.5*T:T/NumberOfSampesPerT:1.5*T;

% Number of terms to be kept in Fourier series expansion


NumberOfTerms = 100;
k = -NumberOfTerms:1:NumberOfTerms;

%Fourier series coefficients


a = sin(k*omega*T1)./(1i*k.^2*omega*pi);
%zeroth coefficient being set explicitly
a(k==0) = 0; %T1/T;

% Plot of the spectral content


figure;
subplot(2,1,1);
stem(k,abs(a));
axis([min(k) max(k) 1.1*min(abs(a)) 1.1*max(abs(a))]);
grid on
title('Fourier Series Coefficients (Magnitude)')
xlabel('k')
ylabel('a(k)')

subplot(2,1,2);
stem(k,angle(a));
axis([min(k) max(k) 1.1*min(angle(a)) 1.1*max(angle(a))]);
grid on
title('Fourier Series Coefficients (Phase)')
xlabel('k')
ylabel('a(k)')

% Computation of the generated Triangular wave form


x = zeros(size(t));
for ind = 1:length(k)
x = x + a(ind)*exp(1i*k(ind)*omega*t);
end
x = real(x);

% Plot of the generated Triangular wave form


figure;
plot(t,x)
axis([min(t) max(t) 1.5*min(x) 1.5*max(x)]);
grid on
title('Triangular Waveform')
xlabel('t')
ylabel('x(t)')

Output:

Conclusion: Successfully generated a periodic triangular waveform by utilizing its Fourier series
expansion, enabling us to represent the waveform as a sum of sinusoidal functions, thus
demonstrating the capability of Fourier analysis in waveform synthesis.
Experiment-6

Aim: - To compute the inverse Fourier Transform of a continuous signal defined in frequency
domain.

Software: - MATLAB (R2023a)

MATLAB Code:
%scale factor should be varied and observed
T1 = 1.0; % time duration of the pulse being 1

% time duration for which signal is being generated


NumberOfSampesPerT1 = 5;
t = -1.0*T1:T1/NumberOfSampesPerT1:1.0*T1;

% generating the rectangular pulse x(t)


x(t >= -T1) = 1.0;
x(t >= T1) = 0.0;

% parameters for numerical integration to compute Fourier Transform


dt = T1/NumberOfSampesPerT1;

%defintion of the range of values for the omega and X(omega)


omega = -4*pi: pi/20: 4*pi;
X_omega = zeros(size(omega));
for ind = 1:length(t)
X_omega = X_omega + x(ind)*exp(1i*omega*t(ind))*dt;
end

% This examples will have X(omega) as completely real but since there might
% be small values of imaginary part, we completely set them to zero
X_omega = real(X_omega);

% The original mathematical expression of the Fourier Transform


% of the rectangular pulse
X_omega_o = 2 * sin(omega*T1)./omega;
% explicitly setting the value of X(omega) for omega = 0 frequency
X_omega_o(omega==0) = 2*T1;

% Error between orginal and numerically computed Fourier transform


err = norm(X_omega_o - X_omega,2)/norm(X_omega,2);

% Plot of the spectral content


figure;
plot(omega,X_omega,'Linewidth',2);
hold on
plot(omega,X_omega_o,'r--','Linewidth',3);
axis([min(omega) max(omega) 1.1*min(X_omega_o) 1.1*max(X_omega_o)]);
grid on
legend('Original Expression','Numerically Computed')
title(horzcat('Fourier Transform with relative error=',num2str(err)))
xlabel('$\omega$','interpreter','latex')
ylabel('X($\omega$)','interpreter','latex')
% The x-axis is being changed in the plot to have tick points at different
% values of pi
set(gca,'xtick',[-4*pi:pi:4*pi])
set(gca,'xticklabels',{'4\pi','3\pi','2\pi','\pi','0','\pi','2\pi','3\pi','4\pi'})

Output:

Conclusion: After completing the experiment, we efficiently computed the inverse Fourier
Transform of the continuous signal defined in the frequency domain, effectively transforming it
back into the time domain representation, thereby demonstrating the versatility and power of
Fourier analysis in signal processing tasks.
Experiment-7

Aim: - To compute the Fourier Transform of a continuous non-periodic signal (rectangular pulse).

Software: - MATLAB (R2023a)

MATLAB Code:

%scale factor should be varied and observed


T1 = 10; % time duration of the pulse being 1

% time duration for which signal is being generated


NumberOfSampesPerT = 100;

% sinc function in frequency domain with the cycles to be considered

omega = -T1: T1/NumberOfSampesPerT: T1;


X_omega = 2 * sin(omega*T1)./omega;
X_omega(omega==0) = 2*T1;

% parameters for numerical integration to compute Fourier Transform


domega = T1/NumberOfSampesPerT;

%defintion of the range of values for the t and x(t)


t = -2*T1:T1/NumberOfSampesPerT:2*T1;
x = zeros(size(t));

%computing the inverse Fourier transform


for ind = 1:length(omega)
x = x + X_omega(ind)*exp(1i*omega(ind)*t)*domega / (2*pi);
end

% In this example, x(t) is a real function. However, there might


% be small values of imaginary part, we explicitly get rid of them here
x = real(x);

% Plot of the time domain signal14


figure;

subplot(1,2,1)
plot(omega,X_omega, 'k');
%axis([min(omega) max(omega) 1.1*min(X_omega) 1.1*max(X_omega)]);
grid on
title('Original Signal')
xlabel('\omega')
ylabel('x(\omega)')

% The x-axis is being changed in the plot to have tick points at different values of pi
%set(gca,'xtick',[-2*pi:pi:2*pi])
%set(gca,'xticklabels',{'2\pi','\pi','0','\pi','2\pi'})
subplot(1,2,2)
plot(t,x,'r');
%axis([min(t) max(t) 1.1*min(x) 1.1*max(x)]);
grid on
title('Inverse Fourier Transform')
xlabel('t')
ylabel('x(t)')

Output:

Conclusion: Upon completing the experiment, we accurately computed the Fourier Transform of
the continuous non-periodic signal, such as a rectangular pulse, revealing its frequency domain
representation and showcasing the fundamental principles of Fourier analysis in characterizing
signals with finite duration.
Experiment-8

Aim: - To compute the Discrete Time Fourier Transform of signal.

Software: - MATLAB (R2023a)

MATLAB Code:
clc
clear

%scale factor should be varied and observed


N1 = 5; % time duration of the pulse being 1

% %Signal 1
% %time duration for which signal is being generated
% n = -3.0*N1:1:3.0*N1;
% % generating the rectangular pulse x(t)
% x(n >= -N1) = 1.0;
% x(n > N1) = 0.0;

% Signal 2
% time duration for which signal is being generated
n = -3.0*N1:1:3.0*N1;
% generating the rectangular pulse x(t)
x(n >= -N1) = -1.0;
x(n >= 0) = 1.0;
x(n > N1) = 0.0;

% % Signal 3
% n = -3.0*N1:1:3.0*N1;
% x(n >= -N1) = n(n >= -N1);
% x(n > N1) = 0.0;

% Plot of the signal


figure;
subplot(3,1,1);
stem(n,x);
axis([min(n) max(n) 1.1*min(x) 1.1*max(x)]);
grid on
title('Discrete Time Signal')
xlabel('n')
ylabel('x[n]')

NumberofCycles = 5;
NumberOfSampesPerPi = 100;
omega = -NumberofCycles*pi : pi/NumberOfSampesPerPi : NumberofCycles*pi;

X_omega = zeros(size(omega));
for ind = 1:length(n)
X_omega = X_omega + x(ind)*exp(1i*omega*n(ind));
end

% Plot of the spectral content


subplot(3,1,2);
plot(omega,abs(X_omega));
axis([min(omega) max(omega) 1.1*min(abs(X_omega)) 1.1*max(abs(X_omega))]);
grid on
title('DTFT magnitude')
xlabel('$\omega$','interpreter','latex')
ylabel('X($\omega$)','interpreter','latex')
set(gca,'xtick',[-NumberofCycles*pi:pi:NumberofCycles*pi])
set(gca,'xticklabels',{'-5\pi','-4\pi','-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi','4\pi','5\pi'})

subplot(3,1,3);
plot(omega,angle(X_omega));
axis([min(omega) max(omega) -2*pi 2*pi]);
grid on
title('DTFT phase')
xlabel('$\omega$','interpreter','latex')
ylabel('X($\omega$)','interpreter','latex')
set(gca,'xtick',[-NumberofCycles*pi:pi:NumberofCycles*pi])
set(gca,'xticklabels',{'-5\pi','-4\pi','-3\pi','-2\pi','-\pi','0','\pi','2\pi','3\pi','4\pi','5\pi'})
set(gca,'ytick',[-2*pi:pi:2*pi])
set(gca,'yticklabels',{'-2\pi','-\pi','0','\pi','2\pi'})

Output:

Conclusion: Following the experiment's conclusion, we effectively computed the Discrete Time
Fourier Transform (DTFT) of the signal, providing insights into its frequency content and
emphasizing the significance of DTFT in analyzing discrete-time signals' spectral characteristics.
Experiment-9

Aim: - To perform symbolic computation in matlab

Software: - MATLAB (R2023a)

MATLAB Code:

syms z;
expr = -2*z/(1+z^2)^2;

%Find the indefinite integral of a mathematical expression.


F = int(expr);
disp(horzcat('The integration of',string(expr),'is'));
disp(string(F));

%Compute differentiation of a mathematical expression.


F = diff(expr);
disp(horzcat('The differentiation of',string(expr),'is'));
disp(string(F));

%Compute partial fraction decomposition of a mathematical expression.


num = z^2 + 1;
den = z^3 - 3*z + 2;
expr = num / den;
F = partfrac(expr);
disp(horzcat('The partial fraction of',string(expr),'is'));
disp(string(F));

% Compute poles and zeros of a transfer function.


P = poles(F);
Z = solve(num);
disp(horzcat('The poles of',string(F),'is'));
disp(string(P));
disp(horzcat('zeros of',string(F),'is'));
disp(string(Z));
Output:

"The integration of" "-(2*z)/(z^2 + 1)^2" "is" 1/(z^2 + 1)

"The differentiation of" "-(2*z)/(z^2 + 1)^2" "is" (8*z^2)/(z^2 + 1)^3 - 2/(z^2 + 1)^2

"The partial fraction of" "(z^2 + 1)/(z^3 - 3*z + 2)" "is" 4/(9*(z - 1)) + 2/(3*(z - 1)^2) +
5/(9*(z + 2))

"The poles of" "4/(9*(z - 1)) + 2/(3*(z - 1)^2) + 5/(9*…" "is" "-2" "1"

"zeros of" "4/(9*(z - 1)) + 2/(3*(z - 1)^2) + 5/(9*…" "is" "-1i" "1i"

Conclusion: Upon concluding the experiment, performing symbolic computation in MATLAB


offered a powerful method for manipulating mathematical expressions symbolically, enhancing
accuracy and efficiency in mathematical analysis and problem-solving tasks.
Experiment-10

Aim: - To perform Z-transform and Laplace transform using symbolic computation in matlab

Software: - MATLAB (R2023a)

MATLAB Code:

syms n z;
% Define the symbolic expression
x = (1/2)^n * cos(4*n);
% Calculate the Z-transform
X = ztrans(x);
% Display the symbolic expression and its Z-transform
disp('Symbolic Expression:');
disp(x);
disp('Z-transform:');
disp(X);
% Calculate the inverse Z-transform
x_inverse = iztrans(X);
% Display the regenerated symbolic expression
disp('Regenerated Symbolic Expression by Inverse Z-transform:');
disp(x_inverse);

syms t s;
% Define the symbolic expression
x = exp(-2*t)*sin(3*t);
% Calculate the Laplace transform
X = laplace(x);
% Display the symbolic expression and its Laplace transform
disp('Symbolic Expression:');
disp(x);
disp('Laplace Transform:');
disp(X);
% Calculate the inverse Laplace transform
x_inverse = ilaplace(X);
% Display the regenerated symbolic expression
disp('Regenerated Symbolic Expression by Inverse Laplace Transform:');
disp(x_inverse);

Output:

Symbolic Expression:
(1/2)^n*cos(4*n)

Z-transform:
(2*z*(2*z - cos(4)))/(4*z^2 - 4*cos(4)*z + 1)

Regenerated Symbolic Expression by Inverse Z-transform:


2/2^(n + 1)*cos(4*n)

&

Symbolic Expression:
sin(3*t)*exp(-2*t)

Laplace Transform:
3/((s + 2)^2 + 9)

Regenerated Symbolic Expression by Inverse Laplace Transform:


sin(3*t)*exp(-2*t)

Conclusion: Following the experiment's completion, utilizing symbolic computation in


MATLAB enabled seamless computation of Z-transforms and Laplace transforms, facilitating
thorough analysis of discrete-time and continuous-time signals and systems with enhanced
precision and efficiency.

You might also like