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.

How to implement 12 bit fixed point representation in Matlab

Status
Not open for further replies.

scdoro

Member level 5
Member level 5
Joined
Jan 12, 2005
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,040
matlab fi function fix points

hi all,

i have a question here and i am done with the first part on designing the bandpass filter by writing a matlab script below.

_________________________________________
% M file for bandpass FIR filter
ws1=0.3*pi
wp1=0.4*pi;
wp2=0.5*pi;
ws2=0.6*pi;
tr_width=min((wp1-ws1),(ws2-wp2));
M=ceil(6.6*pi/tr_width)+1
n=[0:1:M-1];
wc1=(ws1+wp1)/2;
wc2=(wp2+ws2)/2;
hd=ideal_lp(wc2,M)-ideal_lp(wc1,M);
w_ham=(hamming(M))';
h=hd.*w_ham;
[db,mag,pha,grd,w]= freqz_m(h,[1]);
delta_w=2*pi/1000;
Rp=-min(db(wp1/delta_w+1:1:wp2/delta_w)) % Actual passband ripple
As=-round(max(db(ws2/delta_w+1:1:501))) % Min stopband attenuation

%Plots
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([0 M-1 -0.4 0.5]; xlabel('n'); ylabel('hd(n)')
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_ham); title ('Hamming Window')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h); title('Actual Impulse response')
axis([0 M-1 -0.4 0.5]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4); plot(w/pi,db); axis([0 1 -150 10]);
title('Magnitude Response in dB'); grid;
xlabel('frequency in pi units'); ylabel('Decibels')
____________________________________________________


I am stuck in trying to proceed with the second part.

Qn1) how do i proceed with the 2nd part on determining the 12 bit fixed point representations of filter coefficients.

Qn2) and how do i plot the magnitude response of the fixed point filter in Matlab?

Please assist.

thanks

regards
scdoro
 

Hi scdoro,

if you have an access to fixed-point toolbox of matlab. Then you can use fi() function for input signal, output signal, and coefficients of the filter. With fi() function you may also define how many fixed-point you need for the problem and how the rounding should take place.

best
 

Re: How to implement 12 bit fixed point representation in Ma

Okie. thanks for the guide.

I think it helps me to learn about the filter design toolbox.i plot the fixed point filter and the original filter on the same magnitude response graph and i got this result in the attachment. It seems that they are very similar to each other..except for some distortion in the fixed point filter.

What does this imply about the results? Is that supposed to be the correct output?

thanks
 

Hi,

from your figure it seems that the filter implementation using 12-bit fixed point number is not that different than that of floating-point number. I didn't check it myself so i can't justify whether your result is correct or not.

Just try playing around with fixed-point number, i.e. decreasing the fixed-point number and the result should get worst.

best
 

Re: How to implement 12 bit fixed point representation in Ma

I have a Matlab script that generates a ROM to use it in a vhdl project. It just generates a fir filter, with fir1 function, and then the coefficients are binarized and a ROM file is created. It might help you to understand how binarization is done.
You cand several parameters, like filter order, number of bits to represent the coefficients, etc. Almost all comments are in Spanish, since I am from Mexico, but I changed some of them to English so you can use it.
This script generates a file called ROM_FIR.vhd, which is the vhdl description of the ROM coefficients. If you don't have a vhdl editor you still can open it in Matlab editor or in any other Text Editor.
Regards,

Ulises
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top