Sunteți pe pagina 1din 5

Experiment 1A: Arithmetic Operations

Compute MATLAB command Result Comment


clc; clear all; Clear Command Window
Remove items from
MATLAB workspace
a=input('enter the first Enter the first matrix [1 2; 3 4] a= 1 2
matrix'); 3 4
b=input('enter the second Enter the second matrix [5 6; 7 8] b= 5 6
matrix');
7 8
c=a+b; c= 6 8 % addition
10 12
d=a-b; d= -4 -4 % subtraction
-4 -4
e=a*b; e= 19 22 % element by
43 50 element
multiplication
f=a.*b f= 5 12 % element by
21 32 element
multiplication
g=a/b g= 3.0000 -2.0000 % division
2.0000 -1.0000
h=a./b h= 0.2000 0.3333 % element by
0.4286 0.5000 element
division

i=a^2 i= 7 10 % exponential
15 22
j=a.^2 j= 1 4 % element by
9 16 element
exponention
k=det(a) k= -2 % determint

l=inv(a) l= -2.0000 1.0000 % inverse


1.5000 -0.5000
m=2*a m= 2 4 % scalar
6 8 multiplication

n=a' n= 1 3 % transpose
2 4
q=[a a; b b] q= 1 2 1 2 % concatenation
3 4 3 4
5 6 5 6
7 8 7 8
a(:,2)=[] a= 1 % deleting the
3 second column

p= q(1:3,1:3) p= 1 2 1 % Index exceeds


3 4 3 matrix
dimensions.
5 6 5
r=[q(:,4) q(:,1) q(:,3) r= 2 1 1 2 %Interchange
q(:,2)] 4 3 3 4 the colomns of
a matrix
6 5 5 6
8 7 7 8

DSP LAB CBIT - ECE Page 1


Experiment 1B: GENERATION OF BASIC SIGNALS
Compute MATLAB command Result Comment
clc; clear all; %Clear Command Window
% Remove items from
MATLAB workspace
close all; % deletes all figures
whose handles are not
hidden
n=input('enter the value of n:'); enter the value of n: 5 Requests user input
n=5

t=-n:n; t = -5 -4 -3 -2 -1
0 1 2 3 4 5
ximpulse=[zeros(1,n) ones(1,1)
zeros(1,n)];
subplot(5,2,1)
plot(t,ximpulse); xlabel('Time');
ylabel('Amplitude'); title('Impulse
function');

subplot(5,2,2)
stem(t,ximpulse); xlabel('Time');
ylabel('Amplitude'); title('Impulse
sequence');

tunitstep=0:n;
xstep=ones(1,n+1);
subplot(5,2,3)
plot(tunitstep,xstep);
xlabel('Time'); ylabel('Amplitude');
title('Unitstep function');

subplot(5,2,4)
stem(tunitstep,xstep);
xlabel('Time'); ylabel('Amplitude');
title('Unitstep sequence');

tramp=0:n;
subplot(5,2,5)
plot(tramp,tramp); xlabel('Time');
ylabel('Amplitude'); title('Ramp
function');

subplot(5,2,6)
stem(tramp,tramp); xlabel('Time');
ylabel('Amplitude'); title('Ramp
sequence');

texp=0:.1:n;
xexp=10*exp(texp);subplot(5,2,7)
plot(texp,xexp); xlabel('Time');
ylabel('Amplitude');
title('Exponential function');

subplot(5,2,8)
stem(texp,xexp); xlabel('Time');
ylabel('Amplitude');
title('Exponential sequence');

tsine=0:0.1:n;
xsine=sin(tsine);
subplot(5,2,9)
plot(tsine,xsine); xlabel('Time');
ylabel('Amplitude'); title('Sine
function');

subplot(5,2,10)
stem(tsine,xsine); xlabel('Time');
ylabel('Amplitude'); title('Sine
sequence');

DSP LAB CBIT - ECE Page 2


Compute MATLAB command Result Comment
tcos=0:0.001:n;
xcos=cos(tcos);
figure, subplot(5,2,1)
plot(tcos,xcos); xlabel('Time');
ylabel('Amplitude'); title('Cos
function');
subplot(5,2,2)
stem(tcos,xcos); xlabel('Time');
ylabel('Amplitude'); title('Cos
sequence');

tsaw=0:0.001:.1;
xsaw=sawtooth(2*pi*100*tsaw,0.5);
subplot(5,2,3)
plot(tsaw,xsaw); xlabel('Time');
ylabel('Amplitude');
title('Sawtooth function');

subplot(5,2,4)
stem(tsaw,xsaw); xlabel('Time');
ylabel('Amplitude'); title('Sawtooth
sequence');

tsquare=0:0.001:.1;
xsquare=square(2*pi*100*tsquare,50);
subplot(5,2,5)
plot(tsquare,xsquare);
xlabel('Time'); ylabel('Amplitude');
title('Square function');

subplot(5,2,6)
stem(tsquare,xsquare);
xlabel('Time'); ylabel('Amplitude');
title('Square sequence');

xran=rand(1,100);
subplot(5,2,7)
plot(0:99,xran); xlabel('Time');
ylabel('Amplitude'); title('random
noise function');

subplot(5,2,8)
stem(0:99,xran); xlabel('Time');
ylabel('Amplitude'); title('random
noise sequence');

DSP LAB CBIT - ECE Page 3


Experiment 2: LINEAR AND CIRCULAR CONVOLUTION
Compute MATLAB command Result Comment
clc; clear all; Clear Command Window
Remove items from
MATLAB workspace
close all; deletes all figures
whose handles are
not hidden
x1 = input('Enter the first % Get the first
sequence:'); sequence
x2 = input('Enter the second % Get the second
sequence:'); sequence
N1 = length(x1); % Returns the length
of first sequence
N2 = length(x2); % Returns the length
of second sequence
N = N1+N2-1; % Get the Maximum
length out of two
signals
X1=[x1 zeros(1,N-N1)];

X2=[x2 zeros(1,N-N2)];

for m=1:N
y(m) = 0;
for n=1:N
i=m-n+1;
if(i<=0)
i=N+i;
end
y(m) = y(m)+X1(n)*X2(i);
end
end
disp('The linear convolution of two % Displays the
given sequences is:'); result on command
disp(y); window

n=0:N-1; % Get the length for x-axis

subplot(3,1,1)
stem(1:N1, x1); xlabel('Time');
ylabel('x(n)'); title('input
sequence x(n)');
subplot(3,1,2)
stem(1:N2, x2); xlabel('Time');
ylabel('h(n)');
title('input sequence h(n)'
subplot(3,1,3)
stem(n, y);
xlabel('Time'); ylabel('linear
convolution output');
title('linear convolution');

DSP LAB CBIT - ECE Page 4


Experiment 2: LINEAR AND CIRCULAR CONVOLUTION
Compute MATLAB command Result Comment
clc; clear all; Clear Command Window
Remove items from
MATLAB workspace
close all; deletes all figures
whose handles are
not hidden

DSP LAB CBIT - ECE Page 5

S-ar putea să vă placă și