# Butterworth Filter PlugIn Tests

### Introduction

The Butterworth PlugIn does not provide an idealised Butterworth filter. Specifically, it is an implementation of the formulae set out in David Winter's book . First, it cannot be guaranteed that these formulae are correct (though there is no reason to suspect otherwise). Second, a digital filter is only an approximation to the ideal "analogue" filter.

The Butterworth PlugIn implements code to calculate coefficients for the filter according to the desired cut-off frequency. These coefficients are then applied to a generic "Direct Form II" implementation of an Infinite Response Filter. See  if you want to learn about Digital Signal Processing.

There are different methods used to calculate the filter coefficients, and it is not specified in Winter which method was used to arrive at the given formulae.

The following tests were performed to verify the response function of the Butterworth PlugIn.

### Method

The Butterworth filter plug-in was tested within the Workstation pipeline. Independent pipeline processes were specially written to generate sine waves and analyse them after filtering.

The sinewave generator created new trajectories with particular labels (e.g. "Test001"). Data points were written to these trajectory with the Z component containing a calculated sine wave. All sinewaves had an amplitude of 1. 50 different sinewaves were generated, at frequencies evenly spaced from 1 to 20 Hz.

All the sinewaves were filtered by the Butterworth plug-in with a cut-off frequency of 10 Hz.

Each sinewave was then analysed with an analyser plug-in. A zero-crossing algorithm was used to determine individual cycles of the sinewave, and the frequency was calculated from the mean of the time periods between the zero crossings. The r.m.s. value of the sine wave was calculated from all the points in the wave lying between the 3rd zero-crossing from the start, and the third from last crossing point, in order to eliminate the end effects ("ringing") of the filter. The attenuation of the signal (from the signal of amplitude 1) was calculated using the formula

Attenuation = 20 * log10( RMSAmplitude * sqrt(2) );

Results from the analysis were output to the processing pipeline log file.

A third plug-in was written to finally collate the data from the log file, and generate a text file suitable for import into Mathcad, where final analyses were made.

This procedure was performed with no filtering stage, to check the analysis stage, and for both the unidirectional (single pass) filtering, and for bi-directional filtering (with a second pass in the 'reverse time' direction).

### Analysis

The frequencies of the generated waves and the corresponding filtered waves were compared, to ensure no non-linear distortions were introduced by the filter. The differences between the generated frequencies and the analysed frequencies were found by subtraction, for both the unidirectional and the bi-directional filters. The overall error was expressed as the standard deviation of the individual frequency errors. A graph of the frequency errors was plotted to see if any frequency dependent trend was detectable.

The unfiltered attenuation mean and standard deviation were calculated to test the correct functioning of the analysis process.

Finally, the attenuations of the sinewaves of different frequencies were plotted against the equivalent "ideal analogue" filter. The ideal filter formula is straightforward in the uni-filtered case:- Where the Order N = 2, and ohmega-c is the cut-off frequency.

However, in the bi-filtered case, although the filter can be considered 4th order, it is really two applications of the same second order filter, i.e. the uni-filtered formula squared :- rather than the 4th order Butterworth with N = 4. As stated in Winter, the cut-off frequency is shifted by a factor of 0.802 to achieve a -3 dB cut-off at the frequency equivalent to the uni-filtered cut off.

### Results

The original data, as output in the Workstation log can be viewed in the following links.
Unfiltered Data
Uni-directional Filtered data
Bi-directional Filtered data

These data were analysed and displayed using Mathcad - the document can be viewed as a PDF file if you want more details.

Mean and Standard Deviations of Frequency Errors

 Mean (Hz) Standard Deviation (Hz) Unfiltered 0.019 0.014 Uni-filtered 0.021 0.017 Bi-filtered 0.019 0.014

Graph of frequency errors vs. frequency Unfiltered attenuation

Mean = 0.0001 dB   Standard Deviation = 0.004 dB

Attenuation (in dB) of the Uni-directional filtered data in comparison with the 'ideal analogue' Butterworth filter Attenuation (in dB) of the bi-directional filtered data in comparison with the 'ideal analogue' 2nd order Butterworth filter squared. Comparison of the Uni-directional filtered data and the Bi-directional filtered data. ### Conclusions

The frequency errors showed very low values - less than 2% of the minimum frequency. In addition, the same trends were shown by the frequency errors of unfiltered wave forms in comparison with the filtered wave forms. This indicates that the frequency errors seen are introduced by the sinewave generation and analysis processes, rather than by the filtering process.

The attenuations, as expected, do not match exactly those of the ideal Butterworth equation. However, the uni-directional filter does match the ideal closely, up to the -3 dB cut-off point (where the two plots cross) and after that drops away with a sharper frequency response than the ideal filter. In fact, the digital filter attenuates less in the pass bad, and more in the stop band, and has a sharper cut-off than the idealised Butterworth.

The comparison of the bi-directional filter data emphasises these differences, as should be expected. However it is noticeable that the bi-directional filtered attenuation curve does not pass through the -3 dB cut-off point as is required by the design criteria.

One possibility is that the cut-off frequency factor of 0.802 was chosen analytically from the differences in the ideal Butterworth formulae. However, since the DSP single pass filter has a slightly different form between the pass band and the cut-off frequency, a different factor should be applied.

By inspection of the un-filtered data file, a measured attenuation of approximately -1.5 dB is achieved at a (target) frequency of 8.37 Hz (-1.477 dB). Thus a better cut-off frequency factor might be 0.837, rather than 0.802.

To account for this in using this filter in the bi-directional mode (as would always be expected, to keep different frequency motions in phase) where a factor of 0.802 is already built in, the user might be advised to select their cut-off frequency lower than that truly required, by a factor of about 0.958, though a more rigorous method to choose this figure ought to be applied (specifically, analysis of the digital filter formulae, rather than the analogue formulae).

Changing the filter to have a cut-off of 9.58 Hz gives the following result which gives a -3 dB point closer to the required cut-off of 10 Hz. The original data are also available as a plain text file.

### References

 David A. Winter Biomechanics and Motor Control of Human Movement 2nd Edition New York John Wiley 1990 ISBN 0471509086
 Oppenheim Schafer Digital Signal Processing Prentice Hall, New Jersey 1975 ISBN 0132146355