Beruflich Dokumente
Kultur Dokumente
%SAMPLING THEOREM
clc;
close all;
clear all;
f=input('Enter the input signal frequency, f=');
t=0:0.001:0.1;
x=cos(2*pi*f*t);
fs=input('Enter the sampling frequency fs>>f,fs=');
ts=1/fs;
tn=0:ts:0.1;
x1=cos(2*pi*f*tn);
subplot(3,1,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Input signal');
subplot(3,1,2);
stem(tn,x1);
xlabel('Time');
ylabel('Amplitude');
title('Sampled output');
subplot(3,1,3);
plot(tn,x1);
xlabel('Time');
ylabel('Amplitude');
title('From sampled data-Reconstructed wave form');
Page 1
programs
Page 2
programs
Page 3
programs
Page 4
programs
E11
clc;
close all;
clear all;
x1=input('Enter the first sequence x1(n) to be convoluted =:');
x2=input('Enter the second sequence x2(n) to be convoluted =:');
subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence,x1(n)');
subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence,x2(n)');
L1=length(x1);
L2=length(x2);
if L1>L2
L=L1-L2;
x1=[x1,zeros(1,L)];
elseif L2>L1
L=L2-L1;
x1=[x1,zeros(1,L)];
end
N=max(L1,L2);
for k=0:N-1
sum=0;
for j=0:N-1
sum=sum+x1(j+1)*x2(mod(k-j,N)+1);
end
Y1(k+1)=sum;
end
disp('Circular convolution by expression');
disp(Y1);
subplot(3,1,3);
stem(Y1);
xlabel('Time');
ylabel('Amplitude');
title('The Circular convoluted sequence,Y(n)=x1(n)*x2(n)');
Y2=cconv(x1,x2,N);
disp('The Circular convolution sequence by using cconv(),is');
disp(Y2);
Page 5
programs
E12
clc;
close all;
clear all;
a=input('Enter the first input sequence,a=');
b=input('Enter the second input sequence,b=');
N=max(length (a), length (b));
A=fft(a,N);
B=fft(b,N);
C=A.*B;
x=ifft(C,N);
disp('The circular convolved output,x is');
disp(x);
r=0: length (x)-1;
subplot(2,1,1);
figure (1)
stem(r,x);
xlabel ('Number of samples');
ylabel('Amplitude');
title('Circular convolution by DFT & IDFT method');
subplot(2,1,2);
L1=length(a);
L2=length(b);
N1=L1+L2-1;
A=fft(a,N1);
B=fft(b,N1);
C=A.*B;
y=ifft(C,N1);
disp('The linear convolution is');
disp(y);
r=0: length (y)-1;
stem(r,y);
xlabel ('Number of samples');
ylabel('Amplitude');
title('Linear convolution by DFT & IDFT method');
Page 6
programs
figure(2)
L1=length(a);
L2=length(b);
N1=L1+L2-1;
A=fft(a,N1);
B=fft(b,N1);
C=A.*B;
y=ifft(C,N1);
disp('The linear convolution is');
disp(y);
r=0: length (y)-1;
stem(r,y);
xlabel ('Number of samples');
ylabel('Amplitude');
title('Linear convolution by DFT & IDFT method');
Page 7
programs
E14
clc;
close all;
clear all;
disp('Enter the input sequence x(n): as x=[1 2 3 4....]');
xn=input('enter the input sequence x(n):');
N=length(xn);
Xk=zeros(1,N);
for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+(xn(n+1))*exp((-i)*2*pi*k*n/N);
end
end
t=0:N-1;
subplot(3,1,1);
stem(t,xn);
ylabel('Amplitude , |x|');
xlabel('Time index , n');
title('Input sequence,x(n)');
magnitude=abs(Xk);
disp('The magnitude response of X(k):');
disp(magnitude);
t=0:N-1;
subplot(3,1,2);
stem(t,magnitude);
ylabel('Amplitude , |X(k)|');
xlabel('Sample no: ,k');
title(' Magnitude sequence of X(k)');
phase=angle(Xk);
disp('The phase response of X(k):');
disp(phase);
t=0:N-1;
subplot(3,1,3);
stem(t,phase);
ylabel('Phase');
xlabel('Sample no: ,k');
title(' Phase response of X(k)');
Page 8
programs
E15
clc;
close all;
clear all;
disp('Enter the input sequence x(n): as x=[1 2 3 4....]');
xn=input('enter the input sequence x(n):');
N=length(xn);
Xk=zeros(1,N);
n=0:N-1;
disp(' ');
disp('--------The DFT,X(k)={......} is ---------');
Xk=fft(xn);
disp(Xk);
disp('The IDFT of the sequence,X(k) is ,y(n)={.....}');
y=ifft(Xk);
disp(y);
subplot(3,2,1);
stem(n,xn);
title('Input Sequence,x(n)');
% subplot(3,2,2);
% stem(n,Xk);
% title('Input Sequence in, X(k)');
subplot(3,2,3);
stem(n,abs(Xk));
title('Magnitude spectrum of DFT, |X(k)|');
subplot(3,2,4);
stem(n,angle(Xk));
title('Phase spectrum of DFT, |X(k)|,arg(k)');
subplot(3,2,5);
stem(n,y);
title('y(n)= IDFT of X(k)');
Page 9
programs
E16
Page 10
programs
E17
Page 11
programs
E18
% BILINEAR TRANSFORMATION
clc;
close all;
clear all;
T=1;
wp=0.5*pi;
ws=0.75*pi;
rp=0.707;
rs=0.2;
Rp=-20*log10(rp);
Rs=-20*log10(rs);
Wp=(2/T)*tan(wp/2);
Ws=(2/T)*tan(ws/2);
[N wn]=buttord(Wp,Ws,Rp,Rs,'s');
[b,a]=butter(N,wn,'s');
disp('The analog transfer function, H(s) is given by:')
printsys(b,a);
disp(' ');
[B,A]=bilinear(b,a,1/T);
disp('**************************************************************');
disp(' ');
disp('The digital transfer function, H(s) is given by:')
printsys(B,A,'z');
[H,w]=freqz(B,A);
figure;
subplot(2,1,1);
plot(w,20*log(abs(H)));
grid;
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of filter using Bilinear Transformation method');
subplot(2,1,2);
plot(w,angle(H));
grid;
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of filter using Bilinear Transformation method');
Page 12
programs
E19
Page 13
programs
E20