Code covered by the BSD License

# EC1302 DSP Lab

### Salai Selvam V (view profile)

These are matlab code for experiments in the course EC1302 DSP Lab.

h=firwin(A,wc,N,wf,ft)
```function h=firwin(A,wc,N,wf,ft)

format short g;

if (nargin<3)
error('Insufficient no. of input arguments');
else
end

if (length(wc)==2)
if (wc(1)<wc(2))
wc1=wc(1);
wc2=wc(2);
else
wc1=wc(2);
wc2=wc(1);
end
ft='bpf';
else
end

if (nargin==3)
wf='hm';
ft='lpf';
elseif (nargin==4)
ft='lpf';
end
tau=(N-1)/2;

switch ft
case 'lpf'
for n=0:(N-1)
if (n~=tau)
hd(n+1)=((A/pi)*sin(wc*(n-tau)))/(n-tau);
elseif (n==tau)
hd(n+1)=(A/pi)*wc;
end
end
case 'hpf'
for n=0:(N-1)
if (n~=tau)
hd(n+1)=((A/pi)*(sin(pi*(n-tau))-sin(wc*(n-tau))))/(n-tau);
elseif (n==tau)
hd(n+1)=(A/pi)*(pi-wc);
end
end
case 'bpf'
for n=0:(N-1)
if (n~=tau)
hd(n+1)=((A/pi)*(sin(wc2*(n-tau))-sin(wc1*(n-tau))))/(n-tau);
elseif (n==tau)
hd(n+1)=(A/pi)*(wc2-wc1);
end
end
case 'bef'
for n=0:(N-1)
if (n~=tau)
hd(n+1)=((A/pi)*(sin(wc2*(n-tau))-sin(wc1*(n-tau))+ sin(pi*(n-tau))))/(n-tau);
elseif (n==tau)
hd(n+1)=(A/pi)*(wc2-wc1+pi);
end
end
otherwise
for n=0:(N-1)
if (n~=tau)
hd(n+1)=((A/pi)*sin(wc*(n-tau)))/(n-tau);
elseif (n==tau)
hd(n+1)=(A/pi)*wc;
end
end
end

switch wf
case 'r'
for n=0:(N-1)
w(n+1)=1;
end
case 'hm'
for n=0:(N-1)
w(n+1)=0.54-0.46*cos((2*pi*n)/(N-1));
end
case 'hn'
for n=0:(N-1)
w(n+1)=0.5-0.5*cos((2*pi*n)/(N-1));
end
case 'b'
for n=0:(N-1)
w(n+1)=0.42-0.5*cos((2*pi*n)/(N-1))+0.08*cos((4*pi*n)/(N-1));
end
case 'k'
w=kaiser(N,0.01);
otherwise
for n=0:(N-1)
w(n+1)=0.54-0.46*cos((2*pi*n)/(N-1));
end
end

if (rem(N,2)==0)
for n=0:(N/2-1)
h(n+1)=hd(n+1)*w(n+1);
h(N-1-n+1)=hd(n+1)*w(n+1);
end
elseif (rem(N,2)~=0)
for n=0:((N-1)/2)
h(n+1)=hd(n+1)*w(n+1);
h(N-1-n+1)=hd(n+1)*w(n+1);
end
```