# NewGamePhysics.Physics.ButterworthFilter Class Reference

Implementation of a numerical biquad (tweaked) Butterworth filter. More...

List of all members.

## Public Member Functions
| ButterworthFilter (ButterworthFilterType filterType, double sampleRate, double cutoffFrequency)
| Create an instance of a biquad Butterworth filter.
| ButterworthFilter (ButterworthFilterType filterType, double sampleRate, double cutoffFrequency, double resonance)
| Create an instance of a biquad Butterworth filter.
double[] | Calculate (double[] samples)
| Calculate the filtered samples from the input samples.
## Static Public Attributes
static double | DefaultResonance = Math.Sqrt(2.0)
| Square root of 2.

## Detailed Description

Implementation of a numerical biquad (tweaked) Butterworth filter.

Source: http://www.musicdsp.org/archive.php?classid=3#38 and Source: http://www.musicdsp.org/archive.php?classid=3#128 and Source: http://en.wikipedia.org/wiki/Digital_biquad_filter

Definition at line 37 of file ButterworthFilter.cs.

## Constructor & Destructor Documentation

NewGamePhysics.Physics.ButterworthFilter.ButterworthFilter | ( | ButterworthFilterType | filterType,
|  | double | sampleRate,
|  | double | cutoffFrequency |
| ) |  |  |

Create an instance of a biquad Butterworth filter.

Parameters:

  | filterType | The type of the filter.
  | sampleRate | The sample rate (Hz) to assume.
  | cutoffFrequency | The cutoff frequency (Hz). Theoretical value 0 Hz to SampleRate/2, but practical is only SampleRate/4.

Uses default resonance of sqrt(2).

Definition at line 85 of file ButterworthFilter.cs.

    00088                                     : this(filterType, sampleRate, cutoffFrequency, DefaultResonance)
    00089         {
    00090         }

NewGamePhysics.Physics.ButterworthFilter.ButterworthFilter | ( | ButterworthFilterType | filterType,
|  | double | sampleRate,
|  | double | cutoffFrequency,
|  | double | resonance |
| ) |  |  |

Create an instance of a biquad Butterworth filter.

Parameters:

  | filterType | The type of the filter.
  | sampleRate | The sample rate (Hz) to assume.
  | cutoffFrequency | The cutoff frequency (Hz). Theoretical value 0 Hz to SampleRate/2, but practical is only SampleRate/4.
  | resonance | A resonance amount. Allowable range is from sqrt(2) to 0.1 only. At sqrt(2) resonance is 0dB, smaller values increase resonance.

Definition at line 109 of file ButterworthFilter.cs.

    00114         {
    00115             // Check input parameters
    00116             if (sampleRate <= 0.0)
    00117             {
    00118                 throw new ArgumentException("The sample rate cannot be zero or negative.");
    00119             }
    00120
    00121             if ((cutoffFrequency <= 0.0) ||
    00122                 (cutoffFrequency > (sampleRate / 2.0)))
    00123             {
    00124                 throw new ArgumentException("The cutoff frequency should be greater than " +
    00125                     "zero, but less than half the sample rate");
    00126             }
    00127
    00128             if ((resonance < 0.1) || (resonance > DefaultResonance))
    00129             {
    00130                 throw new ArgumentException("The resonance parameter should be in " +
    00131                     " the range 0.1 to sqrt(2)");
    00132             }
    00133
    00134             // Calculate filter parameters
    00135             switch (filterType)
    00136             {
    00137                 case ButterworthFilterType.LowPass:
    00138                     this.InitializeLowPass(sampleRate, cutoffFrequency, resonance);
    00139                     break;
    00140                 case ButterworthFilterType.HighPass:
    00141                     this.InitializeHighPass(sampleRate, cutoffFrequency, resonance);
    00142                     break;
    00143             }
    00144         }

## Member Function Documentation

double [] NewGamePhysics.Physics.ButterworthFilter.Calculate | ( | double[] | samples | ) |

Calculate the filtered samples from the input samples.

Parameters:

  | samples | Sample array. Minimum size of array is 3 samples.

Returns:
  Filtered sample array. First two samples are 0.0.

Definition at line 192 of file ButterworthFilter.cs.

    00194         {
    00195             if (samples == null)
    00196             {
    00197                 throw new ArgumentNullException("samples");
    00198             }
    00199
    00200             int nMax = samples.Length;
    00201             if (nMax < 3)
    00202             {
    00203                 throw new ArgumentException(
    00204                     "samples",
    00205                     "The samples array must contain at least 3 values.");
    00206             }
    00207
    00208             double[] filteredSamples = new double[nMax];
    00209             filteredSamples[0] = 0.0;
    00210             filteredSamples[1] = 0.0;
    00211             for (int n = 2; n < nMax; n++)
    00212             {
    00213                 filteredSamples[n] =
    00214                     this.a1 * samples[n] +
    00215                     this.a2 * samples[n - 1] +
    00216                     this.a3 * samples[n - 2] -
    00217                     this.b1 * filteredSamples[n - 1] -
    00218                     this.b2 * filteredSamples[n - 2];
    00219             }
    00220
    00221             return filteredSamples;
    00222         }

## Member Data Documentation

double NewGamePhysics.Physics.ButterworthFilter.DefaultResonance = Math.Sqrt(2.0)`[static]`

Square root of 2.

Definition at line 42 of file ButterworthFilter.cs.

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/Physics/ButterworthFilter.cs