fir.pdf

1
clear %%Usual Declarations Below (from question) N=7 wc=0.2*pi alpha=(N-1)/2 %%New thing here, this is called in-line functions. These are normal %%functions like we save in the file but run inside the actual code %%The actual function goes like this %%function y=hdn(n) %%y=(sin(wc*(n-alpha)))/(pi*(n-alpha)) %%end %%Instead of this, lazy people do the below. This will be really useful in %%the upcoming semesters. Here I used this just to eradicate for loops. hdn=@(n) (sin(wc*(n-alpha)))/(pi*(n-alpha)) wnham=@(n) 0.54-(0.46*(cos((2*pi*n)/(N-1)))) wnrec=1 for i=0:N-1 hnrec(i+1)=hdn(i)*wnrec hnham(i+1)=hdn(i)*wnham(i) end %%I've added a manual replacement for places where n=alpha hnrec(alpha+1)=wc*(2*pi) hnham(alpha+1)=wc*(2*pi) %%Declaring a -pi to pi as in the for loop you cannot specify such limits w=-pi:0.01:pi yrec=zeros(1,length(w)) yham=zeros(1,length(w)) %%Have used DTFT, I don't remember the other formula, if you remember, send %%it and I'll make a code from it. for i=1:length(w) for k=1:N yrec(i)=yrec(i)+(hnrec(k)*exp(-1j*w(i)*(k-1))); yham(i)=yham(i)+(hnham(k)*exp(-1j*w(i)*(k-1))); end end

Upload: kesava-prasad-arul

Post on 10-Jul-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FIR.pdf

clear %%Usual Declarations Below (from question) N=7 wc=0.2*pi alpha=(N-1)/2 %%New thing here, this is called in-line functions. These are normal %%functions like we save in the file but run inside the actual code %%The actual function goes like this %%function y=hdn(n) %%y=(sin(wc*(n-alpha)))/(pi*(n-alpha)) %%end %%Instead of this, lazy people do the below. This will be really useful in %%the upcoming semesters. Here I used this just to eradicate for loops. hdn=@(n) (sin(wc*(n-alpha)))/(pi*(n-alpha)) wnham=@(n) 0.54-(0.46*(cos((2*pi*n)/(N-1)))) wnrec=1 for i=0:N-1 hnrec(i+1)=hdn(i)*wnrec hnham(i+1)=hdn(i)*wnham(i) end %%I've added a manual replacement for places where n=alpha hnrec(alpha+1)=wc*(2*pi) hnham(alpha+1)=wc*(2*pi) %%Declaring a -pi to pi as in the for loop you cannot specify such limits w=-pi:0.01:pi yrec=zeros(1,length(w)) yham=zeros(1,length(w)) %%Have used DTFT, I don't remember the other formula, if you remember, send %%it and I'll make a code from it. for i=1:length(w) for k=1:N yrec(i)=yrec(i)+(hnrec(k)*exp(-1j*w(i)*(k-1))); yham(i)=yham(i)+(hnham(k)*exp(-1j*w(i)*(k-1))); end end