Tuesday 4 March 2014

FIR Low Pass Filter using Kaiser Window

Program:

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=kaiser(n1);
b=fir1(n,wp,y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

Output:

enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05



FIR Filter HIgh Pass using Kaiser Window

Program:

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=kaiser(n1);
b=fir1(n,wp,'high',y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

Output:
enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05


FIR Filter High Pass FIlter Triangular Window

clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=triang(n1);
b=fir1(n,wp,'high',y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

OUTPUT:
enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.04
enter stopband ripple0.05


FIR filter with Triangular Window Low Pass

PROGRAM:
clc;
clear all;
close all;
fp=input('enter passband frequency');
fs=input('enter stopband frequency');
f=input('enter sampling frequency');
rp=input('enter passband ripple');
rs=input('enter stopband ripple');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13.0;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
%to make order of filter even
if(rem(n,2)~=0)
 n1=n;
 n=n-1;
end
y=triang(n1);
b=fir1(n,wp,y);
[h,w]=freqz(b,1,256);
mag=20*log10(abs(h));
ang=angle(h);
subplot(2,1,1);
plot(w/pi,mag);
xlabel('normalised freq');
ylabel('gain(in db)');
subplot(2,1,2);
plot(w/pi,ang);
title('phase response');
xlabel('normalised frequency');
ylabel('phase angle');

OUTPUT:

enter passband frequency1500
enter stopband frequency2000
enter sampling frequency9000
enter passband ripple0.05
enter stopband ripple0.04



Thursday 19 December 2013

Addition and Multiplication of Two Sequences

close all;
clear all;
clc;
x=input('enter sequence -1');
y=input('enter input sequence-2');
M=length(x);
N=length(y);
subplot(2,2,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title('input sequence-1');
subplot(2,2,2);
stem(y);
xlabel('time');
ylabel('amplitude');
title('input sequence-2');
if M>N
z=x+[y,zeros(1,M-N)];
a=x.*[y,zeros(1,M-N)];
else
z=[x,zeros(1,N-M)]+y;
a=[x,zeros(1,N-M)].*y;
end;
subplot(2,2,3);
stem(z);
xlabel('time');
ylabel('amplitude');
title(' Addition of input sequences");
subplot(2,2,4);
stem(a);
xlabel('time');
ylabel('amplitude');
title('multiplication of input sequences ');

Output:
 sequence -1[1 4 8 6]
enter input sequence-2[1 6 8 9]



Sinc funtion and Triangular function

close all;
clear all;
clc;
t=-4:0.1:4;
x=sinc(pi*t);
subplot(2,1,1);
plot(x);
xlabel('time');
ylabel('amplitude');
title('sinc function');
y=0:0.5:2;
for j=0:3
x=(4*j)+y;
subplot(2,1,2);
plot(x,y);
hold on;
end;
for k=0:3
x=(4*k)-y;
subplot(2,1,2);
plot(x,y);
hold on;
end;
hold off;

Output:

Program for Impulse Function and Step function Generation

close all;
clear all;
clc;
n=[-5:5];
i=imp_scr(0,-5,5);
subplot(2,1,1);
stem(n,i);
xlabel('time');
ylabel('amplitude');
title('impulse function');
s=step_scr(0,-5,5);
subplot(2,1,2);
plot(n,s);
xlabel('time');
yalbel('amplitude');
title('step sequence');
%user defined functons

%for imp_scr
function[x,n]=imp_scr(no,n1,n2);
n=[n1:n2];
x=[(n-n0)==0];

%for step_scr
function[x,n]=step_scr[n0,n1,n2];
n=[n1:n2];
x=[(n-n0)>=0];


Note: the user has to type the user defined functions in a new window and save them with the exact same names of imp_scr and step_scr if the user defined functions are to work
The files are to be saved in the same directory as the original file.