Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Quantization Problem...Help Please

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]

19 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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...?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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