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

DLDEXPALL

Uploaded by

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

DLDEXPALL

Uploaded by

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

Experiment 1

Aim: Write a MATLAB program to perform the Basic Operations on Matrices.


Apparaters: Personal computer and MATLAB software.
PROGRAM:
% Basic Matrix Operations
clc;
close all;
% Addition of 2 matrices
A = [ 1 2 3; 3 4 5; 6 7 8];
B = [ 1 2 3; 2 4 7; 3 5 8];
C=A+B
% Subtraction of 2 Matrices
D=A-B
% Multiplication of 2 Matrices
E=A*B
% Division of 2 Matrices
F=A/B
% Inverse of 2 Matrices
G=inv(A)
%Element by Element Multiplication
H=A.*B
% Transpose of matrices
A_transpose=A'
B_transpose=B'
% Determinant
K=det(A)
L=det(B)
% Eigen Values and Eigen Vectors
[V,E]=eig(A)
[V,E]=eig(B)

Output:
C=
2 4 6
5 8 12
9 12 16
D=
0 0 0
1 0 -2
3 2 0
E=
14 25 41
26 47 77
44 80 131
F=
1.0000 0 0
1.0000 -2.0000 2.0000
1.0000 -5.0000 5.0000
G=
1.0e+015 *
-2.7022 4.5036 -1.8014
5.4043 -9.0072 3.6029
-2.7022 4.5036 -1.8014
H=
1 4 9
6 16 35
18 35 64
A_transpose =
1 3 6
2 4 7
3 5 8
B_transpose =
1 2 3
2 4 5
3 7 8
K =0
L=1
V=
-0.2656 -0.7444 0.4082
-0.4912 -0.1907 -0.8165
-0.8295 0.6399 0.4082
E=
14.0664 0 0
0 -1.0664 0
0 0 -0.0000
V=
-0.2797 -0.2360 - 0.4332i -0.2360 + 0.4332i
-0.6148 0.7650 0.7650
-0.7374 -0.3864 + 0.1486i -0.3864 - 0.1486i
E=
13.3063 0 0
0 -0.1531 + 0.2274i 0
0 0 -0.1531 - 0.2274i
Experiment 2

Aim: Write a MATLAB program to generate Various Signals and Sequences (Periodic and
Aperiodic) such as Unit Impulse, Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp,
and Sinc function.
Apparaters: Personal computer and MATLAB software.
PROGRAM:

% to plot sinusoidal signal%

clear all
t=-1:.01:1;
x1=sin(2*pi*1.5*t);
subplot(3,3,1);
plot(t,x1);
xlabel('----> t ');
ylabel('x1(t)');
title(' sinusoidal signal');

% to plot an exponential signal%


x2=exp(-2*t);
subplot(3,3,2);
plot(t,x2);
xlabel('----> t ');
ylabel('x2(t)');
title(' exponential signal');

% to plot sawtooth signal %


t1=-20:0.01:20;
x3=sawtooth(t1);
subplot(3,3,3);
plot(t1,x3);
xlabel('----> t1 ');
ylabel('x3(t)');
title(' swatooth signal');

% to plot a square signal5


t1=-20:0.01:20;
x4=square(t1);
subplot(3,3,4);
plot(t1,x4);
xlabel('----> t1 ');
ylabel('x4(t)');
title(' square signal');
clear all

% to plot sinc function %


t1=-20:0.01:20;
x5=sinc(t1/2);
subplot(3,3,5) ;
plot(t1,x5);
xlabel('----> t1 ');
ylabel('x5(t)');
title(' sinc function');

% to plot rectangular pulse %


x6=rectpuls(t1/10);
subplot(3,3,6), plot(t1,x6);
xlabel('----> t1 ');
ylabel('x6(t)');
title('rectangular pulse');

% to plot triangular pulse%


x7=tripuls(t1/10);
subplot(3,3,7) ;
plot(t1,x7);
xlabel('----> t1 ');
ylabel('x7(t)');
title('triangular pulse');

% to plot signum function%


x8=sign(t1/3);
subplot(3,3,8) ;
plot(t1,x8);
xlabel('----> t1 ');ylabel('x8(t)');
title('signum function');
Output Waveforms:
% to generate unit step sequence%

N=31;
x1=ones(1,N);
n=0:1:N-1;
subplot(2,2,1);
stem(n,x1);
xlabel('n ');
ylabel('x1(n)');
title('unit step sequence');

% to generate sinusoidal sequence %


x2=2*cos(.1*pi*n);
subplot(2,2,2);
stem(n,x2);
xlabel('n ');
ylabel('x2(n)');
title('sinusoidal sequence');

% to generate an exponential sequence %


x3=.6.^(n) ;
subplot(2,2,3), stem(n,x3);
xlabel('n ');
ylabel('x3(n)');
title('exponential sequence');

% to generate unit impulse %


n=-4:1:4;
x4=[zeros(1,4),ones(1,1),zeros(1,4);]
subplot(2,2,4);
stem(n,x4);
xlabel('n ');
ylabel('x4(n)');
title('unit impulse');

Output Waveforms:
%to generate unit ramp sequence %

n=0:1:10;
x1=n ;
subplot(3,1,1);
stem(n,x1);
xlabel('n ');
ylabel('x1(n)');
title('unit ramp sequence');

% to generate unit step sequence %


n=-4:1:4;
x2=[zeros(1,4),ones(1,5)];
subplot(3,1,2);
stem(n,x2);
xlabel('n ');
ylabel('x2(n)');
title('unit step sequence');

% to generate sinusoidal sequence %


n=-20:.25:20;
x3=2*sin(.5*pi*n);
subplot(3,1,3);
stem(n,x3);
xlabel('n ');
ylabel('x3(n)');
title('sinusoidal sequence');

Output Waveforms:
Experiment 3

Aim: Write a MATLAB program to perform Operations on Signals and Sequences such as
Addition, Multiplication, Scaling, Shifting, Folding, Computation of Energy and Average
Power.
Apparaters: Personal computer and MATLAB software.
PROGRAM:

% ADDTION OF TWO SEQUENCES %

% input sequence 1 %
n=0:1:3;
x=[1,2,2,3];
n1=length(x);
subplot(2,2,1);
stem(n,x);
xlabel('n');
ylabel('input sequence1');

% input sequence 2 %
n=0:1:3;
y=[1,6,4,3];
n2=length(y);
subplot(2,2,2);
stem(n,y);
xlabel('n');
ylabel('input sequence 2');

% addition of x and y %
n=0:1:6;
r1=x+y;
subplot(2,2,3);
stem(r1);
xlabel('n');
ylabel('addition of x and y ');

Output Waveforms:
% ADDITION OF TWO SINUSOIDAL SIGNALS %

clc;
t=0:.01:pi;
y1=sin(2*pi*t);
subplot(3,1,1);
plot(t,y1);
title('sinusoidal signal 1');
y2=cos(3*pi*t);
subplot(3,1,2);
plot(y2);
title('sinusoidal signal 2');
h=y1+y2;
subplot(3,1,3);
plot(h);
title('addition of two sinusoidal signals');

Output Waveforms:
% TIME SCALING ,TIME SHIFTING %

clear all;
tmin=-15;
tmax=20;
t=tmin:.1:tmax;
y0=y(t);
y1=y(t+4);
y2=2*y(t-3);
y3=y(2*t);
y4=y(2*t-3);
y5=y(t/2);
y6=y(-t);
ymax=max([max(y0),max(y1),max(y2),max(y3),max(y4),max(y5)]);
ymin=min([min(y0),min(y1),min(y2),min(y3),min(y4),min(y5)]);
subplot(3,2,1),plot(t,y0);
xlabel('t'),ylabel('y0');
axis([tmin tmax ymin ymax]);
subplot(3,2,2),plot(t,y1);
xlabel('t'),ylabel('y1');
axis([tmin tmax ymin ymax]);
subplot(3,2,3),plot(t,y2);
xlabel('t'),ylabel('y2');
axis([tmin tmax ymin ymax]);
subplot(3,2,4),plot(t,y3);
xlabel('t'),ylabel('y3');
axis([tmin tmax ymin ymax]);
subplot(3,2,5),plot(t,y4);
xlabel('t'),ylabel('y4');
axis([tmin tmax ymin ymax]);
subplot(3,2,6),plot(t,y5);
xlabel('t'),ylabel('y5');
axis([tmin tmax ymin ymax]);

% generation of function y(t) %

function x=y(t);
x1=t+5;
x2=11+4*t;
x3=24-9*t;
x4=t-6;
x=x1.*(-5<t&t<=-2)+x2.*(-2<t&t<=1)+x3.*(1<t&t<=3)+x4.*(3<t&t<=-6);

Output Waveforms:
Experiment 4

Aim: Write a MATLAB program to Find a) Even and Odd parts of a Signal b) Real and
Imaginary parts of a signal

Apparaters: Personal computer and MATLAB software.

PROGRAM:

clear all; clc; close all; % Clear workspace, command window, and close all figures
t = -10:0.01:10; % Define time vector from -10 to 10 with a step size of 0.01
% Define the given signal y(t)
y0 = y(t);
% Time reversal of the signal
y1 = y(-t);
% Find maximum and minimum values for setting y-axis limits
ymax = max([max(y0), max(y1)]);
ymin = min([min(y0), min(y1)]);
% Plotting the original and time-reversed signals
subplot(4, 2, 1), plot(t, y0);
xlabel('t');
ylabel('y(t)');
title('Original Signal');
subplot(4, 2, 2), plot(t, y1);
xlabel('t');
ylabel('y(-t)');
title('Time-Reversed Signal');
% Even part of the signal
ye = (y0 + y1) / 2;
% Odd part of the signal
yo = (y0 - y1) / 2;
% Plotting the even and odd parts
subplot(4, 2, 3), plot(t, ye);
xlabel('t');
ylabel('y_e(t)');
title('Even Part of Signal');
subplot(4, 2, 4), plot(t, yo);
xlabel('t');
ylabel('y_o(t)');
title('Odd Part of Signal');
% Shifting the signal by 2 units to the right
subplot(4, 2, 5), plot(t, y(t - 2));
xlabel('t');
ylabel('y(t-2)');
title('Shifted Right by 2 units');
% Shifting the signal by 2 units to the left
subplot(4, 2, 6), plot(t, y(t + 2));
xlabel('t');
ylabel('y(t+2)');
title('Shifted Left by 2 units');
% Stretching the signal horizontally by a factor of 2
subplot(4, 2, 7), plot(t, y(t * 2));
xlabel('t');
ylabel('y(t*2)');
title('Time Scaling (t*2)');

% Compressing the signal horizontally by a factor of 2


subplot(4, 2, 8), plot(t, y(t / 2));
xlabel('t');
ylabel('y(t/2)');
title('Time Scaling (t/2)');
% Define the function y(t) based on given conditions
function x = y(t)
x1 = 4;
x2 = 2;
x = x1 .* (0 < t & t <= 2) + x2 .* (2 < t & t <= 4);
end

OUTPUT:
Experiment 5

Aim: Write a MATLAB program to find the Convolution between Signals and Sequences.
Apparaters: Personal computer and MATLAB software.
PROGRAM:
% Convolution of two given sequences x and h%
clear all
x=[1,2,1,2,1,3,2];
N1=length(x);
n=0:1:N1-1;
subplot(2,2,1),stem(n,x);
xlabel('n'),ylabel('x(n)');
title('input sequence of x(n)');
h=[1,-1,2,-2,1,1];
N2=length(h);
n1=0:1:N2-1;
subplot(2,2,2),stem(n1,h);
xlabel('n'),ylabel('h(n)');
title('impulse sequence of x(n)');
y=conv(x,h)
n2=0:1:N1+N2-2;
subplot(2,1,2),stem(n2,y);
xlabel('n'),ylabel('y(n)');
title('Convolution of two sequences of x(n) and h(n)');

OutputWaveforms:
% Convolution of 2 signals %

clc;
t=0:.01:pi;
y1=sin(2*pi*t);
subplot(3,1,1);
plot(t,y1);
y2=cos(3*pi*t);
subplot(3,1,2);
plot(y2);
h=conv(y1,y2);
subplot(3,1,3);
plot(h);

OutputWaveforms:
Experiment 6

Aim: Write a MATLAB program to find the Auto Correlation and Cross Correlation of two
Signals and Sequences.
Apparaters: Personal computer and MATLAB software.
PROGRAM:

% TO GENERATE THE AUTO CORRELATION and CROSS CORRELATION%

% input sequence1 %

n=0:1:3;
x=[1,2,2,3];
n1=length(x);
subplot(2,2,1),stem(n,x);
xlabel('n'); ylabel('input sequence');

% input sequence2 %

n=0:1:3;
y=[1,6,4,3];
n2=length(y);
subplot(2,2,2);
stem(n,y);
xlabel('n');
ylabel('input sequence');

% auto correlation of x and y %

n=0:1:6;
r1=xcorr(x,x);
subplot(2,2,3), stem(r1);
xlabel('n'); ylabel('ACR sequence');

% cross correlation of x and y %

n=0:1:6;
r2=xcorr(x,y);
subplot(2,2,4), stem(r2);
xlabel('n');
ylabel('CCR sequence');

Output Waveforms:
% ACR and CCR OF TWO SINUSOIDAL SIGNALS%

% to generate sine sequence %


n=-20:.25:20
x1=2*sin(.5*pi*n);
subplot(4,1,1), stem(n,x1);
xlabel('n ');
ylabel('x1(n)');
title('sine sequence');

% to generate cosine sequence %


x2=2*cos(.1*pi*n);
subplot(4,1,2), stem(n,x2);
xlabel('n ');
ylabel('x2(n)');
title('cosine sequence');
% autocorrelation of x1 and x2 %
n=0:1:6;
r1=xcorr(x1,x2);
subplot(4,1,3), stem(r1);
xlabel('n');
ylabel('autocorrelation of x1 and x2');

% crosscorrelation of x and y %
n=0:1:6;
r2=xcorr(x1,x2);
subplot(4,1,4), stem(r2);
xlabel('n');
ylabel('crosscorrelation of x and y');

Output Waveforms:
Experiment 7

Aim: Write a MATLAB program to verify the Sampling Theorem.


Apparaters: Personal computer and MATLAB software.
PROGRAM:

% Sampling Theorem %
clc;
clear all;
close all;
t=-100:.01:100;
fm=.02;
x=cos(2*pi*t*fm);
subplot(2,2,1),plot(t,x);
xlabel('time in sec'),ylabel('x(t)');
title('continous time signal');
fs1=.02;
n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(2,2,2),stem(n,x1);
hold on
subplot(2,2,2);
plot(n,x1);
title('discrete time signal x(n) with fs<2fm');
xlabel('n'),ylabel('x(n)');
fs2=0.04;
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(2,2,3),stem(n1,x2);
hold on
subplot(2,2,3);
plot(n1,x2);
title('discrete time signal x(n) with fs=2fm');
xlabel('n'),ylabel('x(n)');
n2=-50:50;
fs3=.5;
x3=cos(2*pi*fm*n2/fs3);
subplot(2,2,4),stem(n2,x3);
hold on
subplot(2,2,4);
plot(n2,x3);
title('discrete time signal x(n) with fs>2fm');
xlabel('n'),ylabel('x(n)');

Output Waveforms:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy