• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Digital Signal Processors (DSP) » OMAP™ Processors » OMAP-L13x, AM1x and C674x Processors Forum » strange behavior of C6accel_DSP_fft32x32
Share
OMAP™ Processors
  • Forums
  • Announcements
Options
  • Subscribe via RSS
Resources
  • OMAP-L1x DSP+ARM9™-based Processors Product Folder
  • OMAP3525/30 DSP+ARM Cortex™-A8-based SOCs Product Folder

  • Top OMAPL Wiki Links
  • OMAPL3x Schematic Review Checklist
  • OMAPL13x Boot resources

  • OMAPL Document Resources
  • OMAPL137 Technical reference manual
  • OMAPL138 Technical reference manual
  • OMAPL Boot loader App Notes
  • Forums

    strange behavior of C6accel_DSP_fft32x32

    This question is answered
    Myosotis
    Posted by Myosotis
    on May 05 2012 06:38 AM
    Intellectual510 points
    data.zip

    Hello! I faced the strange behavior of function C6accel_DSP_fft32x32().

    It works fine in demo samples which are coming with c6accel lib (c6accel_1_01_00_07) from DVSDK 4 (dvsdk_omapl138-evm_04_03_00_06).

    But with my input signal file this function returns wrong result.

    Tell me please, what may be the cause. Thanks for any advice

    #include <stdio.h>
    #include <stdlib.h> 
    #include <string.h>
    #include <math.h>
    
    /* Codec Engine includes */ 
    #include <xdc/std.h> 
    #include <ti/sdo/ce/Engine.h>
    #include <ti/sdo/ce/CERuntime.h>
    #include <ti/sdo/ce/osal/Memory.h>
    #include <xdc/runtime/System.h>
    
    /* Include C6ACCEL headers */
    #include "../c6accelw/c6accelw.h"
    
    #define ENGINENAME "omapl138" 
    #define ALGNAME "c6accel"
    #define APPNAME "test_DSP_FFT" 
    
    #pragma DATA_ALIGN(pInputArray, 8);  // The alignment is very important
    #pragma DATA_ALIGN(pOutputArray, 8); // for input/ouput and twiddle pointers
    #pragma DATA_ALIGN(pTwiddleTable, 8);
    
    signed int   *pTwiddleTable;  //Input twiddle factors 
    signed int  *pInputArray, *pOutputArray; 
    
    /* Codec Engine engine and codec labels, defined in cfg file: */
    static String algName      = ALGNAME;
    static String engineName   = ENGINENAME;
    static String progName     = APPNAME;
    static String ref_src_fft = "complex_input_signal.dat";  
    static String sOut_file = "real_output_spectrum.dat";
         
    // Create default heap memory configuration for wrapper
    static Memory_AllocParams wrapperMemParams = {
        Memory_CONTIGHEAP,
        Memory_CACHED,
        Memory_DEFAULTALIGNMENT,
        0
    };
    
    int main () {
        int N = 32768;//count of points for FFT
        C6accel_Handle hC6accel = NULL; 
        CERuntime_init();
        hC6accel = C6accel_create(engineName, NULL, algName, NULL);
        while (1) {
    	/*Check for failure*/
    	if ( hC6accel == NULL) {
    		printf("%s: C6accel_create() failed \n",progName);
                    break;
    		}
        C6Accel_setSync(hC6accel); //Set C6Accel instance for synchronous call 
        test_DSP_FFT(hC6accel,N); 
        C6accel_delete(hC6accel);
        break; 
        }
        return 0;
    }
    
    int test_DSP_FFT(C6accel_Handle hC6accel,unsigned int nx)
    {
    	int i,j,status;
    	unsigned int freaden; 
            signed int  iNum;
            double scale = 2147483647.5;  
    	FILE  *fSamples, *fOut;
    	UInt32 framesize = 2*nx*sizeof(int);
    	
    	//---------------memory allocation--------------------------------//
    	pTwiddleTable = Memory_alloc(framesize, &wrapperMemParams);
    	if (pTwiddleTable == NULL) {
    		printf("Memory_alloc error\n");
    		return -1; 
    	} 
    	Memory_cacheWbInv(pTwiddleTable, framesize);
    	memset (pTwiddleTable,0x00,framesize);
    	 
    	pInputArray = Memory_alloc(framesize, &wrapperMemParams); 
    	if (pInputArray == NULL) {
    		printf("Memory_alloc error\n");
    		return -1; 
    	} 
    	Memory_cacheWbInv(pInputArray, framesize);
    	memset (pInputArray,0x00,framesize);
    	
    	pOutputArray = Memory_alloc(2*nx*sizeof(int), &wrapperMemParams);  
            if (pOutputArray == NULL) {
              printf("\nFailed memory_alloc. \n");
              return -1; 
            }
            Memory_cacheWbInv(pOutputArray, framesize);
            memset (pOutputArray,0x00,framesize); 
            //----------------------------------------------------------------//
        
    	// Generate the twiddle table with real and imaginary parts
    	gen_twiddle(pTwiddleTable, nx, scale); 
    	// read input complex data 
    	if ((fSamples = fopen(ref_src_fft,"rb")) == NULL) {
    		printf("Failed to open file %s\n",ref_src_fft);
    		return -1;
    	}
    	fread(pInputArray,sizeof(int),2*nx,fSamples); 
    	fclose(fSamples); 
    	// Call the fft32x32 in the C6Accel 
            status = C6accel_DSP_fft32x32 (hC6accel,pTwiddleTable, nx, pInputArray, pOutputArray); 
    	printf("Status of C6accel_DSP_fft32x32 = %d\n",status);
    	if (status!=NULL)
    		return -1;
    	
    	signed int *pOut = malloc(nx*sizeof(int));
    	memset(pOut,0x00,nx*sizeof(int)); 
    	
    	fOut = fopen("complex_output_spectrum.dat","wb");
            fwrite(pOutputArray,sizeof(int),nx*2,fOut); 
            fclose(fOut);
    	//put in file module of complex 	
    	while (1) {
    	    for (i=0,j=0; j<nx; i=i+2,j++) { 
    	        pOut[j] = (int)(sqrt(pOutputArray[i]*pOutputArray[i]+pOutputArray[i+1]*pOutputArray[i+1]));
    	    }
    	    break; 
    	} 
        fOut = fopen(sOut_file,"wb"); 
        fwrite(pOut,sizeof(int),nx,fOut); 
        fclose(fOut); 
        
        Memory_free(pInputArray,framesize,&wrapperMemParams);
        Memory_free(pOutputArray,framesize,&wrapperMemParams);
        Memory_free(pTwiddleTable,framesize,&wrapperMemParams);
        free(pOut); 
        printf("Done. See spectrum at file %s\n",sOut_file);
        return 0; 
    }
    
    static int d2i(double d)   //Truncate a 'double' to a 'int',   with clamping. 
    {   
        if (d >=  2147483647.0) return (int)0x7FFFFFFF;   
        if (d <= -2147483648.0) return (int)0x80000000;   
        return (int)d;   
    }   
    
    int gen_twiddle(int *w, int n, double scale)   
    {   
        int i, j, k, s=0, t;   
       
        for (j = 1, k = 0; j < n >> 2; j = j << 2, s++)   
        {   
            for (i = t=0; i < n >> 2; i += j, t++)   
            {   
                w[k +  5] = d2i(scale * cos(6.0 * PI * i / n));   
                w[k +  4] = d2i(scale * sin(6.0 * PI * i / n));   
       
                w[k +  3] = d2i(scale * cos(4.0 * PI * i / n));   
                w[k +  2] = d2i(scale * sin(4.0 * PI * i / n));   
       
                w[k +  1] = d2i(scale * cos(2.0 * PI * i / n));   
                w[k +  0] = d2i(scale * sin(2.0 * PI * i / n));   
       
                k += 6;   
            }   
        }   
        return k;   
    }   
    
    

    In data.zip you can find:

    1. complex_input_signal - input file with integer 32 bit values (real and imaginary parts on even and odd positions respectively)
    2. real_output_spectrum - output file with module of complex number
    3. complex_output_spectrum - output file with integer 32 bit values (real and imaginary parts on even and odd positions respectively)
    DVSDK OMAPl138 DSP C6Accel fft
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Rahul Prabhu
      Posted by Rahul Prabhu
      on May 07 2012 10:58 AM
      Verified Answer
      Verified by Myosotis
      Genius15455 points

      Hi,

      I think this might be a case where the input data is not scaled properly due to which the output may be overflowing. I would strongly recommend you to download the C64x+ version of the DSPLIB, or  view the details of the implementation of the fft_32x32 kernel mentioned in the document sprueb8b.pdf. There is also an example implementation of the 32 bit FFT function in the C64x+ DSP library.

      The data that we passed in the test bench of the C6Accel is a pre-scaled data due to which you may not see this step implemented in the sample application.

      Regards,

      Rahul 

      ---------------------------------------------------------------------------------
      Please click the
      Verify Answer button on this post if it answers your question.
      ---------------------------------------------------------------------------------

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use