Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20641 Discussions

Quantization Problem...Help Please

Altera_Forum
Honored Contributor II
3,220 Views

Hi i'm working on a 2 Channel QMF perfect reconstruction Filter bank using a tutorial in Matlab and i'm trying to implement the design on a Cyclone II FPGA board. after setting everything up i notice that i wasnt getting the expected results. so i decided to simulate it in Simulink. i notice that the filter is fine and works as expected, but when i changed the arithmetic to fixed point the filter started to behave differently, i'm not sure how to fix this problem. i have images and code Please help.[CODE]N = 99;

[H0,H1,G0,G1] = firpr2chfb(N,.45);

 

% Analysis filters (decimators).

Hlp = mfilt.firdecim(2,H0);

Hhp = mfilt.firdecim(2,H1);

 

% Synthesis filters (interpolators).

Glp = mfilt.firinterp(2,G0);

Ghp = mfilt.firinterp(2,G1);

 

Hlp.arithmetic = 'fixed';

Hlp.InputWordLength = 16;

Hlp.InputFracLength = 15;

Hlp.FilterInternals = 'FullPrecision'; 

%Hlp.OutputWordLength = 16;

%Hlp.OutputFracLength = 14;

Hlp.CoeffWordLength = 16;

Hlp.signed = true;

%Hlp.AccumWordLength = 20;

% Hlp.NumStateWordLength = 20;

% Hlp.DenStateWordLength = 20;

%Hlp.CastBeforeSum = false;

%Hlp.RoundMode = 'nearest';

%Hlp.OverflowMode = 'wrap';

 

%----------------------------------------------------------

 

Hhp.arithmetic = 'fixed';

Hhp.InputWordLength = 16;

Hhp.InputFracLength = 15;

Hhp.FilterInternals = 'FullPrecision';

%Hhp.OutputWordLength = 16;

Hhp.signed = true;

%Hhp.OutputFracLength = 14;

Hhp.CoeffWordLength = 16;

%Hhp.AccumWordLength = 20;

% Hhp.NumStateWordLength = 20;

% Hhp.DenStateWordLength = 20;

%Hhp.CastBeforeSum = false;

%Hhp.RoundMode = 'nearest';

%Hhp.OverflowMode = 'wrap';

 

%----------------------------------------------------------

 

Glp.arithmetic = 'fixed';

Glp.InputWordLength = 34;

Glp.InputFracLength = 33;

Glp.FilterInternals = 'FullPrecision';

%Glp.OutputWordLength = 32;

Glp.signed = true;

%Glp.OutputFracLength = 29;

Glp.CoeffWordLength = 16;

%Glp.AccumWordLength = 32;

% Glp.NumStateWordLength = 20;

% Glp.DenStateWordLength = 20;

% Glp.CastBeforeSum = false;

%Glp.RoundMode = 'nearest';

%Glp.OverflowMode = 'wrap';

 

%-----------------------------------------------------------

 

Ghp.arithmetic = 'fixed';

Ghp.InputWordLength = 34;

Ghp.InputFracLength = 33;

Ghp.FilterInternals = 'FullPrecision';

Ghp.signed = true;

%Ghp.OutputWordLength = 32;

%Ghp.OutputFracLength = 29;

Ghp.CoeffWordLength = 16;

%Ghp.AccumWordLength = 32;

% Ghp.NumStateWordLength = 20;

% Ghp.DenStateWordLength = 20;

% Ghp.CastBeforeSum = false;

%Ghp.RoundMode = 'nearest';

%Ghp.OverflowMode = 'wrap';

/CODE]

0 Kudos
19 Replies
Altera_Forum
Honored Contributor II
569 Views

Your post lacks essential info e.g. cutoff points of your filters and what actually you are trying to do with decimation/interpolation. Why did you choose this particular plan. Many of us never heard of QMF. If you help us clarify then we can help. 

 

Edit: your input is set to +/- 5 and is possibley causing saturation.make it +/- 1
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

for some reason..it wont let me post on my own post. 

 

well it uses a special function in matlab called firpr2chfb to create the filters. but the .45 is the passband edge, and the stopband edge is 1-.45. they use the coefficients from that design to design the interpolator and decimator. a QMF filterbank is merely suppose to reconstruct the signal u sent through it originally at it's output.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Did you try setting input to +/- 1 instead of 5

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Thank you very much it worked. i simply changed the amplitude now it perfectly reconstructs like the non-quantized example. 

 

really appreciate it Kaz.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Software engineers (our friendly makers of wonderful tools) regard 1 as a loose representation in digits. In fact you can represent 1 as any suitable roof value. but truncation is all that is important to match the meaning. For example if your multiplicand is meant to be .3 then you can use .3*1024 = 307 representation, multiply by input then truncate 10 bits off result.  

 

In your tool 1 means max hardware representation and 5 can't be understood by it !! in short the soft 1 = 2^n-1 hard 1
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Can you please explain that more clearly i didnt quite get it...i fixed the problem in the simulation but i'm not getting the same result in the implementation.

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

The scaling of your signaltap display is not there and so it is difficult to see what is going on.  

Can you post the signaltap results as digits and do you know what is your targetted fin value and how sure are you about its value. I mean if you fin is near cutoff of filter it will be attenuated.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

I thought the problem was that i wasnt using enough bits to represent the magnitude of the sinusoid i was using as my input so i redesigned the filter to use less bits as the fraction bits thinking it would work...but i pretty much got the same results. i'm stumped. here is the image of th input and output in hexidecimal. 

f_sin01 is the input, and out is the output. as u can see they are no where near each other.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

I can only see few figures in hex. Fin hits a minimum of 401h = 1025 and this is unexpected for an input of 16 bits signed for which dynamic range would be between 32767 & -32767 max.  

There are no figures for output. 

Remember you are looking at display and could be scaled in a way that depends on bitwidth. So you better check actual min/max of your signals before judging on the performance.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

No that is right i should have sent an updated version of my design. the Max and Min should 401h for the input, i'm using 11 bits not 16, but i get no where close for the output.

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

But 11 bits signed should have a dynamic range of +/- 1023 

Your Fin minumum value is + 1025 and maximum ? sounds like dc offset unless display or rep is not what I think
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

it does have a dynamic range of +/- 1025...The problem is it goes through the filters the magnitude of the output of those filters is astronomically larger than the input.

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Here i'll repost my entire Design specs again, i think i'm losing you. The QMF filter bank, simply reconstructs the original Signal you input, but putting it through a series of decimators and interpolators. so the input and output should be the same with the exception of a delay.  

N = 99; = firpr2chfb(N,.45); % Analysis filters (decimators). Hlp = mfilt.firdecim(2,H0); Hhp = mfilt.firdecim(2,H1); % Synthesis filters (interpolators). Glp = mfilt.firinterp(2,G0); Ghp = mfilt.firinterp(2,G1); Hlp.arithmetic = 'fixed'; Hlp.InputWordLength = 11; Hlp.InputFracLength = 0; Hlp.FilterInternals = 'FullPrecision'; Hlp.CoeffWordLength = 10; Hlp.signed = true; Hhp.arithmetic = 'fixed'; Hhp.InputWordLength = 11; Hhp.InputFracLength = 0; Hhp.FilterInternals = 'FullPrecision'; Hhp.CoeffWordLength = 10; Hhp.signed = true; Glp.arithmetic = 'fixed'; Glp.InputWordLength = 22; Glp.InputFracLength = 0; Glp.FilterInternals = 'FullPrecision'; Glp.signed = true; Glp.CoeffWordLength = 10; Ghp.arithmetic = 'fixed'; Ghp.InputWordLength = 22; Ghp.InputFracLength = 0; Ghp.FilterInternals = 'FullPrecision'; Ghp.signed = true; Ghp.CoeffWordLength = 10; I've tried changing the input wordlength and and fraction bits, but nothing seems to help, and i'm getting no where close to expected output. Is this more helpful...?
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

if your input is 11 bits and output is 34 bits then you have allowed full bit growth to appear out and so will appear scaled up a lot. At the output you need to truncate off some LSBs and possibly discard some MSbs plus saturation. The number of LSBs to be discarded depends on how you scale your coeffs (decimal point) so discard as many as decimal point. I assume your tool is supposed to do that because you define 'nearest' etc. but your output size should be 11 bits if you want to compare input with output

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

I should say you discard as many LSBs as decimal point location plus effect of summing up all coeffs. This is a bit tricky but your tool should do that.

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

i've tried doing that originally, by restricting the output to only 11 bits, but when i do that the simulations show no results...do you know how i can do that. the tool i'm using is matlab 2010ra.

0 Kudos
Altera_Forum
Honored Contributor II
569 Views

I am sorry I don't use that particular tool for design automation. It is at the end matter of play and see. 

 

It might help however to describe your problem as I am lost really. 

I mean describe it on your own words rather than tool reports: what is the input range of Fin, output range you get, output range you expect, bitwidths and coeff values ...etc.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

The specific problem is i dont know why im not getting the output to be the same as the input, when the simulation shows that it should be...ive taken some of the things you've said into consideration like the bit growth of the filters, but i dont get why it cant represent an 11 bit magnitude as a 34 bit magnitude. also i'm not sure if the word length of the coefficients affect this bit growth. 

 

The input Range should be the highest signed 11 bit number which is +-1025, and the output range should be the same. theres a high pass decimator and low pass decimator, with a 10 bits to represent their coefficients. same for the interpolators. the decimators and interpolators are halfband filters.
0 Kudos
Altera_Forum
Honored Contributor II
569 Views

Firstly, 11 bits signed has a range of +1023 -1024 and in your case +/- 1023 (not 1025 at all). 

secondly if your output is 33 bits or so then its range is very high. You don't expect +/- 1023 on 33 bits ! all you need could be just truncation of output to match input provided your filter has correct gain
0 Kudos
Reply