Capsim Block Documentation
This star reads a file and computes its FFT during the initialization phase. (This produces H(k)). During execution, the star performs a complex multiplication of the FFT of the file with the input complex data blocks (The input fft, X(k)). It then outputs the complex result.
| Port | Type | Name | |
|---|---|---|---|
| 0 | complex | x1 |
| Port | Type | Name | |
|---|---|---|---|
| 0 | complex | y |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | log2 [ length of FFT ] | int | fftexp | ||
| 1 | File with impulse response | file | file_name | imp.dat |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | int | fftl | ||
| 1 | cap_fft_cpx* | cxinBuff | ||
| 2 | cap_fft_cpx* | cxoutBuff | ||
| 3 | cap_fft_cfg | cfg | ||
| 4 | int | sample | ||
| 5 | FILE* | fp |
int no_samples; int i,j; FILE *fopen(); float a,b,c,d; complex val; |
|---|
fftl = 1 << fftexp;
if (fftl < 8)
{
fprintf(stderr,"fftfile: fft length is too short \n");
return(1);
}
cfg=cap_fft_alloc(fftl,0,NULL,NULL);
if ((cxinBuff = (cap_fft_cpx*)calloc(fftl,sizeof(cap_fft_cpx))) == NULL)
{
fprintf(stderr,"cmxfft: can't allocate work space \n");
return(2);
}
if ((cxoutBuff = (cap_fft_cpx*)calloc(fftl,sizeof(cap_fft_cpx))) == NULL)
{
fprintf(stderr,"cmxfft: can't allocate work space \n");
return(3);
}
if(strcmp(file_name,"stdin") == 0)
fp = stdin;
else if((fp = fopen(file_name,"r")) == NULL) {
fprintf(stderr,"fftfile: cannot open file\n");
return(1); /* file cannot be opened */
}
i=0;
/* Read input lines until EOF */
while((fscanf(fp,"%f",&cxinBuff[i].r) != EOF) && i<(fftl)) i++;
for(i=0; i< fftl; i++) {
cxinBuff[i].i=0.0;
}
/* perform fft calculation */
cap_fft(cfg,cxinBuff,cxoutBuff);
sample = 0;
SET_CELL_SIZE_IN(0,sizeof(complex));
SET_CELL_SIZE_OUT(0,sizeof(complex));
|
|---|
/* note the minimum number of samples on the */
/* input buffers and iterate that many times */
{
for(no_samples=(MIN_AVAIL());no_samples >0; --no_samples)
{
/* get samples */
IT_IN(0);
a = x1(0).re;
c = cxoutBuff[sample].r;
/* now get imaginary samples */
b = x1(0).im;
d = cxoutBuff[sample].i;
/* output */
if(IT_OUT(0)) {
KrnOverflow("cmxfftfile",0);
return(0);
}
val.re = a*c - b*d;
val.im = b*c + a*d;
y(0)=val;
sample++;
if (sample == fftl) sample = 0;
}
return(0);
}
|
|---|
/* free up allocated space */
free((cap_fft_cpx*)cxinBuff);
free((cap_fft_cpx*)cxoutBuff);
|
|---|
/* 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 */
|
|---|
/* cmxfftfile.s */
/***********************************************************************
cmxfftfile()
************************************************************************
Inputs: The FFT of the signal to be filtered, X(k)
Outputs: The FFT of the impulse response (from a file)
times the input signal, Y(k) = X(k)H(k)
Parameters: int fftexp, the exponent of the fft length
file_name, the name of the file containinf the samples
************************************************************************
This star reads a file and computes its FFT during the initialization phase.
(This produces H(k)).
During execution, the star performs a complex multiplication of
the FFT of the file with the input complex data blocks (The input fft, X(k)).
It then outputs the complex result.
This star multiplies the two complex data streams as follows:
Each complex sample is assumed to be composed of a real sample followed by
an imaginary sample. This star operates like a "butterfly," i.e.
c1 = a + jb = x1(0) + x1(1)
c2 = c + jd = x2(0) + x2(1)
r = c1 * c2 = (ac-bd) + j(bc+ad) = y(0) + y(1)
Programmer: Prayson W. Pate,Sasan Ardalan
Date: March 12, 1989
*/
|
|---|