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.

DSP Libary 3.0 - CFFT Example

Hello dear community,

I have some questions about the DSP-Library 3.0 Example of the CFFT for CCS5.

At first I'd like to tell you the actual situation.

 

In the example, I have included the "t2_SCALE.h", which contains the following 32 DATA (signed int16) values.

 #define NX 16

DATA x[2*NX] ={

23773, -2998,    /* 0 */

22759, 23573,    /* 1 */

-4899, -1857,   /* 2 */

21490, -4442,    /* 3 */

-24136, 18901,  /* 4 */

-8033, 1373,    /* 5 */

17096, -16234,  /* 6 */

-26758, 9397,   /* 7 */

-19714, 18458,  /* 8 */

-16227,-26225,  /* 9 */

-16448, 9896,  /* 10 */

5666, -6580,   /* 11 */

-12437, 18113, /* 12 */

-16443, 153,   /* 13 */

-26463, 11435, /* 14 */

13472, -3882,  /* 15 */

};

 

Now the functions cfft and cbrev are computed above these values.

 cfft(x, NX, SCALE);

cbrev(x,x,NX);

 

The results are stored in "x" and are almost the same as the comparing-data in "rtest", which is given by Texas Instruments.

 DATA rtest[2*NX] ={

-4206, 3068,  /* 0 */

6064,  -1581, /* 1 */

2009,  -3210, /* 2 */

7369,  -3740, /* 3 */

161,   5065,  /* 4 */

8019,  953,   /* 5 */

1238,  -5800, /* 6 */

-53,   -2434, /* 7 */

-3698, 3896,  /* 8 */

-6844, -3103, /* 9 */

4674,  2013,  /* 10 */

-2688, -6683, /* 11 */

-387,  1088,  /* 12 */

3828,  1291,  /* 13 */

2235,  1608,  /* 14 */

6045,  4566,  /* 15 */

};

 

So, that is working fine, but I wonder, how to compare these results with Matlab.

In the documentation "spru422j", page 39 is written, that "The C55 DSPLIB cfft results can be compared to the unmodified MATLAB cfft."

 

But my Matlab Version does not possess a function named "cfft", that's why I used the standart "fft" function.

 

% Values from t2_SCALE.h

M = [23773, -2998, 22759, 23573, -4899, -1857, 21490, -4442, -24136, 18901, -8033, 1373, 17096, -16234, -26758, 9397, -19714, 18458, -16227, -26225,

-16448,9896, 5666, -6580, -12437, 18113, -16443, 153,-26463, 11435, 13472,

-3882]

 % compute fft

Q = fft(M,16);

 

Unfortunately, my Matlab results do not match with the TI results.

Could you tell me please, what I'm doing wrong? And are you able to generate results with Matlab, which are similar to the "rtest" data?

You would help me a lot.

Thank you very much for your time and your help.

Best regards

Etienne

  • Etienne,

    Matlab fft does not perform any scaling. if you want to compare the C55 cfft() results with the matlab fft() results you need to take the scaling into consideration.

    If you use the C55 NO_SCALE cfft() mode there is no scaling performed and you can compare the results directly with Matlab

    Thanks

    Cesar

  • Hello Cesar,

    thank you very much for your  fast response!

    But now I'm a little bit confused. There are two different directions of solving my problem, your explanation and the one, which is described in the "spru422j" documentation.

     

    The documentation Illustration - Comparing the results to MATLAB

    NOSCALE version: The MATLAB cfft results need to be multiplied by the cfft size, N, in order to

    be compared to the C55 DSPLIB cfft results.

    SCALE version: The C55 DSPLIB cfft results can be compared to the unmodified MATLAB cfft

    results.

     

    Compared to your illustration, the explanation of the documentation is twisted.

    So, maybe there is a little mistake in the document.

     

    Well, but nevertheless I tried both illustrations and no one matched to the DSP results.

    Probably, I'm just to birdbrained.

    So I'd like to show you my steps in computing the Matlab fft in abidance by your response.

     

    Results for cfft[NOSCALE] in CCS from "t2_NOSCALE.h"

    #define NX 16

    DATA rtest[2*NX] ={

    2698,  -2525, /* 0 */

    1760,  4307,  /* 1 */

    -1070, 24,    /* 2 */

    2951,  3820,  /* 3 */

    2348,  -1039, /* 4 */

    -2370, 2971,  /* 5 */

    4689,  2939,  /* 6 */

    -426,  -735,  /* 7 */

    3197,  -2219, /* 8 */

    -24,   -3405, /* 9 */

    0,     609,   /* 10 */

    2213,  228,   /* 11 */

    4735,  903,   /* 12 */

    -68,   2900,  /* 13 */

    -3961, 2523,  /* 14 */

    -1930, 2960,  /* 15 */

    };

     

     

    Matlab calculation

    %Array with 32 input values

    M = [921,891,-551,853,218,-184, -29,806, 801,-906,536,-302,-90,641, -987,-1004, 658,-740, -114,-609, 236,-617, 597,212,863,-467, 487,-617,-663,-993,-194,505];

    %calculate Matlab fft

    Q = fft(M,16);

     

    Matlab Results

    1.0e+003 *

       1.6140                                /* 0 */

      -0.5803 - 1.9020i             /* 1 */

     0.7306 - 1.1969i               /* 2 */

    -0.2682 - 2.8069i               /* 3 */

    2.8810 - 0.0890i               /* 4 */

       3.4003 - 3.6054i             /* 5 */

     2.4574 + 0.8051i               /* 6 */

    -2.0717 - 1.4684i               /* 7 */

     0.0240                                 /* 8 */

     -2.0717 + 1.4684i             /* 9 */

       2.4574 - 0.8051i             /* 10 */

      3.4003 + 3.6054i             /* 11 */

      2.8810 + 0.0890i             /* 12 */

     -0.2682 + 2.8069i             /* 13 */

      0.7306 + 1.1969i             /* 14 */

      -0.5803 + 1.9020i            /* 15 */

     

     

    As you see my results obtaining with Matlab do not match.

    I can't find my failure, although there are not so many places to make mistakes.

    Are you able to see the spot, where I fail? – Sorry, but I seriously don't get it.

     

    Etienne

  • Etienne,

     

    I checked the matlab documentation and the matlab fft() performs scaling

    http://www.mathworks.com/help/matlab/ref/fft.html

    So, the DSPLIB documentation is correct and you should be able to compare the cfft() results directly to the Matlab results.

    However please keep in mind that the DSP data is in Q15 format. I think the DSPLIB user guide includes a section about the Q15 format. You need to convert the Q15 format to decimal format used by Matlab.

    There are q15 calculators online that you can use to perform the conversion

     

    Thanks

    cesar

     

     

  • Caesar,

     

    thank you for checking the documentation of the DSP library.

    Yes, there is a user guide about the q15 format and it includes two conversion-functions (q15tofl and fltoq15).

     

    But if I convert my q15 input values to float before computing the cfft an error occurs. Because the arguments for the cfft have to be this way: (DATA*, ushort, type);

    The same appears in Matlab, when I try to execute the fft after converting the float input data to q15 format.

     

    Well, when I convert the results of the computed fft in Matlab and CCS.

    I still do not get the same values.

    That is the way how I convert my results in CCS:

    float* Test = (float*)malloc(sizeof(float)*16);

    cfft(x,16, SCALE);

    cbrev(x, x, 16);

    q15tofl(x, Test, 16);

     

    And in Matlab:

    %Array with input values

    M = [921,891,-551,853,218,-184, -29,806, 801,-906,536,-302,-90,641, -987,-1004, 658,-740, -114,-609, 236,-617, 597,212,863,-467, 487,-617,-663,-993,-194,505];

    %calculate Matlab fft

    Q = fft(M,16);

    %converts to signed int16

    Q = int16(Q);

     Unfortunately, still no match.

    Thanks

    Etienne

  • Hello,

     I become a little bit desperated in comparing Matlab FFT with Texas Instruments FFT.

    Does no one know how to generate the same values with both functions?

    Or maybe someone have the same problem like me.

     

    Greetings

    Etienne

  • Etienne,

    The C55 DSPLIB cfft() output format is Q15

     

    Please read the Appendix A "Overview of Fractional Q Formats" in the DSPLIB User Guide to understand how to convert from Q15 to decimal format.

    Decimal format is not the same as "Floating Point".

     

    Thanks

    Cesar

     

  • Good morning Cesar,

     

    Sorry I misinterpreted the type decimal with float. Decimal have a higher precision.

    Thank you very much for your time and your endurance.

     

    I read the DSPLIB documentation Appendix A: "Overview of Fractional Q Formats" and I used an online-converter and some Matlab functions to convert q15 to decimal and reverse.

    Just to be sure, I'd like to tell you my comprehension about the Q Formats.

    Maybe I misunderstood some details, hopefully not. :)

     

    Q0.15 is written in a Qm.n format.

    m bits used to represent the two’s complement integer portion.

    n bits used to represent the two’s complement fractional portion.

     

    So Q0.15 is using 15 bits for the fractional portion and 1 bit for the sign.

    In return Q15.0 is using 15 bits for the integer portion and 1 bit for the sign.

    Q0.31 and Q31.0 are working like the same principle, but they are two 16 bit words instead of one.

     

    The data type "DATA" is in the DSPLIB guide called "Q.15" and "LDATA" is called "Q.31".

    I'm not sure, but DATA is a signed int16 and LDATA a signed long, so should they not be called "Q15.0" and "Q31.0"?

     

    Convert a number of type DATA to Decimal (Q0.31) according to Matlab and the Online converter, I have to divide the DATA number by 2^15 (32768).

     

    For example: 3301/32768 = 0.01007

    That is the same solution I obtained by Matlab function "q152dec" and the online converter.

     

    But this calculation method is the same, which is used to convert q15 to a float. The only difference should be the precision in resolution.

     

    Would you agree with my thoughts or did I misunderstand something?

     

    Regards

    Etienne

  • Etienne,

     

    Your understanding is correct. if the data format is Q0.15 one can divide by 32768 to get the decimal value.

    You should be able to compare the decimal values to the Matlab results

     

    Thanks

    cesar 

  • Hello Cesar,

     

    I have read some other guides, which are about Fixed Point and Q Format handling.

    (http://sestevenson.wordpress.com)

     

    My statement: "Convert a number of type DATA to Decimal (Q0.31) … I have to divide the DATA number by 2^15 (32768)." seems to be false, according to you and this guide I have read.

     

    I think this is the right way of converting Q15.0 to Q0.31.

    My number X = 8192 (DATA – Q15.0) divided by 2^15 equates to X = 0.25 (Q0.15).

    So If I want to get the (Decimal - Q0.31) format, I have to divide X by 2^31.

    X = 8192/ 2^31 = 3.8147e-006

     

    Now, I have  some questions.

    1)

    The data type "decimal", which you mentioned, is not only represented by Q0.31 format.

    It could be also represented by Q0.15 format, but with less precision, true?

     

    2)

    When you looking to my Matlab and CCS FFT results:

     

    CCS Results (taken from "t2_SCALE.h")

     -4206, 3068,  /* 0 */

     6064,  -1581, /* 1 */

     2009,  -3210, /* 2 */

     7369,  -3740, /* 3 */

     161,   5065,  /* 4 */

     8019,  953,   /* 5 */

     1238,  -5800, /* 6 */

     -53,   -2434, /* 7 */

     -3698, 3896,  /* 8 */

     -6844, -3103, /* 9 */

     4674,  2013,  /* 10 */

     -2688, -6683, /* 11 */

     -387,  1088,  /* 12 */

     3828,  1291,  /* 13 */

     2235,  1608,  /* 14 */

     6045,  4566,  /* 15 */

     

     

    Matlab Results

      1.0e+005 *

     0.4900                    /* 0 */

     0.3111 - 0.5401i   /* 1 */

     -0.0266 - 0.5817i  /* 2 */

     0.4994 - 0.3087i   /* 3 */

     2.8810 - 0.0890i   /* 4 */

     0.7056 + 1.2490i  /* 5 */

     -0.2246 - 0.1818i /* 6 */

    0.4002 + 0.1378i   /* 7 */

    -0.0642                    /* 8 */

     0.4002 - 0.1378i   /* 9 */

     -0.2246 + 0.1818i  /* 10 */

     0.7056 - 1.2490i    /* 11 */

     0.0238 - 0.3209i    /* 12 */

     0.4994 + 0.3087i    /* 13 */

     -0.0266 + 0.5817i  /* 14 */

     0.3111 + 0.5401i  /* 15 */

     

    (Results calculated is described in my very first post in this thread)

     

    You see, that even conversation, would not make sure, that the values can be compared.

    For example element Zero in CCS has real and imaginary parts, but in Matlab only a real part.

    So my main problem persists, how can I generate the same Matlab and CCS FFT results? :)

     

    Best regards

    Etienne