Capsim Block Documentation
Discrete Hilbert Transform
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | x |
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | y |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | length of Hilbert transform impulse response | int | impl | 17 | |
| 1 | bandwidth (0 < BW <= 0.5) | float | fbw | 0.5 | |
| 2 | log2(fft length) | int | fftexp | 8 |
int i,k; float anarg,imp_del,tmp,argval,window; int no_samples; char impResponseFile[200]; int impFlag; FILE* fp; |
|---|
pcount = impl;
/*
* allocate necessary storage
*/
if( (temp = (cap_fft_scalar*)calloc(fftl,sizeof(cap_fft_scalar))) == NULL
|| (temp2 = (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
|| (save = (cap_fft_scalar*)calloc(impl,sizeof(cap_fft_scalar))) == NULL ) {
fprintf(stderr,"hilbert: can't allocate work space\n");
return(2);
}
imp_del=(float)impl/2.0-0.5;
for( i=0; i< impl; i++) {
anarg=(float)i-imp_del;
if(anarg != 0.0)
{
tmp = sin( fbw * PI * anarg);
argval = 2*PI*(float)i/(float)(impl-1);
/*
* Blackman window
*/
window= 0.42 -0.5*cos(argval) + 0.08*cos(2*argval);
temp[i] = TWO_OVER_PI*tmp*tmp/anarg*window;
}
else
temp[i] = 0.0;
}
preverse = cap_fftr_alloc(fftl, INVERSE_FFT, NULL,NULL);
pforward = cap_fftr_alloc(fftl, FORWARD_FFT, NULL,NULL);
cap_fftr(pforward, temp,iresp);
norm=1.0/(float)fftl;
// rfft(iresp, fftl);
|
|---|
for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) {
IT_IN(0);
temp[pcount++] = x(0);
if(pcount == fftl) {
for(i=0; i |
|---|
free(temp); free(iresp); free(save); free(temp2); free(freqBuffCx);
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 */
|
|---|
/* hilbert.s */
/***********************************************************************
hilbert()
************************************************************************
"Discrete Hilbert Transform":
Reference:
A.V. Oppenheim amd R. W. Schafer,"Digital Signal
Processing",pp 360-363,Prentice-Hall,1974
A Blackman window is used in the design.
It then uses the overlap save method for fast convolution to model the
hilbert transform impulse response.
The parameters are as follows:
Param. 1 - (int) implexp: log2 [ length of impulse response in samples].
Note: The larger the length, the better the approximation. However, the
simulation efficiency suffers considerably.
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.
|
|---|