Monday 30 December 2013

FIR Filter Frequency Response Calculator

This blog post calculates the FIR Filter frequency response, in terms of gain (magnitude squared in linear units or dB) vs frequency, and the phase (in radians) vs frequency. The calculator takes as input the FIR filter coefficients, which can be complex.

The number of Fast Fourier Transform (FFT) bins can be specified in the appropriate textarea below - if left blank the number of FFT bins will be the filter length rounded up to the nearest integer power of 2. The user specified number of FFT bins must be greater than or equal to the filter length rounded up to the nearest integer power of 2.

Please enter the numbers in the text areas below - one number per line, for each of the Real and Imaginary input textareas (the textareas have already been filled in with some numbers for illustration purposes). There must be no new line after the last number.

Note that if the input is real only, the imaginary input textarea can be left empty (rather than having to fill it with the same number of zeros as there are real inputs, which can be a bit more cumbersome). Conversely, if the input is imaginary only, the real input textarea can be left empty (rather than having to fill it with the same number of zeros as there are imaginary inputs).

Alternatively you can choose to load a CSV file, which must be either a single column of numbers (for a real only input) or two comma-separated columns of numbers - the first line can be a comment line, starting with the character #.

There is the option of specifying a sampling frequency below - setting this to a non-zero value will result in the x-axes of the FIR response plots being set to the frequency as opposed to the frequency bin index. Leaving this field blank will result in the x-axes of the plots being set to the FFT bin index.

For plotting purposes, you can select between the following units: complex response i.e. real and imaginary, magnitude, magnitude squared and dB units, using the drop-down box below. For each bin, the dB is calculated as $10\times log_{10}(|FFT|^2)$ where $|FFT|^2$ is the magnitude squared value of the FFT for that bin.

There is a checkbox which allows you to center the zero frequency (i.e. DC component) of the spectrum. If the DC component is centred then the frequency indices that exceed half the sampling frequency will be set to negative values.

To calculate the FIR Filter response, press the button labelled "Calculate FIR Response" below - the results will populate the textarea below labelled "FIR Response", with two comma separated columns - the first column being the frequency (in bin index or Hz) and the second column being the PSD estimate (in dB or linear units). The first line of this textarea will be a comment line starting with character #, and describing the two columns. One can copy and paste the results from this textarea to a text file if so desired. In addition, graphs of the FIR filter response will be plotted.

Once you have pressed the "Calculate FIR Response" button to display the PSD, you can zoom in onto the plot. Note that there are two graphs representing the same data - the lower smaller graph is an overview graph representing the data in its entirety, while the larger graph is the main graph which will represent the zoomed in subsection. You can zoom by selecting sections from either the overview graph or the main graph. To completely undo the zooming operations, simply press the "Calculate FIR Response" button again.

If you change inputs to a smaller number of filter taps, press the calculate button twice for the results to take effect. Alternatively, you can simply reload the page, then fill in the input textareas.



Real Input
Imaginary Input



Number of filter taps is ..


Enter number of FFT bins for obtaining response:-


Enter sampling frequency (optional):-





FIR Gain and Phase Response:-
FIR Gain Response

Linear

FFT bin

Linear

FFT bin




FIR Phase Response (radians)
Phase

FFT bin

Phase

FFT bin



1 comment:

  1. The information you have posted is very useful. The sites you have referred was good. Thanks for sharing..
    calculator

    ReplyDelete