alexgrover

Template For Custom FIR Filters - Make Your Moving Average

Introduction

FIR filters (finite impulse response) are widely used in technical analysis , there is the simple or arithmetic moving average, the triangular, the weighted, the least squares...etc. A FIR filter is characterized by the fact that its impulse response (the output of a filter using an impulse as input) is finite, this mean that the impulse response won't have infinite outputs unlike IIR filters.

They are extremely simple to design to, even without the Fourier transform, this is why i post this template that will let you create custom filters from step responses. Don't hesitate to post your results.

How It Works

Originally you create your filters from the frequency response you want your filter to have, this is because the inverse Fourier transform of the frequency response is the filter impulse response.

After that step you use convolution (convolution is the sum of the product between the signal and the impulse response) and you will have your filter. But we don't have Fourier transforms in pine so how can we possibly make FIR filters from convolution ? Well here the thing, the impulse response is the derivative of the step response and the step response is the sum of the impulse response, this mean we can create filters from step responses.


Step response of a moving average.

Step responses are easy to design, you just need a function that start at 0 and end up at 1.

How To Use The Template

All the work is done for you, the only thing you need to do is to enter your function at line 5 :

f(x)=> your function

For example if you want your filter to have a step response equal to sqrt(x) just enter :

f(x)=> sqrt(x)

This will give the following filter output :


You can create custom step responses from online graphing tools like fooplot or wolfram alpha, i recommend fooplot.

You can also design your filter step response from the line 14/15/16, b will be your filter step response, just use a, for example b = pow(a,2), then replace output in plot by b and use overlay false, you can also plot step, if you like your step response copy the content of b and paste after f(x) =>.

Filter Characteristics

The impulse response determine how many of a certain signal you want in your filter, this is also called weighting, you can think of filter design as cooking where your ingredients are the the signal at different periods and the impulse response determine how many of an ingredient you must include in the recipe. The step response can also tell you about your filter characteristics, for example :


This one converge faster to the step function, this mean that the filter will have less lag.