Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Frequency/Magnitude response of lowpass FIR filter

Status
Not open for further replies.

Naveed Ahmed

Member level 4
Joined
Aug 31, 2008
Messages
77
Helped
9
Reputation
18
Reaction score
9
Trophy points
1,288
Location
Singapore
Activity points
1,862
Hi,

I have written a test program in matlab for lowpass fir, when i m plotting its magnitude response after fft, it seems to be a high pass filter. Why its doing so??
My code is as follow:

N=50; %Filter order
Length=N+1; %length
n0=N/2; %delay parameter
n=0:1:N;
fc_l=1/8; %Cut off frequency for the low pass filter
Wc_l=2*pi*fc_l;
%===================LOWPASS FIR FILTER=====
h_lp=sin(Wc_l*(n-n0)) ./(pi*(n-n0)); %Impulse response of Low Pass FIR filter For n-n0!=0
h_lp(n0+1)=(Wc_l/pi) %Imp response of Low Pass FIR filter For n=n0 or n-n=0
F=fft(h_lp,51);
X=real(F);
Y=imag(F);
[th,Mag]=cart2pol(X,Y);
plot(0:50,Mag)

Thnks,

ur comments plz

naveed
 

Hi,

if you do this
f=(0:50)/50
plot(f,Mag)

your plot will be normalized and you see the relevant part which is 0 to 0.5
the part higher than 0.5 is the negative spectrum (0.5 is the nyquist frequency)
your filter is correct.
best regards

---------- Post added at 09:21 ---------- Previous post was at 08:53 ----------

Hi Naveed,
here is a slight modification that will show the spectrum of your filter

N=50; %Filter order
Length=N+1; %length
n0=N/2; %delay parameter
n=0:1:N;
fc_l=1/8; %Cut off frequency for the low pass filter
Wc_l=2*pi*fc_l;
%===================LOWPASS FIR FILTER=====
h_lp=sin(Wc_l*(n-n0)) ./(pi*(n-n0)); %Impulse response of Low Pass FIR filter For n-n0!=0
h_lp(n0+1)=(Wc_l/pi) %Imp response of Low Pass FIR filter For n=n0 or n-n=0

F=fft(h_lp,1024); %% 1024 higher frequency resolution
F=fftshift(F); % moving the zero-frequency component to the center
% X=real(F);
% Y=imag(F);
% [th,Mag]=cart2pol(X,Y);
% plot(0:1023,Mag)
f=(-512:511)/1024 % Normalised Frequency vector (-0.5 to +0.5)
plot(f,abs(F))
 

Thanks chahid,

Its showing now, there is another method aswell, we can use the builtin freqz command... freqz(h_lp)
But it shows us in normalized frequency mode, we need to convert that. Whats the conversion relation between normalized freq to hz??

Thx
 

Hi Ahmed,


In normalized spectrum means sampling frequency = 1 you have just to multiply by
the sampling frequency to get it in hz. or use directly
freqz(h_lp,1,1024,Fs) Fs is sampling frequency if you put Fs=1000 hz you get
the cut frequency = fc_l * Fs
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top