Beruflich Dokumente
Kultur Dokumente
Blog
NMath Tutorial videos
Chebyshev Filters in C#
There are three classes of widely used IIR (recursive) filters in signal processing: Butterworth,
Chebyshev, and elliptical. In this article I will give a short introduction to the Chebyshev filter,
present a code implementation, and end with a usage example. The Butterworth filter was
discussed in a previous blog article.
Chebyshev filters come in two flavors defined by either allowing ripple in the pass-band (type 1) or
ripple the stop-band (type 2). We will only discuss the type 1 filters here, as the type 2 filters are
rarely used. Type 1 Chebyshev filters trade-off steeper roll-off with ripple in the pass band and in
the limit of zero ripple, mimic Butterworth filters. Simply put, the more ripple allowed in the
passband, the steep roll-off the filter achieves.
Chebyshev filters derive their name from Chebyshev polynomials [1]. Finding Chebyshev
polynomials for a given order represent a computational challenge, and when computed often
exhibit various numerical instabilities (often overflow) if not done properly. For an excellent review
and comparison of computational techniques for computing Chebyshev polynomials see this paper
by Wolfram Koepf. Here, we will side step the entire computational issue, as legions of engineers
have done before us, and simply look up the Chebyshev polynomials, by order, in a switch
statement. Because Chebyshev filters with an order n above 10 or 12 would be unusual, this table
look-up approach can be considered, practically speaking, complete.
Wikipedia has a excellent overview article discussing the Chebyshev filter, so Ill refer you there for
a background treatment of Chebyshev filtering theory.
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
Categories
.NET (11)
Best Practices (5)
Search
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
Case Studies (2)
Chebyshev Filters
CenterSpace (16)
The gain expression for Chebyshev filters has a very similar structure to Butterworth filters. As with
the Butterworth filter, there are the three familiar design parameters, DC Gain, cutoff frequency
f0, and filter order n, with an additional parameter, epsilon, for specifying the desired pass-band
ripple.
Corporate (6)
Customer Stories (2)
Events (1)
Excel (6)
Marketing (5)
MKL (2)
NMath (60)
NMath Tutorial (16)
NMath Premium (12)
NMath Stats (27)
The Tn signifies a Chebyshev polynomial of order n. So for example when n = 2, it happens that
Tn = 2*x*x - 1, where when substituted into the gain equation we replace x with f/f0. The
ripple factor can be equated to pass-band ripple in Db with the equation:
Statistics (5)
Student version (1)
Support (4)
Syncfusion (2)
Theory (2)
Uncategorized (6)
Video (1)
Passband ripple in Db
n*log(n)) operation.
But before we do that, we need a way to find the Chebyshev polynomials of a given order n. To
that end Ive build a simple method that returns a Chebyshev polynomial given the order; if the
requested order is larger than the look-up table, a NotImplementedException is thrown. This
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
Visualization (9)
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
look-up approach can easily be extended as far as would be needed for most any practicable
Chebyshev filter.
An excellent on-line resource for Chebyshev polynomials, or any other integer sequence can be
found at OEIS, the Online Encyclopaedia of Integer Sequences. If you wish to delve into computing
the coefficients of Chebyshev polynomials, a good review of techniques can be found here.
Chebyshev Filter
The following code implements the Chebyshev filter, following the three steps mentioned above:
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
[1] FFT(signal), [2] FFT(signal)*G(f), [3] IFFT.
private DoubleComplexVector ChebeshevFilter( DoubleComplexVector signal,
double sampleFrequency, int order, double f0,
double ripple, double DCGain )
{
// Get the Chebyshev polynomial
Polynomial T = ChebyshevPolynomial( order );
int N = signal.Length;
// Remove DC offset
signalFFT[0] = 0;
if ( f0 > 0 )
{
// Filter
System.Threading.Tasks.Parallel.For( 1, N / 2, i =>
{
double binFreq = binWidth * i;
double gain =
DCGain / ( Math.Sqrt( ( 1 + Math.Pow( T.Evaluate( binFreq / f0) , 2.0
) ) ) );
signalFFT[i] *= gain;
signalFFT[N - i] *= gain;
} );
return signal;
}
Filtering Example
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
To test the Chebyshev filtering code above, Ive generated a test signal which is the sum to two
sinusoids of frequences 1 Hz and 8 Hz. For comparison, this is the same test signal I used to test
the Butterworth filter in my previous post. The test signal is sampled at 25 Hz and then filtered
using a third order Chebyshev filter with a frequency cut-off of 1.5 Hz and ripple factor (epsilon) of
0.2.
public void ChebyshevFilterTest()
{
DoubleComplexVector signal = new DoubleComplexVector( 100 );
// Filter
DoubleComplexVector filteredSignal = this.ChebeshevFilter( signal, 25, 3,
1.5, 0.2, 1.0 );
// Display results
Chart chart = NMathChart.ToChart( new DoubleVector(
signal.ToRealDataTable() ) );
chart.Titles[0].Text = "Input signal, sampled at 25 Hz";
chart.ChartAreas[0].AxisY.Title = "Input signal magnitude";
chart.ChartAreas[0].AxisX.Minimum = 0;
Chart chartfft = NMathChart.ToChart( new DoubleVector(
filteredSignal.ToRealDataTable() ) );
chartfft.Titles[0].Text = "Filtered signal";
chartfft.ChartAreas[0].AxisY.Title = "Filtered signal magnitude";
chartfft.ChartAreas[0].AxisX.Minimum = 0;
NMathChart.Show( compositeChart );
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
This example test code, using NMath charts, generates the following chart of the unfiltered and
filtered signal side by side.
-Happy Computing,
Paul
[1] Chebyshev is a transliteration of a Russian name and in the past has been variously spelled as
Chebychev, Tschebyscheff, Tchebysheff and Tchebichef.
Tags: c# chebyshev, c# chebyshev filter, c# data filtering, c# iir filtering, chebyshev filter, nmath
filtering, vb.net chebyshev, vb.net chebyshev filter
Leave a Reply
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]
CenterSpace Blog Blog Archive Chebyshev Filters with NMath - CenterSpace Blog
Name (required)
Website
Submit Comment
http://www.centerspace.net/blog/chebyshev-filter-csharp/[13/04/2015 16:04:48]