Capsim Block Documentation
If one input then compute autocorrelation. If two inputs then compute crosscorrelation.
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | y |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | Number of samples | int | npts | 128 |
int no_samples; int i,j; float tmpReal; float temp2; |
|---|
/*
* 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);
|
|---|
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 |
|---|
/*
* free up allocated space
*/
free((char*)fftBuffer);
free((char*)freqBuff);
if(numberOfInputBuffers == 2) {
free((char*)fftBuffer2);
free((char*)freqBuff2);
}
free(preverse);
free(pforward);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD 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://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/* autoxcorr.s */
/***********************************************************************
autoxcorr()
************************************************************************
If one input then compute autocorrelation.
If two inputs then compute crosscorrelation.
************************************************************************
Programmer: Sasan H. Ardalan
Date: January 4, 1991
|
|---|