[Kst] kdeextragear-2/kst/plugins/pass_filters

Andrew Walker arwalker at sumusltd.com
Wed Apr 14 01:01:35 CEST 2004


CVS commit by arwalker: 

Modification based on tests now that plugins are functional again.


  M +9 -3      filters.h   1.2
  M +9 -5      butterworth_bandpass/butterworth_bandpass.cpp   1.2
  M +5 -5      butterworth_bandstop/butterworth_bandstop.cpp   1.2
  M +6 -2      butterworth_highpass/butterworth_highpass.cpp   1.3
  M +3 -2      butterworth_lowpass/butterworth_lowpass.cpp   1.2


--- kdeextragear-2/kst/plugins/pass_filters/filters.h  #1.1:1.2
@@ -14,5 +14,5 @@
 #define KST_UNUSED(x) if(x){};
 
-double filter_calculate( int iFreqStep, const double inScalars[] );
+double filter_calculate( double dFreqValue, const double inScalars[] );
 
 int kst_pass_filter(
@@ -32,8 +32,11 @@ int kst_pass_filter(
         double outScalars[] ) {
   
+  KST_UNUSED( outScalars )
+  
   gsl_fft_real_wavetable* real;
   gsl_fft_real_workspace* work;
   gsl_fft_halfcomplex_wavetable* hc;
   double* pResult[1];
+  double dFreqValue;
   int iLengthData;
   int iReturn = -1;
@@ -65,4 +68,5 @@ int kst_pass_filter(
             //
             iStatus = gsl_fft_real_transform( pResult[0], 1, iLengthData, real, work );
+            
             if( !iStatus ) {
               //
@@ -70,5 +74,6 @@ int kst_pass_filter(
               //
               for( i=0; i<iLengthData; i++ ) {
-                filter_calculate( i, inScalars );
+                dFreqValue = 0.5 * (double)i / (double)iLengthData;
+                pResult[0][i] *= filter_calculate( dFreqValue, inScalars );
               }
               

--- kdeextragear-2/kst/plugins/pass_filters/butterworth_lowpass/butterworth_lowpass.cpp  #1.1:1.2
@@ -31,8 +31,9 @@ int butterworth_lowpass(const double *co
 }
 
-double filter_calculate( int iFreqStep, const double inScalars[] ) {
+double filter_calculate( double dFreqValue, const double inScalars[] ) {
   double dValue;
   
-  dValue = 1.0 / ( 1.0 + pow( (double)iFreqStep / inScalars[1], 2.0 * (double)inScalars[0] ) );  
+  dValue = 1.0 / ( 1.0 + pow( dFreqValue / inScalars[1], 2.0 * (double)inScalars[0] ) ); 
+  
   return dValue;
 }

--- kdeextragear-2/kst/plugins/pass_filters/butterworth_highpass/butterworth_highpass.cpp  #1.2:1.3
@@ -31,8 +31,12 @@ int butterworth_highpass(const double *c
 }
 
-double filter_calculate( int iFreqStep, const double inScalars[] ) {
+double filter_calculate( double dFreqValue, const double inScalars[] ) {
   double dValue;
   
-  dValue = 1.0 / ( 1.0 + pow( (double)iFreqStep / inScalars[1], 2.0 * (double)inScalars[0] ) );
+  if( dFreqValue > 0.0 ) {
+    dValue = 1.0 / ( 1.0 + pow( inScalars[1] / dFreqValue, 2.0 * (double)inScalars[0] ) );
+  } else {
+    dValue = 0.0;
+  }
   
   return dValue;

--- kdeextragear-2/kst/plugins/pass_filters/butterworth_bandstop/butterworth_bandstop.cpp  #1.1:1.2
@@ -31,11 +31,11 @@ int butterworth_bandstop(const double *c
 }
 
-double filter_calculate( int iFreqStep, const double inScalars[] ) {
+double filter_calculate( double dFreqValue, const double inScalars[] ) {
   double dValue;
-  double dFreq = (double)iFreqStep / inScalars[1];
   
-  dValue = 1.0 / ( 1.0 + 
-           pow( ( (dFreq * dFreq) - (inScalars[1] * inScalars[1]) ) / ( dFreq * inScalars[2] ),
-           2.0 * (double)inScalars[0] ) );  
+  dValue  = dFreqValue * inScalars[2];
+  dValue /= ( (dFreqValue * dFreqValue) - (inScalars[1] * inScalars[1]) );
+  dValue  = 1.0 / ( 1.0 + pow( dValue, 2.0 * (double)inScalars[0] ) ); 
+  
   return dValue;
 }

--- kdeextragear-2/kst/plugins/pass_filters/butterworth_bandpass/butterworth_bandpass.cpp  #1.1:1.2
@@ -31,11 +31,15 @@ int butterworth_bandpass(const double *c
 }
 
-double filter_calculate( int iFreqStep, const double inScalars[] ) {
+double filter_calculate( double dFreqValue, const double inScalars[] ) {
   double dValue;
-  double dFreq = (double)iFreqStep / inScalars[1];
   
-  dValue = 1.0 / ( 1.0 + 
-           pow( dFreq * inScalars[2] / ( (dFreq * dFreq) - (inScalars[1] * inScalars[1]) ),
-           2.0 * (double)inScalars[0] ) );  
+  if( dFreqValue > 0.0 ) {
+    dValue  = (dFreqValue * dFreqValue) - (inScalars[1] * inScalars[1]);
+    dValue /= ( dFreqValue * inScalars[2] );
+    dValue  = 1.0 / ( 1.0 + pow( dValue, 2.0 * (double)inScalars[0] ) );
+  } else {
+    dValue = 0.0;
+  }
+  
   return dValue;
 }





More information about the Kst mailing list