Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finally found it. I just need to implement the following code from matlab source code to c++ . "the_mandrill" were right, I need to add the normalizing constant into the coefficient:</p> <pre><code>kern = exp(-j*w*(0:length(b)-1)); b = real(b*(kern*den(:))/(kern*b(:))); </code></pre> <p><strong>EDIT:</strong> and here is the final edition, which the whole code will return numbers exactly equal to MATLAB : </p> <pre><code>double *ComputeNumCoeffs(int FilterOrder,double Lcutoff, double Ucutoff, double *DenC) { double *TCoeffs; double *NumCoeffs; std::complex&lt;double&gt; *NormalizedKernel; double Numbers[11]={0,1,2,3,4,5,6,7,8,9,10}; int i; NumCoeffs = (double *)calloc( 2*FilterOrder+1, sizeof(double) ); if( NumCoeffs == NULL ) return( NULL ); NormalizedKernel = (std::complex&lt;double&gt; *)calloc( 2*FilterOrder+1, sizeof(std::complex&lt;double&gt;) ); if( NormalizedKernel == NULL ) return( NULL ); TCoeffs = ComputeHP(FilterOrder); if( TCoeffs == NULL ) return( NULL ); for( i = 0; i &lt; FilterOrder; ++i) { NumCoeffs[2*i] = TCoeffs[i]; NumCoeffs[2*i+1] = 0.0; } NumCoeffs[2*FilterOrder] = TCoeffs[FilterOrder]; double cp[2]; double Bw, Wn; cp[0] = 2*2.0*tan(PI * Lcutoff/ 2.0); cp[1] = 2*2.0*tan(PI * Ucutoff / 2.0); Bw = cp[1] - cp[0]; //center frequency Wn = sqrt(cp[0]*cp[1]); Wn = 2*atan2(Wn,4); double kern; const std::complex&lt;double&gt; result = std::complex&lt;double&gt;(-1,0); for(int k = 0; k&lt;11; k++) { NormalizedKernel[k] = std::exp(-sqrt(result)*Wn*Numbers[k]); } double b=0; double den=0; for(int d = 0; d&lt;11; d++) { b+=real(NormalizedKernel[d]*NumCoeffs[d]); den+=real(NormalizedKernel[d]*DenC[d]); } for(int c = 0; c&lt;11; c++) { NumCoeffs[c]=(NumCoeffs[c]*den)/b; } free(TCoeffs); return NumCoeffs; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload