![]() I won't get into the details much further on FIR filters and their pro's and con's as this tutorial focuses more on designing filters fast and efficiently with the aid of Octave. Typically, in FIR filter design the length of the filter will need to be specified. ![]() You can guess and check until the filter matches your expected bandwidth and cutoff requirements, but this could be a long and tedious process. The equation below is an efficient way to compute a reasonable starting length. After trying the calculated N, one can then tweak N or parameters which make up N to meet filter specifications. The code above gives us the following response:īut if we zoom in we will see that the attenuation at 10kHz is greater than 3dB: Using the Octave/Matlab code below, we can see how to design a lowpass filter with a bandwidth of 10kHz and a cutoff of 15kHz using Octave's built in fir1 function, which is well documented here close all *Designing an FIR filter length to be odd length will give the filter an integral delay of (N-1)/2. Gives us a filter which closely matches our speicfications The bandwidth of the filter is always specified to the -3dB point, so in the first iteration of design our filter has a smaller bandwidth than specified (somewhere less than 9kHz). We can see from the first figure that the attenuation in the stopband exceeded our specifications, perhaps we can tweak the attenuation and passband frequency to enhance the design. Let's simulate how it works by adding the code below to the first bit of code we looked at. Plot((-0.5:1/4096:0.5-1/4096)*Fs,20*log10(abs(fftshift(fft(xf,4096)))))Īs we can see in Figure 4, we have the time domain signals on the left and the frequency domain on the right. Hc = fir1(round(N)-1, f,'low') can be modified as such: The fir1 function can also be used to produce notch filters, high pass filters, and bandpass filters by replacing these lines:į = /(Fs/2), may need to be specified with two arguments for bandpass and notch filters as such:į = /(Fs/2), where f1 is the left -3dB edge and f2 is the right -3dB edge The filter (in red) is overlaid onto the plot to show how the filter leaves the sinusoids in the passband and attenuates the signals in the transition and stopband. 'low' can be replaced with 'stop' (notch), 'high' (highpass), 'bandpass' (bandpass)įrom the lowpass filter demonstration above it should be easy to form the coefficients (this is the variable hc in the code) for any filter desired. Once you have calculated the coefficients it is important to scale and quantize them so you can implement your filter in a microprocessor. In part 2 we will get into scaling the coefficients and other steps necessary to put your coefficients into an N-bit microprocessor. ![]() ![]() This is important because without proper scaling you will experience quanitization noise that will affect the frequency response of your filter. Consequently, your design will not match your original specification or the output you simulated in Octave. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |