fconv

Capsim Block Documentation

Short Description

This star convolves its input signal with an impulse response (from file) to generate the output signal.

Top
Input Connections
Port Type Name
0 float x
Top
Output Connections
Port Type Name
0 float y
Top
Parameters
Num Description Type Name Default Value
0 impl: length of impulse response in samples: int impl 128
1 (file)ASCII file which holds impulse response: file impf_name imp.dat
2 log2(fft length): int fftexp 8
Top
States
Num Type Name Initial Value Description
0 cap_fft_scalar* temp
1 cap_fft_cpx* freqBuffCx
2 cap_fft_scalar* temp2
3 cap_fft_cpx* iresp
4 cap_fft_scalar* save
5 cap_fftr_cfg preverse
6 cap_fftr_cfg pforward
7 int pcount impl
8 int fftl 1 << fftexp
9 double norm
Top

Declarations


 

	int i;
	int no_samples;
	FILE* fp;
	float val;



Top

Initialization Code



 

	if(impl < (2.89 * log((float)fftl) + 1))
	fprintf(stderr,"fconv: direct convolution may be faster\n");
	if(impl >= fftl) {
		fprintf(stderr,"fconv: FFT length smaller than impulse response length\n");
		return(1);
	}
	if( (temp = (cap_fft_scalar*)calloc(fftl,sizeof(cap_fft_scalar))) == NULL
	 || (iresp = (cap_fft_cpx*)calloc(fftl,sizeof(cap_fft_cpx))) == NULL
	 || (freqBuffCx = (cap_fft_cpx*)calloc(fftl,sizeof(cap_fft_cpx))) == NULL 
	 || (temp2 = (cap_fft_scalar*)calloc(fftl,sizeof(cap_fft_scalar))) == NULL
	 || (save = (cap_fft_scalar*)calloc(impl,sizeof(cap_fft_scalar))) == NULL  ) {
		fprintf(stderr,"fconv: can't allocate work space\n");
		return(2);
	}
	if((fp = fopen(impf_name,"r")) == NULL) {
		fprintf(stderr,"fconv: can't open impulse response file %s\n",impf_name);
		return(3);
	}
	for(i=0; i
    
Top

Main Code



 

	for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) {
		IT_IN(0);
		temp[pcount++] = x(0);
		if(pcount == fftl) {
			for(i=0; i
    
Top

Wrapup Code



 

	free(temp); free(iresp); free(save); free(temp2); free(freqBuffCx);
	
        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



 

/* fconv.s */
/***********************************************************************
                             fconv()
************************************************************************
"Linear Convolution":
This star convolves its input signal with an impulse response to
generate the output signal.
Param.	1 - (int) impl: length of impulse response in samples.
	2 - (file) impf_name: ASCII file which holds impulse response.
	3 - (int) fftexp: log2(fft length).
Convolution is performed by the fft overlap-save method (described in
Oppenheim & Schafer, Digital Signal Processing, pp. 113).
The FFT length must be greater than the impulse response length.
For efficiency, it should probably be more than twice as long.

fconv


"Linear Convolution":
This star convolves its input signal with an impulse response to
generate the output signal.
Param.	1 - (int) impl: length of impulse response in samples.
	2 - (file) impf_name: ASCII file which holds impulse response.
	3 - (int) fftexp: log2(fft length).
Convolution is performed by the fft overlap-save method (described in
Oppenheim & Schafer, Digital Signal Processing, pp. 113).
The FFT length must be greater than the impulse response length.
For efficiency, it should probably be more than twice as long.


Programmer: M. R. Civanlar
Date: November 16, 1986
Modified: ljfaber, Dec86, Feb87
Modified: 6/88 ljfaber  update comments, efficiency

*/