Continue to Site

# [SOLVED]FIR FIlter Design on FPGA

Status
Not open for further replies.

#### keyboardcowboy

##### Member level 2
I am designing a 9-Tap FIR filter, I have used MATLAB to get the filter coefficients

Code:
 -0.0041    0.0077    0.0893    0.2433    0.3276    0.2433    0.0893    0.0077   -0.0041

I have multiplied all the coefficients with a scaling factor to scale them to 16bits. The input to the filter are random 200 values generated by a custom MATLAB code

Code:
function y4 = sampdata(xlen)

ntaps = 65;  % Design filter to make the data band limited.
f = [0.0 0.9 0.95 1.0];
mag = [ 1.0 1.0 0.7071 0.0];
b = fir2(ntaps, f, mag);
a = 1.0;

t = linspace(0,1,floor(xlen/2));
y1 = 5*square(2*pi*2*t);
y2 = filter(b, a, y1);
x = zeros(1,ceil(xlen/2));

for k=1:ceil(xlen/2)
m = (k-1);
t1 = 5*cos(0.1*pi*m + 0.5*pi);
t2 = 2*cos(0.75*pi*m + 0.5*pi);
t3 = 1*cos(0.92*pi*m + 0.5*pi);
x(k) = t1 + t2 + t3;
end

win = transpose(hanning(ceil(xlen/2)));
y3 = win.*x;

y4 = [y2 y3];
return

The maximum value of the sample data is 6.3445 and the minimum value is -7.5099. I am trying to figure out if I should scale the coefficients and the input data using the same scaling factor or should I use separate scaling factor for each. If I should scale both using the same scaling factor then how can I calculate that factor?

The scaling factor can be different for each. You need to ensure there are enough integer bits and fraction bits to represent the numbers correctly.

From the coefficients you posted, you need 0 integer bits and can probably drop the 2^-1 bit. So you can scale by 2^17.

keyboardcowboy

Points: 2