Académique Documents
Professionnel Documents
Culture Documents
2.a.Convolution
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=conv2(x,h);
subplot(3,1,1);
stem(x);
ylabel('amplitude');
xlabel('(a)n');
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('(b)n');
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('(c)n');
disp(y)
Result:
enter the 1st sequence[3 4 5 6]
enter the 2nd sequence[3 4 5 6]
9 24 46 76 73 60 36
2.b.CIRCULAR CONVOLUTION
x1=input('enter the seq1')
x2=input('enter the seq2')
l1=length(x1)
l2=length(x2)
n1=0:1:l1-1
subplot(3,1,1)
stem(n1,x1)
xlabel('time index')
ylabel('amplitude')
title('first sequence')
n2=0:1:12-1
subplot(3,1,2)
%stem(n2,x2)
xlabel('time index')
ylabel('amplitude')
title('second sequence')
N=max(l1,l2)
y=conv2(x1,x2,N)
N=max(l1,l2)
n3=0:1:N-1
subplot(3,1,3)
stem(n3,y)
xlabel('time index')
ylabel('amplitude')
title('circular convolution')
CIRCULAR CONVOLUTION FUNCTION FILE
function[y]=conv2(x1,x2,N)
l1=length(x1)
l2=length(x2)
N=max(l1,l2)
if(N<max(l1,l2))
error('N must be >=max(l1,l2)')
end
x1=[x1,zeros(1,N-l1)]
x2=[x2,zeros(1,N-l2)]
%circular shift of sequence 2
m=[0:1:N-1]
M=mod(-m,N)
x2=x2(M+1)
H=zeros(N,N)
for n=1:1:N
m=n-1
p=0:1:N-1
q=mod(p-m,N)
xm=x2(q+1)
H(n,:)=xm
end
%matrix convolution
y=x1*H'
OUTPUT RESULT
enter the seq1[1 2 2 1]
x1 =
1 2 2 1
enter the seq2[1 2 2 1]
x2 =
1 2 2 1
l1 =
4
l2 =
4
n1 =
0 1 2 3
n2 =
Columns 1 through 10
0 1 2 3 4 5 6 7 8 9
Columns 11 through 12
10 11
N =
4
y =
4 8 8 4
8 16 16 8
8 16 16 8
4 8 8 4
N =
4
n3 =
0 1 2 3
3.CROSS CORRELATION
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=xcorr(x,h);
subplot(3,1,1);
stem(x);
ylabel('amplitude');
xlabel('(a)n');
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('(b)n');
subplot(3,1,3);
stem(fliplr(y));
ylabel('amplitude');
xlabel('(c)n');
disp('The resultant is');y
Result:
enter the 1st sequence[3 4 5 6]
enter the 2nd sequence[3 4 5 6]
The resultant is
4.Frequency response of a given system
b=[1 , .9];
a=[1 ,.4];
w=0:.01:pi;
[h]=freqz(b,a,w);
subplot(2,1,1);
plot(w/pi,abs(h));xlabel('freq');ylabel('mag');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('freq');ylabel('phase');
5.a.FFT
x=input('enter the sequence');
n=input('enter the length of fft');
y=fft(x,n);
stem(y);axis([-5 30 -10 10]);ylabel('imaginery axis-->');
xlabel('real axis-->');
Result:
enter the sequence[2 3 4 5 6]
enter the length of fft8
RESULT
enter the denominator coeffcients of the filter[1 -1 5]
"stable system"
6.a. PROGRAM FOR DECIMATE FUNCTION
t=0:0.03:2;
x=cos(4*pi*t);
y=decimate(x,2);
t1=decimate(t,2);
subplot(2,1,1);
stem(t,x,'fill');
title('undecimated plot');
subplot(2,1,2);
stem(t1,y,'fill');
title('Decimated plot');
RESULT:
RESULT
enter the passband ripple0.2
enter the stopband ripple40
enter the passbond frequency2000
enter the stopbond frequency3500
enter the sampling frequency8000
RESULT
enter the passband ripple0.36
enter the stopband ripple36
enter the passbond frequency1500
enter the stopbond frequency2000
enter the sampling frequency6000
RESULT
enter the pass band ripple0.02
enter the stop band ripple0.01
enter the pass freq1200
enter the stop freq1700
enter the sampling freq9000