autoxcorr

Capsim Block Documentation

Short Description

If one input then compute autocorrelation. If two inputs then compute crosscorrelation.

Top
Output Connections
Port Type Name
0 float y
Top
Parameters
Num Description Type Name Default Value
0 Number of samples int npts 128
Top
States
Num Type Name Initial Value Description
0 int fftLength
1 int fftexp
2 cap_fft_scalar* fftBuffer
3 cap_fft_scalar* fftBuffer2
4 cap_fft_scalar* temp
5 cap_fft_cpx* freqBuff
6 cap_fft_cpx* freqBuff2
7 int sampleCount 0
8 int numberOfInputBuffers
9 cap_fftr_cfg preverse
10 cap_fftr_cfg pforward
11 double norm
Top

Declarations


 

	int no_samples;
	int i,j;
	float	tmpReal;
	float	temp2;



Top

Initialization Code



 

/*
 * compute the power of 2 number of fft points
 */
fftexp = (int) (log((float)npts)/log(2.0)+0.5);
fftLength = 1 << fftexp;
if (fftLength > npts ) {
        fftLength = fftLength/2;
        fftexp -= 1;
}
if((numberOfInputBuffers = NO_INPUT_BUFFERS()) > 2) {
     fprintf(stderr,"autoxcorr: no input buffers\n");
     return(3);
}
if (fftLength < 8) {
	fprintf(stderr,"autocorr: fft length is too short \n");
	return(1);
}
if ((fftBuffer = (cap_fft_scalar*)calloc(fftLength,sizeof(cap_fft_scalar))) == NULL) {
	fprintf(stderr,"autoxcorr: can't allocate work space \n");
	return(2);
}
if ((freqBuff = (cap_fft_cpx*)calloc(fftLength,sizeof(cap_fft_cpx))) == NULL) {
	fprintf(stderr,"autoxcorr: can't allocate work space \n");
	return(3);
}
if(numberOfInputBuffers == 2) {  
	if ((fftBuffer2 = (cap_fft_scalar*)calloc(fftLength,sizeof(cap_fft_scalar))) == NULL) {
	   fprintf(stderr,"autoxcorr: can't allocate work space \n");
	   return(4);
	}
	if ((freqBuff2 = (cap_fft_cpx*)calloc(fftLength,sizeof(cap_fft_cpx))) == NULL) {
	fprintf(stderr,"autoxcorr: can't allocate work space \n");
	return(5);
	}
}
if ((temp = (cap_fft_scalar*)calloc(fftLength,sizeof(cap_fft_scalar))) == NULL) {
	fprintf(stderr,"autoxcorr: can't allocate work space \n");
	return(6);
}

norm=1.0/(float)fftLength;
norm=norm*norm*2.;


	preverse = cap_fftr_alloc(fftLength, INVERSE_FFT, NULL,NULL);
	pforward = cap_fftr_alloc(fftLength, FORWARD_FFT, NULL,NULL);




Top

Main Code



 

for (no_samples = MIN_AVAIL(); no_samples > 0; --no_samples) {

		/* 
		 * read in input value	
		 */
		if(numberOfInputBuffers == 1) { 
			IT_IN(0);
			fftBuffer[sampleCount] = INF(0,0);
		}
		else {
			IT_IN(0);
			fftBuffer[sampleCount] = INF(0,0);
			IT_IN(1);
			fftBuffer2[sampleCount] = INF(1,0);
		}
		sampleCount++;

		/* 
		 * Get enough points				
		 */
		if(sampleCount >= fftLength)
		{
			/* 
			 * perform fft calculation		
			 */
			 
		cap_fftr(pforward, fftBuffer,freqBuff);	 
			 
		//	rfft(fftBuffer,fftLength);
		
		

		if(numberOfInputBuffers == 1) { 
			    /*
			     * compute X(k)X*(k)
			     */
 
			    cmultfftcap(freqBuff, freqBuff, fftLength, 1.0);

			} else {
			
		        
		             cap_fftr(pforward, fftBuffer2,freqBuff2);
		        
		//		     rfft(fftBuffer2,fftLength);

				
			
			
			    /*
			     * compute X(k)Y*(k)
			     */
			     
			    cmultfftcap(freqBuff, freqBuff2, fftLength, 1.0);
			     

			}
			
			cap_fftri(preverse, freqBuff, fftBuffer);

			// rfti(fftBuffer,fftLength);
			
			/* 
			 * now, output samples			
			 */
            for (i=0; i
    
Top

Wrapup Code



 

	/* 
	 * free up allocated space	
	 */
	free((char*)fftBuffer);
	free((char*)freqBuff);
        if(numberOfInputBuffers == 2) {  
		free((char*)fftBuffer2);
		free((char*)freqBuff2);
        }
    
        free(preverse);
        free(pforward);





Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* autoxcorr.s */
/***********************************************************************
                             autoxcorr()
************************************************************************
If one input then compute autocorrelation.
If two inputs then compute crosscorrelation.
************************************************************************
Programmer: 	Sasan H. Ardalan	
Date: 		January 4, 1991

autoxcorr


If one input then compute autocorrelation.
If two inputs then compute crosscorrelation.


Programmer: 	Sasan H. Ardalan	
Date: 		January 4, 1991

*/