0% found this document useful (0 votes)
39 views

Final Lab Manual ECE_EEE Stream

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Final Lab Manual ECE_EEE Stream

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Department of Mathematics

Third semester MATLAB Lab Manual for a


Electrical & Electronics Engineering Stream

Course title and code:


Transforms and Statistics (23ECI301)
Academic Year: 2024 -2025

Name :

USN :

Section :

Department of Mathematics, SJB Institute of Technology 1


PROGRAM OUTCOMES

INSTITUTE VISION

To become a recognized technical education centre with global perspective.

INSTITUTE MISSION

To provide learning opportunities that fosters student’s ethical values, intelligence


development in science & technology and social responsibility so that they become
sensible and contributing members of the society.

DEPARTMENT VISION

To be the Word’s foremost technical schools fostering intellectual excellence.

DEPARTMENT MISSION

To develop technical challenging leaders and entrepreneurs for facilitating and


enhancing the global competitiveness of organization through excellence in
education, research and training.

Department of Mathematics, SJB Institute of Technology 2


PROGRAM OUTCOMES

Engineering graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data, and
synthesis of the information to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex engineering activities
with anunderstanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainabledevelopment.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or
leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give
and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change

Department of Mathematics, SJB Institute of Technology 3


General Instructions for the Laboratory

Do’s
 It is mandatory for all the students to attend all practical classes & complete the

experiments as per syllabus

 Students should strictly follow the lab timings, dress code with ID cards.

 Should maintain a neat observation book.

 Study the theory and logic before executing the program.

 Submit the complete lab records of executed programs and update the index book in

every lab session.

 Should prepare for viva questions regularly. Handle the computers systems carefully.

 Maintain discipline and silence in the lab.

Don’ts
 Should not take Bags and Mobile phones into the Laboratory.

 Do not wear footwear inside the Laboratory

 Systems & components should be handled carefully failing to which penalty will be

imposed.

 Do not switch off the system abruptly.

 Should not chew gum or eat in the lab.

Department of Mathematics, SJB Institute of Technology 4


COURSE OUTCOMES (With PO & PSO Mapping)

Semester 3rd Course tile& Transforms and


Course code
Statistics

(23ECI301)

Course Outcomes (COs) PO & PSO

CO1 Illustrate the fundamental concepts of transforms and PO1, PO2, PO3, PO5, PO12,

statistical techniques. PS01, PSO2, PSO3

CO2 Apply the knowledge of transform calculus, Fourier series PO1, PO2, PO3, PO5, PO12,

and statistical techniques to solve engineering problems. PS01, PSO2, PSO3

CO3 Analyze the solution of the problems using suitable PO1, PO2, PO3, PO5, PO12,

techniques of transform calculus, Fourier series and PS01, PSO2, PSO3

statistical methods.

CO4 Interpret the knowledge of transform calculus, Fourier PO1, PO2, PO3, PO5, PO12,

series and statistical methods in practical situations PS01, PSO2, PSO3

Correlation Matrix

CO/PO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 P09 PO10 PO11 PO12 PSO1 PSO2 PSO3

CO1 3 2 1 2 1 2 1 1

CO2 3 2 1 2 1 2 1 1

CO3 3 2 1 2 1 2 1 1

CO4 3 2 1 2 1 2 1 1

Note: Correlation levels: 1: Slight (Low) 2: Moderate (Medium) 3: Substantial (High), “-” à No

correlations

Department of Mathematics, SJB Institute of Technology 5


Transforms and Statistics

Choice Based Credit System (CBCS) and Outcome Based Education (OBE)

Laboratory Code 23ECI301 CIE Marks 50

Teaching Hours/Week (L:T:P: S) 0:0:2:0 SEE Marks 50

Course Learning Objectives:


This course will enable students to:
1. Have an insight into Laplace transforms, Fourier series, Fourier transforms, Z-transforms.
2. Develop knowledge of solving problems in engineering application using transforms.
3. Develop knowledge of Statistical methods and curve fitting arising in engineering.

Lab No. Programs

1 Demonstrating the use of basic commands in MATLAB

2 Write a program to find the Laplace Transform, Inverse Laplace


Transform and unit step function.

3 Write a program to obtain the Fourier series and its properties.

4 Implementation of Fourier transform its properties.

5 Implementation of Z transform and its properties.

6 Write a program to find the correlation between two variables and the plot the
Regression line.

7 Write a program to find the Fitting a straight line by the method of least square
using MATLAB.

8 MATLAB program to solve application problem using Laplace transform.

9 MATLAB program to solve application problem using Fourier transform.

10 MATLAB program to solve application problem using Z transform.

Department of Mathematics, SJB Institute of Technology 6


RUBRICS

Evaluation of Laboratory Activities

I. Evaluation Procedure for Program / Experiment:

Sl. No. Criteria Marks Allocation

1 Understanding & Write-up(W) 15

2 Conduction (C) 15

3 Results (R) 10

4 Viva (V) 10

Total Marks for Lab Conduction & Evaluation 50

II. Evaluation Procedure for Lab Internals:

. Sl. No. Criteria Marks Allocation

1 Write-up (W) 15

2 Conduction (C) 15

3 Results(R) 10

4 Viva (V) 10

Total Marks for Lab Internals 50

Total Marks (Continuous Internal Evaluation) : 50 Marks

Department of Mathematics, SJB Institute of Technology 7


CONTENTS

EXP. PAGE
NAME OF THE EXPERIMENT CO RBT
NO NO

CO1 L1, L2 15-17


Demonstrating the use of basic commands in MATLAB
1
CO1,
Write a program to find the Laplace Transform, Inverse CO2, CO3 L1, L2 18-23
2
Laplace Transform and unit step function.

Write a program to obtain the Fourier series and its CO1, L1, L2 24-29
3 properties. CO2, CO3
4 Implementation of Fourier transform its properties. CO1, L1, L2 30-35
CO2, CO3

5 Implementation of Z transform and its properties. L1, L2 31-33


CO1,
CO2, CO3
Write a program to find the correlation between two variables L4, L5 36-38
and the plot the Regression line. CO1,
6 CO2, CO3
Write a program to find the Fitting a straight line by the L4, L5 39-41
method of least square using MATLAB. CO1,
7 CO2, CO3
MATLAB program to solve application problem using L3, L4, 42-44
Laplace transform. CO4 L6
8
9 MATLAB program to solve application problem using L3, L4, 45-47
CO4
Fourier transform. L6

MATLAB program to solve application problem using L3, L4, 48-50


CO4
10 Z transform. L6

Department of Mathematics, SJB Institute of Technology 8


PREFACE

MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for

technical computing. It was developed by Cleve Molar of the company MathWorks.Inc in

the year 1984.It is written in C, C++, Java.

Engineers and scientist’s world wise use MATLAB to solve complicated real-world

problems. Analyze data and visualize ideas lead to a better understanding of complex

systems. This course walks you through is an excellent tool for the basics of using

MATLAB including performing calculation with commands, importing data from external

sources and visualizing data through plotting functions.

It is an excellent tool for

 Linear algebra computations


 Data analysis
 Signal processing
 Optimization
 Numerical solution of ordinary differential equations (ODEs) and many other types
of scientific computations.

Department of Mathematics, SJB Institute of Technology 9


Introduction to MATLAB programming language
One can compute the solution for a given problem by using

 Built in functions
 User-written functions

Getting started with MATLAB

 Double click the MATLAB shortcut on window desktop.


 Do not open MaTLab multiple times.
 MATLAB automatically loads all the program files provided by MATH Works for MATLAB and
other MATH Work products.

This desktop majorly consists of the following:


i. Command window
ii. Command history window
iii. Workspace window
iv. Variable editor window
v. Current folder/directory

MatLab window majorly consists


 Command window
 One-line commands can be executed.
 Small calculations can be done here.
 Each line will be executed immediately after pressing “enter key”.
 Command history window
 It is a sub window of Command window.
 Previously executed lines can be taken from here.
 By pressing “up arrow” we can get this window.
 Workspace window
 Variables, we used in a program will get listed with its information.
 Current folder/directory
 To see the location of saved and opened m-files.

Department of Mathematics, SJB Institute of Technology 10


Note:
1. >> Prompt indicates that MATLAB is ready to accept input from user, it is also known as the
command line.
2. clc command clears the command window only. Variables remain stored in memory space.
3. clear / clear all command clears all the variables from the command window and command history
window.
4. There are two types of m-files offered by MATLAB.
 Script m-file (To write a program)
 Function m-file (To build own functions)

Department of Mathematics, SJB Institute of Technology 11


M-File (Script)
In command prompt, where we write the statement (MATLAB code) on the command line prompt in
command window and enter to execute it.press
 It is a step-by-step approach to execute a particular program.
 This is fine as long as, number of statements in a program is less.

Incase if the program requires very large number of commands or it needs to be executed repeatedly
or if one wants to modify some of the command after running the whole program or if one wants to
execute the whole program again in such cases MATLAB offers a provision where complete MATLAB
code is written in sequence in a file called m-file (MATLAB file). The extension of this files are .m.

Note: on saving M-Files (Script)


➢ File name should not start with number (Try to avoid lengthy file names).
➢ Inbuild functions should not be used as a file names.
➢ File name should not contain space. Instead, underscore ( _ ) can be used.

Department of Mathematics, SJB Institute of Technology 12


Operators and special characters in MATLAB
+ Plus; addition operator

- Minus; subtraction operator

* Scalar and matrix multiplication operator

.* Array multiplication operator

^ Scalar and matrix exponentiation operator

^. Array exponentiation operator

\ Left-division operator

/ Right-division operator

.\ Array left-division operator

./ Array right-division operator

: Colon; generates regularly spaced elements and represents an entire row or


column

() Parentheses; encloses function arguments and array indices; overrides


precedence

[] Brackets; enclosures array elements

, Comma; separates statements and elements in a row.

; Semicolon; separates columns and suppresses display

= Assignment (replacement) operator

Department of Mathematics, SJB Institute of Technology 13


Commands for Managing a Session

clc Clears Command window


clear Removes variables from memory
exist Checks for existence of file or variable
help Searches for a help topic
quit Stops MATLAB

Mathematical Functions:

Exponential and Logarithmic Functions


exp(x) Exponential; ex
log (x) Natural logarithm; ln(x).
Log10(x) Common (base 10) logarithm;
log(x)=log10(x)
sqrt(x) Square root;

Department of Mathematics, SJB Institute of Technology 14


Experiment No-1: Demonstrating the use of Arithmetic Operations in MATLAB
Problem 1: Create two vectors running from one to six and from six to one and then
demonstrate the use of the dot arithmetical operations: s=1:6; t = 6:-1:1; find s+t, s-t, s.*t,
s./t and s.ˆ2.
1. s+t
s = 1:6;
t = 6:-1:1;
u = s+t
OUTPUT: 7 7 7 7 7 7
2. s-t
s = 1:6;
t = 6:-1:1;
u = s-t
OUTPUT: -5 -3 -1 1 3 5

3. s.*t
s = 1:6;
t = 6:-1:1;
u = s.*t
OUTPUT: 6 10 12 12 10 6

4. s./t

s = 1:6;
t = 6:-1:1;
u = s./t
OUTPUT: 0.1667 0.4000 0.7500 1.3333 2.5000 6.0000

5. s.^2
s = 1:6;
t = 6:-1:1;
u = s.^2
OUTPUT: 1 4 9 16 25 36

Department of Mathematics, SJB Institute of Technology 15


2 3
Problem 2: Construct the polynomial y = (x + 2) (x + 1) for values of x from minus one to

one in steps of 0.1.


y = (x + 2)2(x3 + 1)

x=0.1
x= -1:0.1:1;
f = x+2;
g = x.^3+1;
y = (f.^2).*(g);
OUTPUT: x = 0.1000

Problem 3: Plot the polynomial y = x4 +x2 −1 between x = −2 and x = 2


y = x4 +x2 −1 between x = −2 & x = 2
x= linspace(-2,2,50);
c = [1 0 1 0 -1];
y = polyval(c,x);
plot(x,y)
OUTPUT:

Exercises:
1. Create two vectors running from one to six and from six to one and then
demonstrate the use of the dot arithmetical operations: s=1:6; t = 6:-1:1; find 1./s, s/2,
s+1.

2. Construct the polynomial y = (x + 2)3(x5 + 1) for values of x from minus one to one in
steps of 0.2.

Department of Mathematics, SJB Institute of Technology 16


VIVA questions and answers
1. Explain the purpose of using the poly command in MATLAB.
Ans. The poly command is used to work with polynomials in a variety of ways, particularly focusing
on constructing polynomials from their roots and finding polynomial coefficients.

2. Explain the purpose of using the linspace command in MATLAB.


Ans. the linspace command is used to generate linearly spaced vectors. This is particularly useful when
you need to create a range of values that are evenly distributed over a specified interval.

3. Explain the purpose of using the ‘:’operator in MATLAB.


Ans. the colon operator(:) is a versatile and frequently used tool for creating vectors, indexing, and
performing array operations.

4. Explain the purpose of using polyval command in MATLAB.


Ans. The polyval function is used to evaluate the value of a polynomial at specific points. This function
is particularly useful when you have a polynomial defined by its coefficients and you want to compute
its value for given input values.

5. Explain the purpose of using plot command in MATLAB.


Ans. The plot command in MATLAB is used to create 2D line plots and visualize data. It is a
fundamental tool for displaying relationships between variables and analyzing data through graphical
representations.

Department of Mathematics, SJB Institute of Technology 17


Experiment No-2: Write a Program to find the Laplace transform, Inverse Laplace
transform and unit step function.
AIM:
 The Laplace transform is a powerful mathematical tool used to convert complex time-domain
functions, typically involving differential equations, into simpler algebraic forms in the frequency
domain (s-domain). The primary aim is to simplify the process of analyzing and solving linear
time-invariant (LTI) systems, particularly those involving differential equations.
 The inverse Laplace transform convert functions from the frequency domain (s-domain) back into
the time domain. This is essential when solving differential equations or analyzing systems where
the solution or system behavior needs to be understood in terms of time.
 The unit step or Heaviside function is to provide a mathematical model for a signal or system input
that suddenly activates at a specific time and remains active indefinitely. This function helps in
representing situations where a system or signal turns "on" at a particular moment, such as the
activation of a switch or the onset of a force.

APPLICATION AND IMPORTANCE:


Application:
 In electrostatics, the Laplace equation describes the potential field generated by a distribution of
charges in a charge-free region. The electric potential ϕ satisfies the Laplace equation in regions
with no charge density.
 Essential for finding the time-domain response of circuits, particularly when analyzing transient
responses. Engineers can predict how a circuit will behave over time after being subjected to an
input signal.
 In signal processing, the Heaviside function represents signals that start at a specific time. It is used
in the analysis and design of filters, modulators, and other signal processing systems.

Importance:
 Enables the study of system behavior in the frequency domain, which is essential for understanding
resonance, filtering, and frequency response characteristics.
 Inverse Laplace transforms make theoretical solutions applicable to real-world problems, allowing
engineers to predict and control the behavior of systems over time.
 Many physical phenomena involve sudden changes, such as a switch being flipped or a force being
applied instantly. The unit step function provides a simple and effective way to model these events
mathematically.

Department of Mathematics, SJB Institute of Technology 18


Problem 1: Find the Laplace Transform of cosat, sinat, eat and tn
1. cosat
syms t s a % variables t, s and a are symbolic
% Define the function
f = cos (a * t);

% Compute the Laplace transform


F_s = laplace(f, t, s);
% Display the result
disp(F_s)

OUTPUT: s/(a^2 + s^2)

2. sinat

syms t s a
f = sin(a * t);

% Compute the Laplace transform


F_s = laplace(f, t, s);

% Display the result


disp(F_s)

OUTPUT: a/(a^2 + s^2)

at
3. e

syms t s a

% Define the function


f = exp(a * t);

% Compute the Laplace transform


F_s = laplace(f, t, s);

% Display the result


disp('Laplace Transform of e^(at):');
disp(F_s);

OUTPUT: -1/(a - s)

Department of Mathematics, SJB Institute of Technology 19


4.
syms t s n

% Define the function


f = t^n;

% Compute the Laplace transform


F_s = laplace(f, t, s);

% Display the result


disp('Laplace Transform of t^n:');
disp(F_s);

Problem 2: Find the Inverse Laplace Transform of , , ,

, and

1.
% Import the Symbolic Math Toolbox
syms s t

% Define the Laplace domain variable


S = s;

% Define the expression in the Laplace domain


expr = 1/(S + 2) + 3/(2*S + 5) - 4/(3*S - 2);

% Compute the inverse Laplace transform


f_t = ilaplace(expr, s, t);

% Simplify the result


f_t_simplified = simplify(f_t);

% Display the result


disp('The inverse Laplace transform is:');
disp(f_t_simplified);

OUTPUT: exp(-2*t) - (4*exp((2*t)/3))/3 + (3*exp(- (5*t)/2))/2


2.

syms s t
F = (s + 5) / (s^2 - 6*s + 13); % Define the given Laplace function
F_simplified = (s + 5) / ((s - 3)^2 + 4); % Express using the completed square form
f_t = ilaplace(F, s, t); % Find the inverse Laplace transform
disp(f_t); % Display the time-domain function

OUTPUT: exp(3*t)*(cos(2*t) + 4*sin(2*t))

Department of Mathematics, SJB Institute of Technology 20


3.

syms s t
F = 1 / (s * (s + 1) * (s + 2) * (s + 3)); % Define the Laplace function
F_partial = partfrac(F); % Perform partial fraction decomposition
f_t = ilaplace(F_partial, s, t); % Find the inverse Laplace transform
disp(f_t); % Display the time-domain function

OUTPUT: exp(-2*t)/2 - exp(-t)/2 - exp(-3*t)/6 + 1/6

4.
syms s t a b
F = log((s + a) / (s + b)); % Define the Laplace function
f_t = ilaplace(F, s, t); % Compute the inverse Laplace transform
disp(f_t); % Display the time-domain function

OUTPUT: exp(-b*t)/t - exp(-a*t)/t

5.
syms s t a tau

% Define the functions in the s-domain


F_s = 1/s;
G_s = 1/(s^2 + a^2);
% Compute the convolution in the time domain
f_t = ilaplace(F_s, s, t); % Inverse Laplace of 1/s
g_t = ilaplace(G_s, s, t); % Inverse Laplace of 1/(s^2 + a^2)
% Convolution integral
convolution_result = int(f_t * subs(g_t, t, t - tau), tau, 0, t);
% Simplified result
convolution_result = simplify(convolution_result);
disp('Convolution Result in Time Domain:');
disp(convolution_result);

OUTPUT: -(cos(a*t) - 1)/a^2

6.

syms s t k Y
% Define the Laplace transform equation
eqn = s^2*Y - 2*s + k^2*Y == 0;
% Solve for Y(s)
Y_s = solve(eqn, Y);
% Take the inverse Laplace transform to get y(t)
y_t = ilaplace(Y_s, s, t);
disp('The solution y(t) is:');
disp(y_t);

OUTPUT: The solution y(t) is:2*cos(k*t)

Department of Mathematics, SJB Institute of Technology 21


Problem 3: Find the Heaviside unit step function for
and

1.
syms t s
f = (exp(t-1) + sin(t-1)) * heaviside(t-1); % Define the function using Heaviside
function
F = laplace(f, t, s);
disp(F);

OUTPUT: exp(-s)*(1/(s - 1) + 1/(s^2 + 1))

2.
syms t s
f = sin(2*t) * (heaviside(t) - heaviside(t - pi)); % Define the piecewise function using
Heaviside functions
F = laplace(f, t, s);
disp(F);

OUTPUT: (2*exp(pi*s) - 2)/(4*exp(pi*s) + s^2*exp(pi*s))

3.

syms t s
f = cos(t) * heaviside(t) - cos(t) * heaviside(t - pi) + ...
cos(2*t) * heaviside(t - pi) - cos(2*t) * heaviside(t - 2*pi) + ...
cos(3*t) * heaviside(t - 2*pi);
F = laplace(f, t, s);
disp(F);

OUTPUT: s/(s^2 + 1) + (s*exp(-pi*s))/(s^2 + 1) + (s*exp(-pi*s))/(s^2 + 4) - (s*exp(- 2*pi*s))/(s^2 +4)


+ (s*exp(-2*pi*s))/(s^2 + 9)

Exercises:
1. Find the Laplace Transform of cos2t, sin4t, e6t and t3
2. Find the Inverse Laplace Transform of , ,

, and

3. Find the Heaviside unit step function f

4. or and

Department of Mathematics, SJB Institute of Technology 22


VIVA questions and answers
1. What is the Laplace transform, and why is it used in engineering and mathematics?
Ans. The Laplace transform is an integral transform used to convert a time-domain function ( ) into a
complex frequency-domain function ( ). It is widely used in engineering and mathematics to solve
differential equations, analyze systems, and control processes because it simplifies the mathematics by
turning differential equations into algebraic equations.

2. How does the Laplace transform differ from the Fourier transform?
Ans. The Laplace transform is a generalization of the Fourier transform. While the Fourier transform is
used for analyzing signals in terms of their frequency components and is applicable to periodic signals,
the Laplace transform is more versatile, handling a broader class of signals, including those that grow
exponentially, and is useful for both stable and unstable systems.

3. Explain the purpose of using the syms command in MATLAB.


Ans. The syms command in MATLAB is used to declare symbolic variables. These symbolic variables
allow MATLAB to perform algebraic computations exactly, rather than numerically. This is essential
for finding symbolic expressions for the Laplace transform.

4. What role does the inverse Laplace transform play in solving differential equations?
Ans. The inverse Laplace transform is crucial for obtaining the time-domain solution of a differential
equation after it has been solved in the s-domain. Once the algebraic equation in the s-domain is
solved, the inverse Laplace transform is applied to return the solution to its original time-domain form.

5. Can you give an example of a physical situation where the unit step function is used?
Ans. One example is in circuit analysis, where a voltage source is suddenly switched on at t=0.The
resulting voltage can be modeled using a unit step function to analyze how the circuit responds to this
sudden change.

Department of Mathematics, SJB Institute of Technology 23


Experiment No-3: Write a program to obtain the Fourier series and its properties.
AIM: The Fourier series is to represent a periodic function as a sum of sine and cosine functions. This
decomposition allows complex periodic signals to be analyzed and manipulated in the frequency domain, making it
easier to study their properties and perform various operations.

APPLICATION AND IMPORTANCE:


Application:

 Fourier series is used to analyze and process signals. By decomposing signals into their frequency
components, engineers can filter, compress, and enhance signals in communications and audio
processing.
 In electrical engineering, Fourier series are used to analyze alternating current (AC) circuits and
design filters. They help in understanding the behavior of circuits with periodic inputs.
 Fourier series help in analyzing and designing control systems by breaking down periodic signals
into their frequency components. This aids in system analysis, stability analysis, and controller
design.
 Fourier series are used in image processing for filtering and image compression. Techniques such
as JPEG compression use Fourier transforms to analyze and compress image data.
 In acoustics, Fourier series are used to analyze sound waves and musical tones. This helps in
sound synthesis, music analysis, and designing acoustically optimized environments.

Importance:

 Fourier series decompose complex periodic functions into simple sine and cosine components. This
simplification makes it easier to analyze and understand the frequency content of signals.
 By transforming signals into the frequency domain, Fourier series allow engineers and scientists to
study the frequency components and their contributions. This is essential for tasks like filtering,
signal reconstruction, and spectral analysis.
 Fourier series are crucial for designing and analyzing systems in various fields, including
electronics, control systems, and mechanical systems. They help in optimizing system performance
and stability.
 Fourier series enhance our understanding of periodic phenomena and their underlying structures.
This knowledge is applied across various scientific and engineering disciplines to solve real-world
problems.

Department of Mathematics, SJB Institute of Technology 24


Problem 1: Find the Fourier series for
% Define parameters
L = pi; % Interval length is [0, 2*pi], so L = pi
n_terms = 10; % Number of terms in Fourier series
x = linspace(0, 2*pi, 1000); % Points for evaluation
f = @(x) exp(x); % Function definition

% Compute Fourier coefficients


a0 = (1 / (2 * pi)) * integral(@(x) exp(x), 0, 2 * pi);
a_n = zeros(n_terms, 1);
b_n = zeros(n_terms, 1);

for n = 1:n_terms
a_n(n) = (1 / pi) * integral(@(x) exp(x) .* cos(n * x), 0, 2 * pi);
b_n(n) = (1 / pi) * integral(@(x) exp(x) .* sin(n * x), 0, 2 * pi);
end

% Construct the Fourier series


F_series = a0 / 2 * ones(size(x)); % a0/2 term
for n = 1:n_terms
F_series = F_series + a_n(n) * cos(n * x) + b_n(n) * sin(n * x);
end

% Plot the original function and its Fourier series approximation


figure;
plot(x, f(x), 'k', 'LineWidth', 2); hold on;
plot(x, F_series, 'r--', 'LineWidth', 2);
legend('Original function e^x', 'Fourier series approximation');
title('Fourier Series Approximation of e^x');
xlabel('x');
ylabel('f(x) and Fourier Series');
grid on;

OUTPUT:

Problem 2: Find the Half Range Fourier sine series for


Department of Mathematics, SJB Institute of Technology 25
% Define parameters
L = pi; % Interval length (0 to pi)
n_terms = 10; % Number of terms in the series
x = linspace(0, L, 1000); % Points where function and series will be evaluated

% Define the function


f = @(x) x .* sin(x); % Function definition

% Compute Half-Range Sine Series coefficients


b_n = zeros(n_terms, 1);

for n = 1:n_terms
b_n(n) = (2 / L) * integral(@(x) x .* sin(x) .* sin(n * x), 0, L);
end

% Construct the Half-Range Sine Series


F_sine_series = zeros(size(x)); % Initialize
for n = 1:n_terms
F_sine_series = F_sine_series + b_n(n) * sin(n * x);
end

% Plot the original function and its Fourier sine series approximation
figure;
plot(x, f(x), 'k', 'LineWidth', 2); hold on;
plot(x, F_sine_series, 'r--', 'LineWidth', 2);
legend('Original function x sin(x)', 'Half-Range Sine Series');
title('Half-Range Sine Series Approximation of x sin(x)');
xlabel('x');
ylabel('f(x) and Fourier Series');
grid on;

OUTPUT:

Department of Mathematics, SJB Institute of Technology 26


Problem 3: By using practical harmonic analysis find

x0 0 600 1200 1800 2400 3000


y 7.9 7.2 3.6 0.5 0.9 6.8
% Define the data points
x_deg = [0, 60, 120, 180, 240, 300]; % Angles in degrees
x_rad = deg2rad(x_deg); % Convert angles to radians
y = [7.9, 7.2, 3.6, 0.5, 0.9, 6.8]; % Function values

% Number of data points


N = length(x_rad);

% Compute the Fourier coefficients


% Compute a_0 (mean value)
a0 = (1 / N) * sum(y);

% Compute a_1 and b_1


a1 = (2 / N) * sum(y .* cos(x_rad));
b1 = (2 / N) * sum(y .* sin(x_rad));

% Display results
fprintf('a_0: %f\n', a0);
fprintf('a_1: %f\n', a1);
fprintf('b_1: %f\n', b1);

% Create a range for plotting


theta = linspace(0, 2*pi, 1000); % Range of angles for plotting
f_approx = a0 + a1 * cos(theta) + b1 * sin(theta); % Fourier series
approximation

% Plot the original data and the Fourier series approximation


figure;
plot(x_rad, y, 'ko', 'MarkerFaceColor', 'k'); hold on;
plot(theta, f_approx, 'r-', 'LineWidth', 2);
legend('Original Data', 'Fourier Series Approximation');
title('Fourier Series Approximation of Discrete Data');
xlabel('Angle (radians)');
ylabel('y');
grid on;

OUTPUT: a_0: 4.483333


a_1: 4.050000
b_1: 0.894893

Department of Mathematics, SJB Institute of Technology 27


EXERCISES:
1. Find the Fourier series for
2. Find the Half Range Fourier cosine series for
3. By using practical harmonic analysis find

x0 0 600 1200 1800 2400 3000


y 0 9.2 14.4 17.8 17.3 11.7

Department of Mathematics, SJB Institute of Technology 28


VIVA questions and answers

1. Explain the significance of the Fourier series in signal processing.


Ans. In signal processing, the Fourier series is significant because it allows the decomposition of
complex periodic signals into simpler sinusoidal components. This decomposition helps in analyzing
the frequency content of the signal, filtering out noise, and designing filters and equalizers. It is
essential for tasks such as audio compression, signal reconstruction, and spectral analysis.

2. Why is the Fourier series useful for solving partial differential equations (PDEs).
Ans. The Fourier series is useful for solving PDEs because it allows the decomposition of complex
boundary value problems into simpler, solvable components. By representing the solution as a series of
sine and cosine functions, the problem can be transformed into a set of ordinary differential equations
or algebraic equations, which are easier to solve. This approach is commonly used in problems
involving heat conduction, wave propagation, and vibrations.

3. Can you provide an example of a practical application of the Fourier series?


Ans. One practical application of the Fourier series is in image compression. In image processing, the
Discrete Cosine Transform (DCT), which is closely related to the Fourier series, is used to transform
image data into the frequency domain. By representing the image in terms of its frequency
components,
it is possible to compress the image by retaining only the most significant frequencies, thus reducing the
file size while preserving essential details.

4. What is practical harmonic analysis?


Ans. Practical harmonic analysis involves analyzing and synthesizing signals using harmonic
components, which are sinusoids with frequencies that are integer multiples of a fundamental
frequency. It is used in various applications such as signal processing, vibration analysis, and acoustics
to understand the frequency content of signals, design filters, and model periodic phenomena. It relies
on techniques like Fourier series and Fourier transforms to decompose complex signals into their
harmonic constituents.
5. Explain the purpose of using the grid on command in MATLAB.
Ans. The ‘grid on’ command adds horizontal and vertical lines to the plot at major and minor ticks on
the x and y axes. These grid lines help in visually aligning and reading data points more easily, which
is especially useful for detailed plots or when precise values are important.

Department of Mathematics, SJB Institute of Technology 29


Experiment No-4: Implementation of Fourier transform and its properties
AIM:
The Fourier transform is to convert a signal or function from its original time domain (or spatial domain)
into the frequency domain. This transformation provides a way to analyze the frequency components of the
signal, making it easier to study and process signals in terms of their frequency content rather than their
time or spatial behavior.
APPLICATION AND IMPORTANCE:
Application:
 Fourier transform is widely used in signal processing to analyze the frequency components of
signals. It helps in filtering, signal reconstruction, and noise reduction. Applications include audio
processing, image processing, and communications.
 In image processing, the Fourier transform is used to analyze and manipulate the frequency content
of images. Techniques such as image filtering, compression (e.g., JPEG), and enhancement rely on
Fourier transforms.
 Fourier transforms are essential in communication systems for modulating and demodulating
signals, designing filters, and analyzing signal bandwidth and spectrum. They help in improving
data transmission and reception quality.
 In audio analysis, the Fourier transform is used to decompose audio signals into their frequency
components. This is useful for tasks like noise reduction, audio compression, and identifying the
characteristics of sound signals.
 In control systems, the Fourier transform helps in analyzing and designing systems by examining
their frequency response. It aids in system stability analysis and controller design.

IMPORTANCE:
 Fourier transforms are crucial in signal processing for various tasks, including filtering,
compression, and signal reconstruction. They enable the efficient processing and analysis of signals
in both the time and frequency domains.
 Fourier transforms are fundamental in data compression techniques. By transforming data into the
frequency domain, it is possible to remove redundant information and compress data more
efficiently, as seen in image and audio compression formats.
 In engineering and control systems, the Fourier transform helps in analyzing system responses and
designing systems to meet specific performance criteria. It aids in understanding how systems
behave across different frequencies.
 The Fourier transform provides a powerful method for analyzing signals in the frequency domain.
This allows for easier understanding and manipulation of signal characteristics, such as identifying
dominant frequencies, analyzing spectral content, and designing filters.

Department of Mathematics, SJB Institute of Technology 30


Problem 1: Find the Fourier transform of
syms x w

% Define the function f(x) = e^(-|x|)


f = exp(-abs(x));

% Compute the Fourier Transform


F_w = fourier(f, x, w);

% Display the Fourier Transform


disp('The Fourier Transform of f(x) = e^{-|x|} is:');
pretty(F_w)

% Plot the magnitude of the Fourier Transform


figure;
fplot(abs(F_w), [-10, 10], 'LineWidth', 2);
title('Magnitude of the Fourier Transform of f(x) = e^{-|x|}');
xlabel('Frequency (\omega)');
ylabel('|F(\omega)|');
grid on;

OUTPUT: The Fourier Transform of f(x) = e^{-|x|} is:

EXERCISES:
1. Find the Fourier transform of

Department of Mathematics, SJB Institute of Technology 31


VIVA questions and answers
1. How does the Fourier Transform differ from the Fourier Series?
Ans. The Fourier Transform and Fourier Series are both tools for analyzing signals, but they differ in
their applications, Fourier Series used for representing periodic functions as a sum of sines and cosines
over a finite interval. It decomposes a periodic function into its frequency components with discrete
frequencies. Fourier Transform used for analyzing non-periodic functions or signals that extend over
the entire time domain. It provides a continuous spectrum of frequencies, representing the function as a
sum of continuous frequency components.

2. Can you describe a practical application of the Fourier Transform in signal processing?
Ans. In signal processing, the Fourier Transform is used for audio signal analysis. For example, in
audio compression techniques such as MP3 encoding, the Fourier Transform is used to convert audio
signals from the time domain into the frequency domain. By analyzing the frequency components, the
algorithm can remove less significant frequencies, reducing the file size while preserving the quality of
the audio. This application illustrates how the Fourier Transform helps in efficient data compression
and improves audio storage and transmission.

3. What is the significance of the frequency domain representation obtained from the Fourier
Transform?
Ans. The frequency domain representation obtained from the Fourier Transform is significant because
it reveals the frequency content of a signal. Frequency Analysis understanding which frequencies are
present in the signal and their relative strengths. Filtering designing and applying filters to remove or
enhance specific frequency components. Signal compression compressing signals by retaining only
significant frequency components. Signal reconstruction reconstructing signals from their frequency
components using the inverse Fourier Transform. System analysis analyzing how systems respond to
different frequencies, which is essential for system design and stability analysis.

4. Explain the purpose of using the grid on command in MATLAB.


Ans. The legend helps identify and differentiate between multiple data sets or plot elements, making the
plot more informative and easier to interpret.

5. Explain the purpose of using the pretty command in MATLAB.


Ans. The pretty command formats mathematical expressions to make them more readable and
aesthetically pleasing. It transforms symbolic expressions into a clearer, more conventional format,
which helps in understanding complex equations.

Department of Mathematics, SJB Institute of Technology 32


Experiment No-5: Implementation of Z-transform and its properties
AIM: The Z transform is to convert discrete-time signals or sequences from the time domain into the
complex frequency domain. This transformation provides a method for analyzing and manipulating
discrete-time signals and systems in a more convenient form, particularly for system analysis, design, and
digital signal processing.
APPLICATION AND IMPORTANCE:
Application:
 In digital signal processing, the Z transform is used to design and analyze digital filters. It helps in
characterizing filter behavior, determining stability, and implementing filters in digital systems.
 The Z transform is used to analyze discrete-time systems, including stability, causality, and
response characteristics. It simplifies the study of system behavior by transforming difference
equations into algebraic equations.
 In discrete-time control systems, the Z transform helps in analyzing and designing digital
controllers. It is used to convert continuous-time controllers into discrete-time equivalents and to
analyze the performance of digital control systems.
 The Z transform is essential in various signal processing applications, including data compression,
noise reduction, and modulation. It facilitates the manipulation of signals in the frequency domain
for efficient processing.
 In digital communications, the Z transform is used for analyzing and designing communication
systems that operate with discrete-time signals. It helps in optimizing the performance and
reliability of communication systems.

Importance:
 The Z transform provides a powerful tool for analyzing discrete-time signals and systems in the
frequency domain. It enables the study of signal behavior in terms of its frequency components,
making it easier to design and analyze systems.
 The Z transform simplifies the manipulation of difference equations, which describe discrete-time
systems. By converting difference equations into algebraic equations, it makes it easier to solve and
analyze system behavior.
 The Z transform helps in determining the stability and response of discrete-time systems. It
provides a method for analyzing system poles and zeros, which are crucial for understanding
system behavior and designing stable systems.
 In digital filter design, the Z transform is used to create and analyze filters that operate on discrete-
time signals. It allows for the design of filters with specific frequency characteristics and helps
ensure that the filters perform as intended.

Department of Mathematics, SJB Institute of Technology 33


Problem 1: Find the Z transform of
syms n z a

% Define the sequence x[n] = e^(-an)


x = exp(-a * n);

% Compute the Z-transform


X_z = ztrans(x, n, z);

% Display the result


disp('The Z-transform of x[n] = e^{-an} is:');
pretty(X_z)

% Simplifying the expression


X_z_simplified = simplify(X_z);
disp('Simplified Z-transform:');
pretty(X_z_simplified);

OUTPUT: Simplified Z-transform:

EXERCISES:
1. Find the Z transform of
2. Find the Z transform of

Department of Mathematics, SJB Institute of Technology 34


VIVA questions and answers

1. What is the difference between the Z transform and the Fourier transform?
Ans. The Z transform and the Fourier transform are both used for analyzing signals, but they differ in their
applications and domains.Z transform applied to discrete-time signals and sequences, converting them
into the complex frequency domain. It includes both the magnitude and phase information and is used
to analyze discrete-time systems, solve difference equations, and design digital filters. Fourier
transform typically used for continuous-time signals, converting them into the frequency domain. It
provides a continuous spectrum of frequencies and is used for analyzing continuous-time signals and
systems.

2. Explain the purpose of using the ‘disp’ command in MATLAB.


Ans. The ‘disp’ command in MATLAB is used to display text or variables in the Command Window. It provides
a simple and effective way to output information without formatting or additional decorations, making it useful
for displaying messages, variable values, and results during script execution or interactive sessions.

3. Explain the purpose of using the ‘simplify’ command in MATLAB.


Ans. The ‘simplify’ command is used to simplify symbolic expressions. It is part of the Symbolic Math Toolbox
and helps reduce complex expressions to their simplest forms by applying algebraic simplifications. This
command is especially useful for simplifying mathematical equations, expressions, and functions to make them
more manageable and easier to interpret.

4. Explain the purpose of using the ‘fprintf’ command in MATLAB.


Ans. The ‘fprintf’ command in MATLAB is used to write formatted data to the Command Window or to a file.
It allows for precise control over the format of the output, including the alignment, width, and precision of
numeric values. This makes ‘fprintf’ a powerful tool for generating readable and well-structured output, whether
for debugging, reporting results, or creating formatted text files.

5. Can you provide an example of a practical application of the Z transform.


Ans. One practical application of the Z transform is in digital filter design. Digital filters are used in various
fields such as signal processing, communications, and control systems to modify or enhance signals.

Department of Mathematics, SJB Institute of Technology 35


Experiment No-6: Write a program to find the correlation between two variables and the
plot the Regression line.
AIM:
 Correlation is to measure the strength and direction of the linear relationship between two
variables. It quantifies how changes in one variable are associated with changes in another variable.

 Regression analysis is to model the relationship between a dependent variable and one or more
independent variables. The regression line represents the best fit line that predicts the dependent
variable based on the independent variable(s).

APPLICATIONS AND IMPORTANCE:

Applications:
 Understanding relationships between variables in exploratory data analysis. For example,
analyzing the relationship between hours studied and exam scores.

 Assessing the relationship between stock prices and economic indicators. For instance, studying
how changes in interest rates affect stock returns.

 Examining the correlation between lifestyle factors and health outcomes, such as the relationship
between exercise and cholesterol levels.

 Used to predict the value of a dependent variable based on known values of independent variables.
For example, predicting sales based on advertising expenditure.

 In engineering and manufacturing, regression can optimize processes and control systems by
modeling and adjusting variables to achieve desired outcomes.

Importance:

 Predictive Insight helps in identifying patterns and making predictions based on the relationship
between variables.

 In machine learning, correlation helps in selecting relevant features that are strongly related to the
target variable.

 Provides valuable insights for decision-making by understanding how variables are related.

 Quantitative Analysis provides a quantitative measure of the relationship between variables,


including the strength, direction, and nature of the relationship.

 Enables predictions and forecasts based on the regression model, facilitating planning and
decision-making.

Department of Mathematics, SJB Institute of Technology 36


Problem1: The two-regression equation of the variables x and y are x=19.13-0.87y and y=11.64-0.5 x,
Find the correlation coefficient between x and y.
% Given regression coefficients
bx = -0.87; % Coefficient of y in the regression equation of x on y
by = -0.5; % Coefficient of x in the regression equation of y on x

% Calculate the correlation coefficient


r = -sqrt(bx * by); % Negative since both slopes are negative
disp(['Correlation Coefficient: r = ', num2str(r)]);

% Plotting the two regression lines


y_values = linspace(0, 30, 100); % Generate 100 y-values from 0 to 30
x1_values = 19.13 - 0.87 * y_values; % x = 19.13 - 0.87y
x_values = linspace(0, 30, 100); % Generate 100 x-values from 0 to 30
y2_values = 11.64 - 0.5 * x_values; % y = 11.64 - 0.5x

% Plot the regression lines


figure;
plot(x1_values, y_values, 'r-', 'LineWidth', 2); % Plot the first regression line
hold on;
plot(x_values, y2_values, 'b-', 'LineWidth', 2); % Plot the second regression line
hold off;

% Add labels and title


xlabel('X Values');
ylabel('Y Values');
title('Regression Lines and Correlation Coefficient');
legend('x = 19.13 - 0.87y', 'y = 11.64 - 0.5x', 'Location', 'Best');
grid on;

OUTPUT: r = -0.65955

EXERCISES:
1. The two-regression equation of the variables x and y are x=15.13-0.87y and
y=21.64-0.5 x. Find the correlation coefficient between x and y.

Department of Mathematics, SJB Institute of Technology 37


VIVA questions and answers

1. What is the purpose of fitting a regression line?


Ans. The purpose of fitting a regression line is to model the relationship between a dependent variable
and one or more independent variables. This line provides a way to predict the value of the dependent
variable based on the independent variable(s) and to analyze the nature of the relationship between
them.
2. What is the difference between simple and multiple regression?
Ans. Simple Regression involves one independent variable and one dependent variable. The goal is to
model the relationship between these two variables using a linear equation. Multiple Regression
involves two or more independent variables and one dependent variable. It models the relationship
between the dependent variable and multiple independent variables simultaneously.

3. Explain the purpose of using the ‘linewidth’ command in MATLAB.


Ans. The linewidth command in MATLAB is used to specify the width of lines in plots and graphical
elements. It controls the thickness of lines in various plot types, including plots, graphs, and other
visual representations. Adjusting the line width helps in improving the clarity and visual appeal of
plots, especially when presenting data or results.

4. Explain the purpose of using the ‘hold on’ command in MATLAB.


Ans. The hold on command in MATLAB is used to retain the current plot and add new plots to the
same figure without erasing the existing data. This allows you to overlay multiple plots on a single
figure, which is useful for comparing different data sets or visualizing multiple elements together.

5. Explain the purpose of using the ‘hold off’ command in MATLAB.


Ans. The hold off command in MATLAB is used to release the current plot and reset the state so that
subsequent plotting commands replace the existing plot rather than adding to it. This command is
essential for controlling how new plots interact with existing ones.

Department of Mathematics, SJB Institute of Technology 38


Experiment No-7: Write a program to find the Fitting a straight line by the method of least
square using MATLAB.

AIM:

The Method of Least Squares is to find the best-fitting line or model that minimizes the sum of the squared
differences between the observed data points and the values predicted by the model. It is used to
approximate the solution of an overdetermined system of equations, where the number of equations
exceeds the number of unknowns.

APPLICATION AND IMPORTANCE:


Application:
 Data Fitting to find the best-fit curve or line for a set of data points. For example, fitting a linear
model to experimental data to understand the relationship between variables.

 Regression Analysis estimate the coefficients of a linear regression model, which predicts a
dependent variable based on one or more independent variables.

 Signal Processing estimate parameters of a signal model from noisy data. For example, filtering out
noise from a signal by fitting a model to the observed data.

Importance:
 Best Fit Model provides a method to determine the line or curve that best represents the underlying
relationship in the data, which is essential for prediction and analysis.

 Minimizes Errors by minimizing the sum of squared errors, the method ensures that the model has
the smallest possible discrepancy from the actual data, leading to more accurate predictions.

 Statistical Analysis forms the basis for many statistical techniques, including regression analysis,
which is widely used in economics, engineering, and various scientific fields to make inferences
and predictions.

Department of Mathematics, SJB Institute of Technology 39


Problem 1: By the method of least squares, find the straight line that best fits the following
data: x: 1, 2, 3 ,4 ,5 and y: 14 ,27 ,40, 55, 68.

% Sample data (replace these with your actual data)


x = [1, 2, 3, 4, 5]; % x-values
y = [2, 4.1, 6, 8.1, 10]; % y-values
% Number of data points
n = length(x);
% Construct the design matrix A
A = [x(:), ones(n, 1)];
% Solve for the coefficients using the normal equation: (A' * A) * beta = A' * y
beta = (A' * A) \ (A' * y');
% Extract the coefficients
m = beta(1); % Slope
c = beta(2); % Intercept
% Calculate the fitted values
y_fit = A * beta
% Plot the original data and the fitted line
figure;
plot(x, y, 'bo', 'MarkerFaceColor', 'b'); % Original data points
hold on;
plot(x, y_fit, 'r-', 'LineWidth', 2); % Fitted line
legend('Data Points', 'Fitted Line');
title('Linear Least Squares Fitting');
xlabel('x');
ylabel('y');
grid on;
hold off;
% Display the results
fprintf('Fitted line: y = %.2fx + %.2f\n', m, c);

OUTPUT:

EXERCISES:
1. Find the best possible curve of the curve of the form y =a+bx, using the least squares
for the data: x=1 3 4 6 8 9 11 14 and y=1 2 4 4 5 7 8 9

Department of Mathematics, SJB Institute of Technology 40


VIVA questions and answers
1. Why do we minimize the sum of squared errors in the Method of Least Squares?
Ans. We minimize the sum of squared errors because it provides a measure of how well the model fits the data.
By squaring the errors, we ensure that all errors are positive and emphasize larger deviations more than smaller
ones. Minimizing this sum leads to the most accurate estimation of the model parameters, resulting in the best fit
for the data.

2. Can the Method of Least Squares be used for fitting curves other than lines? If so, give an example.
Ans. Yes, the Method of Least Squares can be used to fit curves other than lines. For example, it can be
used to fit a quadratic curve to a set of data points. If the model is , the coefficients
are determined by minimizing the sum of the squared errors between the observed
values and the values predicted by this quadratic equation.

3. Explain the purpose of using the ‘length’ command in MATLAB.


Ans. The length command in MATLAB is used to determine the number of elements in the largest
dimension of an array. This command is particularly useful when working with vectors and arrays, as it
provides a quick way to assess the size of the data structure you're working with.

4. Explain the purpose of using the ‘ones’ command in MATLAB.


Ans. The ones command in MATLAB is used to create an array (matrix, vector, or multidimensional
array) where all elements are set to 1. This command is particularly useful in situations where you need
to initialize arrays with a constant value, perform matrix operations, or set up identity matrices (with
some modifications).

5. Explain the purpose of using the ‘fprintf’ command in MATLAB.


Ans. The ‘fprintf’ command in MATLAB is used for formatted output, allowing you to display text
and variables in a customized format on the screen or write them to a file. This command is
particularly useful when you need precise control over how data is presented, such as in reports,
debugging, or creating user-friendly outputs.

Department of Mathematics, SJB Institute of Technology 41


Experiment No-8: MATLAB program to solve application problem using Laplace
transform.

Problem 1: Analyze the RLC circuit using the Laplace transform for a resistance of 2
ohms, an inductance of 3 henry, and a capacitance of 3.5 microfarads.

R = 2; % Resistance in ohms
L = 3; % Inductance in henries
C = 3.5; % Capacitance in farads

% Define the transfer function in Laplace domain


num = 1; % Numerator for step input (V(s) = 1/s)
den = [L R 1/C];
% Create the transfer function for I(s)
sys = tf(num, den);

% Plot the step response (i.e., the response to V(t) = 1 * u(t))


step(sys);
title('Step Response of the Series RLC Circuit');
xlabel('Time (s)');
ylabel('Current i(t)');
grid on;

OUTPUT:

Department of Mathematics, SJB Institute of Technology 42


EXERCISES:
1. Analyze the RLC circuit using the Laplace transform for a resistance of 1
ohms, an inductance of 5 henry, and a capacitance of 2.5 microfarads.

Department of Mathematics, SJB Institute of Technology 43


VIVA questions and answers.
1. What is the significance of each component in an RLC circuit?
Ans. Resistor (R) dissipates energy as heat and limits the current. Inductor (L) stores energy in a
magnetic field and opposes changes in current. Capacitor (C) stores energy in an electric field and
opposes changes in voltage.

2. What are some practical applications of RLC circuits?


Ans. RLC circuits are widely used in radio transmitters and receivers, filters, oscillators, and in tuning
circuits to select a specific frequency from a complex signal. They are also used in power systems for
harmonic filtering and in impedance matching networks.

3. What is the significance of using the Laplace transform in analyzing circuits like this RLC circuit?
Ans. The Laplace transform simplifies the analysis of circuits by converting differential equations (in
the time domain) into algebraic equations (in the s-domain). This makes it easier to solve for the
system’s behavior, especially for complex circuits.

4. What does the step response of the RLC circuit represent?


Ans. The step response represents how the current in the circuit evolves over time after a sudden
application of a voltage step (e.g., turning on a DC source). It shows how the circuit reaches a new
steady state.

5. Sate Kirchhoff’s Voltage Law.


Ans. Kirchhoff’s Voltage Law is the second of his fundamental laws we can use for circuit analysis.
His voltage law states that for a closed loop series path the algebraic sum of all the voltages around any
closed loop in a circuit is equal to zero. This is because a circuit loop is a closed conducting path so no
energy is lost.

Department of Mathematics, SJB Institute of Technology 44


Experiment No-9: MATLAB program to solve application problem using Fourier
transform.

Problem 1: Apply the Fourier transform for the following Image.

% MATLAB code for Forward and


% Inverse Fourier Transform
clc
clear all
close all
% FORWARD FOURIER TRANSFORM
k=imread('cameraman.jpg');
% Apply fourier transformation.
f=fft2(k);
% apply inverse FT on FTransformed image.
% we get original image in this step.
j=ifft2(f);

% Take log of original image.


j1=log(abs(j));

% Shift corners to center.


j2=fftshift(j);

% Again shift to get original image.


j3=fftshift(j2);

% Remove some frequency from FT image.


f(1:20, 20:40)=0;

% Apply inverse FT.


j4=ifft2(f);

% Display all 4 images.


imtool(j,[]);
imtool(j1,[]);
imtool(j2,[]);
imtool(j3,[]);%j and j3 are same.
imtool(abs(j4),[]);

Department of Mathematics, SJB Institute of Technology 45


OUTPUT:

Figure 1: Original Input Image was obtained by Figure 2: log of absolute Inverse Fourier Transform image.
taking the Inverse FT of the FT image

Figure 3: Corners shifted to center. Figure 4: Inverse FT after removing some frequencies
from Freq Domain.

Department of Mathematics, SJB Institute of Technology 46


VIVA questions and answers

1. Explain the purpose of using the ‘imtool’ command in MATLAB.


Ans. The ‘imtool’ command in MATLAB is a powerful tool used for interactive exploration and analysis of
images. It provides a graphical interface that allows users to view and manipulate images in various ways.

2. Explain the purpose of using the ‘fftshift’ command in MATLAB.


Ans. The ‘fftshift’ command in MATLAB is used to shift the zero-frequency component of a Fourier-
transformed signal to the center of the spectrum. This is particularly useful for visualizing and analyzing the
frequency domain representation of signals.

3. What is the purpose of using the Fourier Transform in image processing?


Ans. The Fourier Transform is used in image processing to analyze and manipulate images in the frequency
domain. Frequency Analysis it transforms an image from the spatial domain to the frequency domain, allowing
us to analyze the frequency components of the image. This is useful for identifying patterns, textures, and
periodicities. Filtering Fourier Transform helps in designing and applying filters. For example, low-pass filters
can be used to remove high-frequency noise, while high-pass filters can enhance edges and details. Image
Enhancement enhancing an image’s contrast or sharpening can be achieved more effectively in the frequency
domain by adjusting specific frequency components.

4. What are some common image processing tasks that involve the Fourier Transform?
Ans. Image Compression techniques like JPEG use Fourier Transform (or its variants) for efficient
image compression. Edge Detection using frequency domain techniques to detect edges and patterns in
images. Image Restoration enhancing or recovering images degraded by noise or distortion through
frequency domain methods. Frequency Domain Analysis analyzing periodic structures or patterns
within images.

5. What is the significance of using abs in the Fourier Transform of an image?


Ans. The ‘abs’ function is significant in the Fourier Transform of an image because it extracts the
magnitude of the complex frequency components, which is essential for visualizing and analyzing the
frequency content. By converting complex values to their magnitudes, abs facilitates the interpretation
of how different frequencies contribute to the image, which is crucial for various image processing
tasks and analysis.

Department of Mathematics, SJB Institute of Technology 47


Experiment No-10: MATLAB program to solve application problem using Z- transform.

Problem 1: Apply the Z transform and Digital Filtering on a Discrete Signal.


clc
clear all
close all
x = [2 2 2 2];
h = [1 1 1 1]/4; % filter (h) --- > A third-order filter has length 4
y = conv(h,x) % convolve filter with x

b = [1 1 1 1];
a = [0.25 .25 .25 .25];
y = filter(b,a,x)

OUTPUT: y = 0.5000 1.0000 1.5000 2.0000 1.5000 1.0000 0.5000


y=8 8 8 8

Problem 2: Apply the Z transform and analyze the noise effect on figure.
I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
K = wiener2(J);
L = medfilt2(J);
figure, imshow(I), figure, imshow(K)

figure,imshow(L)

OUTPUT:

Department of Mathematics, SJB Institute of Technology 48


Department of Mathematics, SJB Institute of Technology 49
VIVA questions and answers
1. How is the Z-transform related to the Fourier transform?
Ans. The Z-transform is a generalization of the Discrete-Time Fourier Transform (DTFT). If we
evaluate the Z-transform on the unit circle (where ∣z∣=1), we obtain the DTFT. Essentially, the Z-
transform extends the DTFT by including the complex variable z, which allows it to analyze stability
and system behavior more comprehensively.

2. Explain the purpose of using the ‘conv’ command in MATLAB.


Ans. To perform convolution between two sequences or vectors. Convolution is a fundamental
mathematical operation used extensively in signal processing, image processing, and various other
fields. It combines two sequences to produce a third sequence, representing the amount of overlap
between the sequences as one slides past the other.

3. What is the importance of ‘filter’ command in MATLAB.


Ans.The filter command in MATLAB is used to apply a digital filter to a signal. It is a powerful tool in
signal processing for implementing linear time-invariant (LTI) systems, where it processes the input
signal according to the difference equation that characterizes the filter.

4. Explain the purpose of using the ‘wiener2’ command in MATLAB.


Ans. It is important for performing adaptive noise reduction on images or 2D signals. This function
implements the Wiener filter, which is a type of statistical filter designed to minimize the mean square
error between the original signal and the filtered signal. The wiener2 function is specifically tailored
for image processing and is particularly effective in removing noise while preserving edges and fine
details in images.

5. What is the importance of ‘medfilt2’ command in MATLAB.


Ans. It is important for performing median filtering on 2D signals, particularly images. Median
filtering is a nonlinear filtering technique used primarily for noise reduction. It is especially effective at
removing certain types of noise, such as "salt-and-pepper" noise, while preserving edges and other
sharp features in an image.

Department of Mathematics, SJB Institute of Technology 50

You might also like