Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

MATLAB, PDF

all matlab practicles

Uploaded by

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

MATLAB, PDF

all matlab practicles

Uploaded by

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

Introduction to Matlab

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

Trigonometric symbol Operation/Symbol

sin(t) Performs sin operation on variable t.

cos(t) Performs cosine operation on variable t.

tan(t) Performs tangent operation on variable t.

asin(t) Perform arc sin operation on variable t or


inverse of the sin function.

acos(t) Perform arc cosine operation on variable t


or inverse of the cosine function.
atan(t) Perform arc tangent operation on variable
t or inverse of the tangent function.

Exponential function

Exponential Symbol Operation

exp(t) Performs exponential operation on


variable t .

Square functions

Symbol Operation

^ Power or square

Sqrt(t) Perform square root operation on


variable t .

Logarithm functions

Symbol Operation

log(t) Perform a natural logarithmic operation


on variable t .

log10(t) Perform a common logarithmic operation


on variable t .

Maximum & Minimum functions

Symbol Operation

min(t) Find minimum value from array t .

max(t) Find maximum value from array t .

Remainder function
Symbol Operation

rem(p , q)

Phase angle function

Symbol Operation

angle(t) Gives phase angle for variable t .

Other useful function

Symbol Operation

abs(t) Return absolute value for variable t .

sign(t) Return sign of the variable t .

ceil(t) Return ceil value for variable t .

floor(t) Return floor value for variable t .

conj(t) Gives complex conjugate variable t .

round(t) Return nearest integer of variable t .

Constant term value function

Symbol/Constant Associated Constant value

pi The π number = 3.14159…

i,j The imaginary unit √ -1

Inf The infinity,∞

These are the mathematical functions representation in the MATLAB.


EXPERIMENT NO. 2-3
AIM:
1.To represent the basic signals (Sine , cosine , gauss , sinc)
2. To represent basic signals(unit step , unit impulse , unit ramp , exponential)

THEORY: MATLAB is an interactive, matrix-based system for scientific and


engineering numeric computation and visualization. Its strength lies in the fact that
complex numerical problems can be solved easily and in a fraction of the time required
by a programming language such as Fortran or C.

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

RESULTS: - Thus the program for linear convolution is written using


MATLAB and verified
EXPERIMENT NO : 5
AIM : Write a Matlab program to compute autocorrelation between two
sequence.

SOFTWARE USED : MATLAB

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 II : Give impulse response sequence h(n).

Step III: Find auto correlation using the MATLAB command xor.

Step IV : Plot x[n], h[n],z[n].

Step V : Display the result .

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');

title('Input Sequence 2') ;

xlabel('Discrete time') ;

ylabel('Discrete time');

figure;

subplot(2,1,1);

y = xcorr(x);

stem(y, 'b');

title('Autocorrelation of the Input Sequence') ;

xlabel('Discrete time'); ylabel('Discrete time')

subplot(2,1,2);

z = xcorr(h);

stem(z, 'y');

title('cross correlation of the Input Sequence') ;

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.

Fourier series uses orthoganality condition. Fourier Series Representation of


Continuous Time Periodic Signals : A signal is said to be periodic ,if it satisfies
the condition: x (t) = x (t + T) or x (n) = x (n + N). Where;

T = fundamental time period,

and,

wo( fundamental frequency) = 2k/T P

Program:
ft = input('Enter any function of t: ');ft = str2sym(ft);

N = input('Enter no. of Harmonics calculated : ');

t1 = input('Enter first time limit : ');t2 = input('Enter second time limit : ');

T = t2 - t1; Wo = 2*pi/T; n = 1:10;

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

An = an.*cos(n*Wo*t); Bn = bn.*sin(n*Wo*t);avg = double(a0);

t = t1:0.0001:t2; t=t(:,1:end-1); ansum = 0; bnsum = 0;

for i = 1:N

ansum = ansum + An(i);


bnsum = bnsum + Bn(i);

end

ansum = eval(ansum);

bnsum = eval(bnsum);

Series = avg + ansum + bnsum ;

Avg = avg*ones(1*length(t));

subplot(2,2,1);

for i = 1:N

harmonics = eval(An(i) + Bn(i));

plot(t,harmonics,'r','LineWidth',2);

hold on

end

grid on; zoom on;

subplot(2,2,2);

plot(t,Avg,'g','LineWidth',2);

hold off

title(strcat('First',num2str(N),'Harmonics and Average Value'))

legend('Harmonics ','Average Value');

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;

title('Fourier approximation and actual Function')

legend('Fourier approx','actual Function')

Output:

You might also like