DSP Notes
DSP Notes
m=input('');
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;
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
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;
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
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
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)
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')
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),
ylabel('x(n)'); title('input
sequence'); n =
0:1:Nh-1;
title('impulse sequence'); n
= 0:1:N-1;
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
n2 = length(h); c=max(n1,
n2); if(c>n1)
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;
= length(x);
= length(h);
h = [h, zeros(1, n1 -
1)]; X = fft(x);
H=
fft(h); Q
= X .* H;
q =
ifft(Q);
Disp(‘q’);
q Output:
Experiment:10
.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.
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)