This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IIR and FIR filter library questions

Other Parts Discussed in Thread: CONTROLSUITE

I am using the F28335 chip. I looked for iir and fir filters and found some for the C2000 but they are written for integer math. My questions are:

1) Is there a library for the C2000 chips with floating point support?

2) If not and I need to use the integer versions, for iir32, do I need to scale the input to Q15 (ie x 32768) before feeding it to the filter function?

3) Why isn't there a 32 bit version of the FIR? Or is there?

Thanks

  • MaxPower said:

    I am using the F28335 chip. I looked for iir and fir filters and found some for the C2000 but they are written for integer math. My questions are:

    1) Is there a library for the C2000 chips with floating point support?

    Maxpower,

    Floating-point filters is definitely on our list of to-dos for early next year.  In the meantime I have some preliminary filter functions that I am willing to share - they just haven't been packaged/documented/etc.  I will post them tomorrow when I'm back in the office.

    -Lori

     

  • Thanks. I look forward to checking them out.

  • Max - my apologies I just realized I forgot to respond back before leaving the office.   I still have this on my to-do.

    -Lori

  • Max,

    I found a copy of the FIR but I think its not the latest.  I want to check with a co-worker first.

    Regards

    Lori

  • Lori,

       Thanks for the great communication. I am not in a hurry at the moment. I am running the integer version, FIR16, and it seems to work. It is very quick in execution. I was concerened about the integer math because when I used the iir16 I had resolution issues.

    I am going to be away from my project next week so the earliest I can try anything is a week from now.

    Thanks and best regards,

    Max

  • -Max,

    There is a fixed-point version of filter library available downloaded from

    http://focus.ti.com/docs/toolsw/folders/print/sprc082.html

    This is a very old lib and I tested the fir and iir 16 bit version. both of them are work. But the document has some problem.

     This lib has 16 bit FIR and 16/32 bit IIR. At this moment, there is not 32 bit fixed point FIR in this library.

    For IIR version, you not only needs scale to Q15 but also needs some scaling factor. This lib can not work independently from

    matlab.

    We are gonna release a updated version of this lib soon. So you would be able to get something easier to use for sure. :)

     -Yu Cai

  • Thank you.

     

    That is the library I am using now and it does seem to work. At least the FIR16 does. I had some resolution issues with the iir16. I look forward to the updated filer libraries.

     

    Kidn regards,

    Max

  • -Max,

    The IIR 16 version also works, but eziir_matlab has some mistakes. If you follow that document step by step, it's kinda confusing. The output *.dat file is correct though.

    I am currently testing IIR 32 version, i believe it would work as well.  I will keep you posted and if anything else resources which potentially be helpful to you, please let me know. 

    Thanks

    Yu Cai 

  • -Max

    I tested fixed point IIR 32 bit version. It has a bug in the old lib. Please be careful when you tried to use that. I will put a fixed one in the update release.

    Thanks

    -Yu Cai

  • Yu Cai

        Thank you for the heads up. Let me know when the update is available.

     

    Max

  • Lori,

        Do you have a floating point version of the IIR fitler available yet for me to try?

    Thanks

    Max

  • Max,

    I currently have FIR and IIR working version in both 16 and 32 bit. Now I am documenting them.  We don't have floating point version of optimized IIR filter library at this time. If you really want to implement it in floating point. You can use C to do that.

    -Yu Cai

  • Yu Cai,

        I can work with the integer versions but Lori (above) mentioned there were floating point versions being worked on and that I might be able to get ahold of some code to try out.

    I look forwared to getting the latest integer versions to try in the meantime.

    Thanks

    Max

  • MaxPower said:

    Lori,

        Do you have a floating point version of the IIR fitler available yet for me to try?

    Thanks

    Max

    Hi Max,

    Unfortunately Yu Cai is correct.  What I found was an FIR tucked away but I was not able to find the IIR.  I apologize for that.  At the moment Yu Cai is finishing up some fixed point cleanup but will be working on the float soon.

    I hope what you have at this time will work for you until then.

    -Lori

     

  • Yu Cai,

        While I am waiting for an updated iir32, I am trying to get iir16 to work. All my math is in floating point on the F28335. The output from the iir16 matlab script is:

    #define IIR16_COEFF {\
       0,5716,0,89,89,\
       -5781,13114,9879,19759,9879}

    #define IIR16_ISF 2476
    #define IIR16_NBIQ 2
    #define IIR16_QFMAT 13

    I call the initialize function as in the examples given.

     

    This is the code I use to convert my floating point number to an integer in Q15 format and then convert from a Q14.

        iir.input = (int)floor((speed_control.Out * 32768.0));          // Scale to Q15 format
        iir.calc(&iir);
        angle->omega_m = (float)iir.output / 16384.0;                    // 2^14 which is the output format

    According to the iir16 asm source, the output is in Q14 format so I have to divide to convert it back to floating point

    Is this correct?

     

    I am not getting the desired results so I am wondering what I am doing wrong.

    Thanks

  • Have you verify the output before you call iir16? I am not sure the version that you are running is good since I updated something from the legacy code and I remember there is something wrong in the document and code itself.

     What i recommend you to do is running a matlab scripts to see the result and compare the result with the data output with you CCS project output. Otherwise you won't know if it's due to your code problem or algorithm problem.

    MAX_TAPS=5;

    RadStep = 0.1963495408494; 

    N=input('Please enter signal length N =');

    halfSize=N-1;

    Rad=[0:RadStep:(halfSize)*RadStep];

    CFFTinBuf1=zeros(1,N);

    Rx=sin(Rad)+cos(Rad*2.3567);

    Ix=0*(cos(Rad*8.345) + sin(Rad*5.789));

    x=Rx+j*Ix;

    x_raw_sig=x/2;

    x_Q15=2^15*x/2;

    B=[ 0.000176614401432267

    0.00123630081002587

    0.00370890243007761

    0.00618150405012935

    0.00618150405012935

    0.00370890243007761

    0.00123630081002587

    0.000176614401432267];

    A=[ 1

    -3.84708594662977

    6.78600477287384

    -6.96288772960265

    4.44516236478943

    -1.75415688503484

    0.39441771610976

    -0.0388476491224433];

    A=A';B=B';

    filter_out_Q15=filter(B,A,x_Q15);

    % good

    isos=[ 307 307 0 8192 -3794 0

    668 1335 668 8192 -7894 2159

    541 1082 541 8192 -8904 3483

    13364 26729 13364 8192 -10923 6131];

    isf=4398;

    nbiq=4;

    qfmat=13;

    d=zeros(nbiq,3);

    taps=3;

    for k=1:length(x_Q15)

    accum=floor(x_Q15(k)*isf);

    for j=1:nbiq

    b_temp=isos(j,1:3);

    a_temp=isos(j,4:6);

    for ii=2:taps

    accum=accum-floor(a_temp(ii)*d(j,ii));

    end

    d(j,1)=floor(accum/2^qfmat);

    accum1=0;

    for ii=1:taps

    accum1=accum1+floor(b_temp(ii)*d(j,ii));

    end

    for ii=(taps-2+1):-1:1

    d(j,ii+1)=d(j,ii);

    end

    accum=floor(accum1);

    end

    x_no_scale_biq_fixed(k)=(accum1)/2^qfmat; % direct I form high order implementation output

    end

    figure(1)

    plot(filter_out_Q15)

    peak1=max(filter_out_Q15);

    hold on

    peak2=max(x_no_scale_biq_fixed);

    plot(x_no_scale_biq_fixed,'r')

    x_output_final=floor(x_no_scale_biq_fixed/2);

     

    And then put this into your iir.h

    #define IIR16_LPF_COEFF {\

    0,3794,0,307,307,\

    -2159,7894,668,1335,668,\

    -3483,8904,541,1082,541,\

    -6131,10923,13364,26729,13364}

    #define IIR16_LPF_ISF     4398
    #define IIR16_LPF_NBIQ    4
    #define IIR16_LPF_QFMAT   13

     

    in your main.c

      /* IIR Filter Initialisation                                */
      iir.dbuffer_ptr=dbuffer;
      iir.coeff_ptr=(int *)coeff;
      iir.qfmat=IIR16_LPF_QFMAT;
      iir.nbiq=IIR16_LPF_NBIQ;
      iir.isf=IIR16_LPF_ISF;
         iir.init(&iir);

    //generate waveform like this   

    for(i=0; i < SIGNAL_LENGTH; i++)
        {
      xn=(int)(32768*(sin(Rad) + cos(Rad*2.3567))/2);          //Q15
      sigIn[i]=xn;
      iir.input=xn;          
            iir.calc(&iir);
            yn=iir.output;
            sigOut[i]=yn;
      Rad = Rad + RadStep;
        }   

     compare the result from you CCS project and the matlab to see if they are the same.  If still have problem ,  let me know.

     

     

  • If you have this IIR16 version work. IIR32 is similar. The release of these example project would be around weeks ahead. The current code are not heavily commented and documented.  Since the legacy library the example is wokring associated with stb.lib. It is not easy to test in standalone. If you can make these iir16 version work. It's not difficult to make 32 bit version work. Good luck! :-)

    -Yu Cai  

  • Yui Cai,

       I ran the script and and the code on the dsp. I attached plots of both. Figure 1 is from matlab and Figure 2 is from the DSP.

    My iir16 low pass filter is not working in my code. If I just get rid of the filter, I can use the data as is and overall my motor control application works OK. With the filter in, not at all. I am trying to dig into it more to try to understand.

    The FIR16 and IIR16 code takes a Q15 number as input. This is convenient when filtering data right from the ADC on the chip. The "fractional" portion of the Q15 number is zero. Does the FIR16/IIR16 code work when the fractional portion is non-zero?

     

    Thanks

  • hmmmm. The picture did not attach properly. I received an error. Let me try that again.

  • I believe the red output is from the matlab scripts. the input for iir16 is Q15.  I think the asm file that you use might be different from mine. Here is my screen shot.

  • Yu Cai,

       If I am running different code, where can I download the latest?

    Thanks

     

  • This code is pre-release version. I am not sure if it can be release at this. the formal release would take 1 or 2 weeks.

    Thanks

    Yu Cai

  • Yu Cai,

        I guess you already told me it would take two weeks. When you said your version was different from mine, I thought that maybe I was using something outdated from what was released. You are referring to the latest version you are working on. Sorry.

    Do you think my problems are due to a bug in iir code? I thought you said that iir16 was ok, in which case, it is something I am doing incorrectly.

    Unless you have any other suggestions for me, I will wait until the new release is out and try that.

    Thanks

  • Yu Cai,

       Is this code soon to be released? Last comment was in 1 to 2 weeks.

    I am using a 'C' version of the code in the meantime.

    Thanks

     

  • The library will be released in Dec 15th. But I can set up a temporary ftp for downloading. What kinda filter do you need? Floating point, fixed point? 32 bit, 16 bit? FIR ,IIR?

    -Yu Cai

  • FIR and IIR, 32 bit fixed point and floating point.

    Thanks

     

     

  • To retrieve the files from the pickup directory:

     

      1. Open an ftp session to ftppickup.ti.com.

             ftp ftppickup.ti.com

     

      2. Login with the userid 'pickup'.

             Name: pickup

     

      3. Enter the password.

             Password: piurh!

     

      4. Change directories to the pickup directory.

             ftp> cd /pub/share/litivex

     

         Note: If you are using a graphical ftp client, you will not

               see the hidden pickup directory name litivex appear

               in the file list.  You will need to use a manual

               'Change Directory' or 'CD' command to change into the

               dropoff directory.

     

      5. Set the file transfer mode to ascii or binary as necessary.

             ftp> bin

     

      6. Transfer the file.

             ftp> get <file>

     

      7. End the ftp session.

             ftp> quit

     

    The files can also be retrieved with the url:

     

      ftp://pickup@ftppickup.ti.com/pub/share/litivex

     

    List of files in the pickup directory 'litivex':

    FILTER.zip

     

     

    The newFixedPoint1 has to be under controlSUITE to run the code. The FPU_FIR_TEST is standalone project. If you have any setup problem, please let me know.

     

    -Yu Cai

  • Yu Cai

    Thanks for the files!

     

     

  • Hello Yu Cai,

    I,m also intrested into IIR-Filters and so I looked into the 'beta'-Version of the Filter-Lib.

    I found some inconsitent Remarks between Sourccode and the Documentation-PDF:

    SourceCode iir5biq32.asm      vers.   Remarks Doc-File 'C28x_Fixed_Point_Libary_v1.00.pdf

    int input;              /* Latest Input sample           */     [Line 39]        vers.   int32 input; [Page 42]

    MOVL    *XAR4++,ACC     ; output32=Filtered Output in Q30 format [Line 125] vers.   Output32: Output data in Q31 format [Page 42]

    --------------------------------------------------

    I have another question for the eziir32.m code:

    Ni=500;             % Number of impulses required for Impulse response

    How is this value choosen? (I figured out this has an impact on the scaling.)

    I ask because the different between the old iir32.asm-File and the new iir5biq32.asm is the inputvalue.

    In the new Filter there is Q31-Inputformat. But the Inputvalue is first multiplied by the Input scaling factor (ISF).

    So depended on the ISF I will loose precision. (or I'm wrong?)

    /Stefan

     

  • Sorry for that inconsistency.

    the output should be in Q30 format. and input should be long (int32) with Q31 format. You can check my example code 2833x_FixedPoint_IIR32 under example_ccsv4 folder and associated matlab script FixedPointIIR32m. It has matlab simulation result as reference for comparison with CCS result. 

    The file and definition in the variable in 2833x_FixedPoint_IIR32 is the finalized version and it has been tested under both Matlab and CCS4.

    -------------------------------------------------------------------------

    for Ni=500.  That's the empirical value. IIR is very sensitive to quantitization error and dynamic range change. If scaling factor not properly selected and coefficient not properly scaling, the output or middle value is easily to overflow.

    I don't know which old file are you talking about, actually for new iir5biq32 is exactly the same as the old asm file except the header comment might has some small typo. The input should be Q31 format which you can check the 2833x_FixedPoint_IIR32 code.

    Actually you can run my test code script of FixedPointIIR32.m you will understand what's going on.

    You have to use eziir32.asm to generate 'good' coefficents and scalling factor ISF otherwise you won't be able to get corrent result. It certainly will lead to overflow.

    Do I answer you question? If any more question, feel free to post here.

     

  • With the old filter i mean the implementation in version 0.9c (sprc082 from 12.Jan 2005).

    There the iir32-Filter has an integer (Q15) as input value. In the new implementation of iir5biq32 there is a long (Q31) as input value.

    In the filterfunction the inputvalue is first multiplied by the 'Input scaling factor'(ISF), to avoid overflow, as you already mentioned.

    But on the other side there is a lost in resolution of the inputsignal. 

    For example in your IIR5BIQ32-Testcoefficients there following defination for a LP-Filter.

     

     

     

     

     

     

     

     

     

     

     

     

    #define IIR32_LPF_ISF

     

     

    #define IIR32_LPF_QFMAT

     

     

    28
    134086103

    This means for me that the inputvalue is multiplied by 0.0312 (134086103/(2^32)). So the lower 5 bit of the inputvalue get lost.

    So there is also a tradeoff of resolution. (with the old implementaion this was only a matter if ISF would by <1/(2^16))

    As far as I see the parameter Ni is the number of samples of the impulse response for the 'norm' of each biquad.

    But how long has this at least to be?

    I'd like to have no overflow inside the filtersection, but also the smallest ISF to have good resolution...

    So my question how the value of 500 (for Ni) is choosen...

    /Stefan

  • /* LPF co-efficients for IIR32 module */
    #define IIR32_LPF_COEFF {\
                0,248624377,0,20118017,20118017,\
                -141524868,517372703,43749199,87498398,43749199,\
                -228291242,583544331,35450657,70901314,35450657,\
                -401770939,715847129,875854244,1751708488,875854244}

    #define IIR32_LPF_ISF   288246535
    #define IIR32_LPF_NBIQ  4
    #define IIR32_LPF_QFMAT 29

    I am not sure if the example code that you are talking is the same as what I am tallking. There  are two example codes for IIR. One is 2833x_FixedPoint_IIR32 and one is 2833x_FxiedPoint_IIR16. One is for 32 bit IIR filter implementation and one is for 16 bit IIR filter implementation.

    For the 32 bit version, the input has to be in 32 bit format input (Q31) and for the 16 bit implementation the input should be Q15. I am not sure if the old version has some bug in it. It was developed long time ago and that's why I cleaned up. The new example code had been tested and the results were compared with matlab scripts.

    In IIR filter, lost resolution is unavoidable by fixed point implementation. If you want to change the ISF value, please check the matlab script either eziir32.m or FixedPointIIR32.m. You can change the Ni and see if the matlab simulation result overflow. If that Matlab simulation is good, then CCS result should be good also. If that one is not good, so you have to sacrifice you resolution.

    Please focus on the example code that I provided and don't pay too much attention to the old version. The old version might have some bug even though it is a release version.

    -Yu Cai

  • Yu Cai,

    I am currently using the c28346 for control purposes in an embedded design. I would like to add DSP FIR and IIR filtering functionality to my project using floating point and optionally fixed point math in either 16-bit or 32-bit. I am new to DSP on the floating point Delfino and would benefit greatly by using the libraries mentioned in this forum. Is there officially released fixed and floating point libraries available on the TI site? Also, can you point me in the right direction in regards to c28346 DSP FIR and IIR filtering reference material, example c28346 DSP FIR and IIR filtering code and etc? Thanks for your help.

    Best regards,

    Guilford

  • I think the latest FIR and IIR library was uploaded with the newest controlSUITE.  It was associated with example project from which you can know how to call those functions. By the way, the matlab script is also attached which can be used as reference guide and very useful in debugging.

    For testing any kinda IIR or FIR filter, you have to verify your algorithm at first in Matlab, which means before matlab code is working, you'd better not porting to your CCS. After it works, then it's a good reference as you debug in CCS or any real-mode. Good luck.

    Y. Cai