MATLAB, PDF
MATLAB, PDF
MATLAB
MATLAB is short for “matrix laboratory.” It is a high-level programming language and
platform that works with matrices and arrays rather than individual numbers. Designed for
scientists and engineers, MATLAB is often used in textbooks as an instructional tool for
college-level mathematics, science, and engineering. It allows for the most direct and
natural expression of matrix and array mathematics.
The MATLAB programming platform is used to design, develop, and analyze systems and
products. Originally, it was created for accessing software developed by the LINPACK and
EISPACK projects. The MATLAB we know today has numerous use cases thanks to many
contributions from users over the years. Examples include:
• Data analysis
• Large-scale computations
• Algorithm development
• Application development
• Embedded system development
• Control systems engineering
• Deployment of Internet of Things (IoT) applications
• Creation of deep learning models.
USES OF MATLAB :
• Data analysis: MATLAB is used for analyzing data, including data exploration and
visualization.
• Modeling and simulation: MATLAB is used for modeling, simulation, and
prototyping.
• Algorithm development: MATLAB is used to develop algorithms.
• Application development: MATLAB is used for developing applications,
including graphical user interfaces.
• Embedded system development: MATLAB is used to develop embedded systems,
such as those found in washing machines, printers, and automobiles.
• Control systems: MATLAB is used for designing, testing, and implementing
control systems.
• Image and video processing: MATLAB is used for acquiring, processing, and
analyzing images and video.
• Deep learning: MATLAB is used for creating deep learning models.
• Computational finance and biology: MATLAB is used for computational finance
and biology.
• Robotics: MATLAB is used for robotics.
• Wireless communications: MATLAB is used for wireless communications.
Features of MATLAB
MATLAB is renowned for its extensive range of features, making it a versatile and
powerful tool for professionals across different domains. Here are the top 10 Features of
MATLAB that set it apart from other programming languages and software
tools. MATLAB employs a high-level programming language that allows users to express
complex mathematical operations and algorithms concisely. The MATLAB language is
designed to resemble mathematical notation, making it intuitive for users with
mathematical backgrounds to transition into programming. Its syntax is easy to read and
write, promoting efficient code development and readability. One of MATLAB's
standout features is its interactive environment. It provides both the command-line
interface (CLI) and the graphical user interface (GUI), allowing users to interact with
their code and data seamlessly. The command window enables quick prototyping, data
exploration, and iterative development by providing immediate feedback on
computations. The GUI tools, such as the Editor and Debugger, enhance the development
process, allowing users to write, debug, and test their code efficiently.
MATLAB ENVIRONMENT:
• Command Window
• Command History
• Workspace
• Current Directory
• Figure Window
Command Window:
Whenever MATLAB is invoked, the main window called command
window is activated. The command window displays the command
prompt’>>’ and a cursor where commands are entered and are executed
instantaneously.
EXPERIMENT .NO. 1
AIM: INTRODUCTION TO PYTHON/MATLAB FOR SIGNAL PROCESSING.
Software: MATLAB
Theory:
The expression of MATLAB consist of various math functions like as arithmetic,
trigonometric, logarithmic, exponential, constant term value, etc. These functions have
proper syntax.
Arithmetic functions
Arithmetic symbol Operation
+ Addition
_ Subtraction
* Multiplication
/ Division
Trigonometric functions
Exponential function
Square functions
Symbol Operation
^ Power or square
Logarithm functions
Symbol Operation
Symbol Operation
Remainder function
Symbol Operation
rem(p , q)
Symbol Operation
Symbol Operation
PROCEDURE:
• Open MATLAB
• Open new M-file
• Type the program
• Save in current directory
• Compile and Run the program
• For the output see command window\ Figure window
•
Program:
t = -1:0.01:1; IC = @(t) t == 0;USC = @(t) t >= 0;URC = @(t) t .* (t >= 0);
EC = @(t) exp(t);SC = @(t) sin(2*pi*t);CC = @(t) cos(2*pi*t);n = -10:10;
ID = @(n) n == 0;USD = @(n) n >= 0;URD = @(n) n .* (n >= 0);
ED = @(n) exp(n/10);SD = @(n) sin(2*pi*n/10);CD = @(n) cos(2*pi*n/10);
tc = gauspuls("cutoff",50e3,0.6,[],-40); t1 = -tc : 1e-6 : tc;
y1 = gauspuls(t1,50e3,0.6);t2 = linspace(-5,5);y2 = sinc(t2);
figure;
subplot(3,2,1);
plot(t, IC(t), 'LineWidth', 2);
title('Continuous Impulse Function');xlabel('Time (t)');ylabel('\delta(t)');
axis([-1 1 -0.5 1.5]);grid on;subplot(3,2,2);
plot(t, USC(t), 'LineWidth', 2);
title('Continuous Unit Step Function');xlabel('Time (t)');ylabel('u(t)');
axis([-1 1 -0.5 1.5]);grid on;
subplot(3,2,3);
plot(t, URC(t), 'LineWidth', 2);
title('Continuous Unit Ramp Function');xlabel('Time (t)');ylabel('r(t)');
axis([-1 1 -0.5 1.5]);grid on;
subplot(3,2,4);
plot(t, EC(t), 'LineWidth', 2);
title('Continuous Exponential Function');xlabel('Time (t)');ylabel('e^t');
axis([-1 1 -0.5 3]);grid on;
subplot(3,2,5);
plot(t, SC(t), 'LineWidth', 2);
title('Continuous Sine Function');xlabel('Time (t)');ylabel('sin(2\pi t)');
axis([-1 1 -1.5 1.5]);grid on;
subplot(3,2,6);
plot(t, CC(t), 'LineWidth', 2);
title('Continuous Cosine Function');xlabel('Time (t)');ylabel('cos(2\pi t)');
axis([-1 1 -1.5 1.5]);grid on;
% Plot Discrete Functions
figure;
subplot(3,2,1);
stem(n, ID(n), 'filled');
title('Discrete Impulse Function');xlabel('n');ylabel('\delta[n]');
axis([-10 10 -0.5 1.5]);grid on;
subplot(3,2,2);
stem(n, USD(n), 'filled');
title('Discrete Unit Step Function');xlabel('n');ylabel('u[n]');
axis([-10 10 -0.5 1.5]);grid on;
subplot(3,2,3);
stem(n, URD(n), 'filled');
title('Discrete Unit Ramp Function');xlabel('n');ylabel('r[n]');
axis([-10 10 -5 15]);grid on;
subplot(3,2,4);
stem(n, ED(n), 'filled');
title('Discrete Exponential Function');xlabel('n');ylabel('e^{n/10}');
axis([-10 10 -0.5 3]);grid on;
subplot(3,2,5);
stem(n, SD(n), 'filled');
title('Discrete Sine Function');xlabel('n');ylabel('sin(2\pi n/10)');
axis([-10 10 -1.5 1.5]);grid on;
subplot(3,2,6);
stem(n, CD(n), 'filled');
title('Discrete Cosine Function');xlabel('n');ylabel('cos(2\pi n/10)');
axis([-10 10 -1.5 1.5]);grid on;
figure;
subplot(2,1,2);
stem(t2,y2,'g','LineWidth',1.5)
xlabel("Time (sec)");ylabel("Amplitude");title("Sinc Function");
grid on;
subplot(2,1,1);
stem(t1*1e3,y1,'r','LineWidth',1.5)
xlabel("Time (ms)");
ylabel("Amplitude");title("Gaussian Pulse");grid on;zoom xon;
RESULTS:
Results have been seen on the command window.
EXPERIMENT NO : 4
AIM : Perform convolution and correlation operations on signals.
Software : MATLAB
THEORY :
CONVOLUTION is a mathematical tool to combining two signals to form a third
signal. Therefore, in signals and
systems, the convolution is very important because it relates the input signal and the
impulse response of the system to produce the output signal from the system. In other
words, the convolution is used to express the input and output relationship of an LTI
system.
> Consider two signals x(n) and h(n). Then, the convolution of these two signals is
defined as:
> Y(n) = x(n)*h(n)
Where Y(n) = output of LTI
x(n) = input of LTI
y(n) = impulse response of LTI
PROCEDURE :
Step 1: Give input sequence x(n).
Step 2: Give impulse response h(n).
Step 3: Find the convoution y(n) using the matlab command convolution.
Step 4: Plot x(n), h(n), Y(N).
PROGRAM :
clc;
disp('Enter the length of sequence 1 -:');m = input('');
disp('enter the 1st sequencex[m]-:');
for i = 1:m
x(i) = input('');
end
disp('enter the length of 2nd sequence -:');n = input('');
disp('enter the 2nd sequence h[n]-:');
for j = 1:n
h(j) = input('');
end
y = conv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel('amplitude---->');xlabel('n--->');
subplot(3,1,2);
stem(h);
ylabel('amplitude---->');xlabel('m---->');
subplot(3,1,3);
stem(y);
ylabel('amplitude------>');xlabel('y----->');
Output-:
THEORY :
Auto Correlation Function : Auto Correlation Function gives the measure of
similarity or coherence b/w a signal and its delayed replica and is known as
special form of a cross¬ correlation function.
ALGORITHM :
Step I : Give input sequence x[n].
Step III: Find auto correlation using the MATLAB command xor.
PROGRAM :
Clc:
Close all;
Clear all ;
x = [1,0,2,1,3,2,4,3,4,2,3,1,2,0];
subplot(2,1,1);
stem(x,'r');
xlabel('Discrete time') ;
ylabel('Amplitude');
title('Input Sequence') ;
h = [0,1,2,2,2,4,4,4,4,4,3,3,3,2,1];
subplot(2,1,2);
stem(h,'g');
xlabel('Discrete time') ;
ylabel('Discrete time');
figure;
subplot(2,1,1);
y = xcorr(x);
stem(y, 'b');
subplot(2,1,2);
z = xcorr(h);
stem(z, 'y');
xlabel('Discrete time')
ylabel('Discrete time')
Result:
Thus we got auto correlation and cross correlation of signal.
PRECAUTIONS :
• Programs can never be saved as standard function name.
• Functions in MATLAB are case sensitive so commands must be written in
proper
format.
EXPERIMENT : 6
Aim : Write a matlab program to analyze the Fourier series .
Software :MATLAB
Theory : To represent any periodic signal x(t), Fourier developed an
expression called Fourier series. This is in terms of an infinite sum of sines and
cosines or exponentials.
and,
Program:
ft = input('Enter any function of t: ');ft = str2sym(ft);
t1 = input('Enter first time limit : ');t2 = input('Enter second time limit : ');
syms t; a0 = (1/T)*int(ft,t1,t2);
an = (2/T)*int(ft*cos(n*Wo*t),t1,t2); bn = (2/T)*int(ft*sin(n*Wo*t),t1,t2);
for i = 1:N
end
ansum = eval(ansum);
bnsum = eval(bnsum);
Avg = avg*ones(1*length(t));
subplot(2,2,1);
for i = 1:N
plot(t,harmonics,'r','LineWidth',2);
hold on
end
subplot(2,2,2);
plot(t,Avg,'g','LineWidth',2);
hold off
xlabel('Time'); ylabel('Amplitude');
fto = eval(ft);
subplot(2,2,2)
plot(t,Series,t,fto,'r','LineWidth',2);
xlabel('time'); ylabel('amplitude');
grid on; zoom on;
Output: