0% found this document useful (0 votes)
22 views35 pages

DSP Notes

It's dsp notes

Uploaded by

oppsp7796
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views35 pages

DSP Notes

It's dsp notes

Uploaded by

oppsp7796
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Experiment:1

.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. Aim: to perform

addition and subtraction of matrix

Apparatus required : MATLAB software


Code:
clear all;
disp('enter the row of matrix');

m=input('');

disp('enter the col of matrix');

n=input('');

a=zeros (m,n);
b=zeros(m,n);
disp('enter the element in matrix a'); for

i=1:m;

for j=1:n;

ele=input('');

a(i,j)=ele

; end;

end;

disp('enter the elements in matrix b');

for i=1:m;

for j=1:n;
ele2=input('');

b(i,j)=ele2

; end;

end;

c=zeros(m,n);
d=zeros(m,n);

for i=1:m;

for j=1:n;

c(i,j)=a(i,j)+b(i,j);

d(i,j)=a(i,j)-b(i,j)

; end;

end;

disp('addition');c

disp('subration');d
Experiment:2
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. Aim: Program to

generate identity matrix

Apparatus required : MATLAB software


Code:
(i) To perform left diagonal identity matrix.
(ii) To perform right diagonal identity matrix.
(iii) To perform corner identity matrix.
………………………………………………………………………………………
……………………………………….
(i) =>
clear all;

close all;

c=zeros(3)

; for i=1:3;

for

j=1:3;

if i==j;
c(i,j)=1
; end

end

end
disp('identity matrix');c
……..

(ii)
clear all;

close all;

c=zeros(3)
; row=1;

col=3;
for i=1:3;

c(row,col)=1

;
row=row+1;

col=col-1;

end

disp('identity matrix');c
…………………………………………………………………
… (iii)
clear all;

close all;

disp('enter the dimension of matrix :')

n=input('');

a=zeros(n);

a(1,1)=1;
a(1,n)=1;
a(n,1)=1;
a(n,n)=1;
disp('required matrix');a
Experiment:3
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. Aim: Program to

generate circular convolution without using inbuilt function.

Using x1(n)=[1,2,2,1] and x2(n)=[1,2,3,1]


Apparatus required : MATLAB software
Code:
clear all;

x=input('enter the

sequence'); n1=length(x);

h=input('enter the

sequence'); n2=length(x);

N=max(n1,n2);

x=[x,zeros(1,N-n1)

];

h=[h,zeros(1,N-n2)]
; y=zeros(1,N);

for i=0:N-1;

for

j=0:N-1;

k=mod((i-j),N);

y(i+1)=y(i+1)+h(j+1)*x(k+

1); end
end
disp('the output sequence is');
Experiment:4

.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*. Aim: Program to

generate circular convolution using inbuild function with plot Appartus required:

MATLAB software

Code :

clc;

clear

all;

close

all;

n=[1 2 2 1];

h=[1 2 3 1];
subplot(2,2,1
) stem(n,'g');

xlabel('time >')

ylabel('amplitude

Manikanta

) subplot(2,2,2)
stem(h,'r');

ylabel('amplitude
Manikanta) xlabel('time

>')
%xlabel('n(N1)*h(N2)') N1=length(n);
N2=length(h);

N=max(N1,N2

);
Y=cconv(n, h,

N)

subplot(2,2,3)

stem( Y, 'fill');

xlabel('n(N1)*h(N2)')

ylabel('amplitude

Manikanta) disp('Y')

Output:
Experiment:5
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: :Program to generate circular convolution without using inbuild function Code :

clc;

clear

all;

close

all;

x = [1, 2, 1];
h = [1, 2, 3, 1];
N1=length(x)
;
N2=length(h)
;
N= max

(N1,N2);

if(N1<N2

x= [x, zeros

(1,N-N1)] end

if (N1>N2)

h= [h, zeros
(1,N-N2)] end

y=zeros(1, N);

for m = 0 : N – 1

for n = 0 : N –
1
z=mod (m - n, N)
y(m + 1) =y(m+1)+x(n+1) *

h(z+1) ; end

end

stem(y)

xlabel ('x(n) * (h(n))');

ylabel('samplesManikanta');

title(‘Circular convolution’);

disp(‘y=’) disp(y)

Output

:
Experiment:6
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: Program to show x1(n) is periodic with N, x2(N) is periodic with N2 and then
x1(N) + x2(N) Are periodic.
Apparatus Required:MATLAB

software Code:

clear all;
n = 0 : 1 : 30
x =sin( 0.2 * pi * n) y

=cos( 0.2 * pi

* n) z = x + y;
subplot(2,2,1), stem ( n, x, 'g')

subplot(2,2,2), stem ( n, y , 'b')


subplot(2,2,3), stem ( n, z , 'r')

grid ON

Output:
Experiment:7
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: Program to compare circular convolution and linear convolution of two sequence
x = [1,1,1,2,1,1] and h = [1,1,2,1]
Apparatus Required:MATLAB

software Code:

clear all;
x = [1, 1, 1, 2, 1, 1];
h = [1, 1, 2, 1];
Nh =

length(h); Nx

= length(x);
N = max(Nx, Nh);

yc = cconv(x, h, N);
y = conv(x, h);
n = (0/1)/N * x - 1; subplot(2,2,1),

stem(n, x, 'b'); . xlabel('n'),

ylabel('x(n)'); title('input

sequence'); n =

0:1:Nh-1;

subplot(2,2,2), stem(n, h);


xlabel('n'),
ylabel('h(n)');

title('impulse sequence'); n

= 0:1:N-1;

subplot(2,2,3), stem(n, yc);

xlabel('n'), ylabel('yc(n)'); title('output

sequence (circular convolution)'); n =

0:1:Nx+Nh-2; subplot(2,2,4), stem(n,

y);

xlabel('n'), ylabel('y(n)');
title('output sequence (linear convolution)');

Output:
Experiment:8
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: Program to generate circular convolution using DFT and IDFT Apparatus

Required:MATLAB software

Code:

clc;
x = input('enter the

sequence'); n1= length(x); h =

input('enter the sequence');

n2 = length(h); c=max(n1,

n2); if(c>n1)

x=[x, zeroes(1, c-n1)];


End

if(c>n2)

h=[h, zeros(1,

c-n2)]; end
N = input('enter the N point

DFT'); x = fft(x);

H=
fft(h); Q
= X. *H;
q = ifft(Q);
disp('Required circular convolution using DFT and IDFT is ');q

Output:
Experiment:9
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: Program to generate linear convolution of two sequence x1(n) and x2(n) using DFT
and IDFT
Apparatus Required:MATLAB

software Code:

clc;

x = input('Enter the first sequence: '); n1

= length(x);

h = input('Enter the second sequence: '); n2

= length(h);

x = [x, zeros(1, n2 - 1)];

h = [h, zeros(1, n1 -
1)]; X = fft(x);

H=

fft(h); Q

= X .* H;
q =
ifft(Q);

Disp(‘q’);

q Output:
Experiment:10
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.

Aim: Program to generate sum of two sine wave

Apparatus Required:MATLAB software Code:

clc;
t = 0: .01:70;
x1=sin(2*pi*t/5)
;
x2=sin(2*pi*t/7)
; x3 =x1+x2; subplot(3,1,1),

plot(t, x1)

xlabel('t'), ylabel ('x1(t)')


subplot(3,1,2), plot(t, x2)
xlabel('t'), ylabel ('x2(t)')
subplot(3,1,3), plot(t,x3)
xlabel('t'), ylabel ('x3(t)= x1(t) + x2(t)')

title('Graph by Manikanta) Output:

You might also like