diff options
author | FreeArtMan <dos21h@gmail.com> | 2021-07-14 07:36:08 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2021-07-14 07:36:08 +0100 |
commit | 8a9c3cda26a77301610d16c2e7da9703d897382d (patch) | |
tree | cdf31bd2b283642e083a0097e33f918df3a3be38 /md | |
parent | 03f1138dac549e505bf16a84a0bbaffd34ed5b87 (diff) | |
download | md-content-8a9c3cda26a77301610d16c2e7da9703d897382d.tar.gz md-content-8a9c3cda26a77301610d16c2e7da9703d897382d.zip |
Update fir post for filter type table and code examples
Diffstat (limited to 'md')
-rw-r--r-- | md/writeup/calculate_fir_coefficients_with_c.md | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/md/writeup/calculate_fir_coefficients_with_c.md b/md/writeup/calculate_fir_coefficients_with_c.md index e364eb4..295fa3f 100644 --- a/md/writeup/calculate_fir_coefficients_with_c.md +++ b/md/writeup/calculate_fir_coefficients_with_c.md @@ -12,7 +12,8 @@ and was able to use them just from tools that take as input parameters and give as output coefficients. Now time came just to calculate FIR from ground up. Also C is perfect to do stuff without abstraction levels hiding details, and can be ported to other languages and platforms. Lets calculate filter coefficients -with windows method. There is few more but those for later. +with windows method. Theory is not explained, there is a lot of playlists +on youtube and lecture notes online to check on that. ## Implementation @@ -29,7 +30,7 @@ MathJax = { </script> Low pass ideal impulse response -Ideal impulse response of the filter +Ideal impulse response for low-pass filter $$2f_c\frac{sin(n \omega_c)}{n \omega_c}$$ @@ -75,6 +76,64 @@ for (i=0;i<filter_N;i++) { How to use calculated coefficients [/writeup/dsp_lp_filter.md#toc-6](/writeup/dsp_lp_filter.md#toc-6) +## Ideal impulse response + +| Filter type| Ideal impulse response | +|---|---| +| Lowpass | $2f_c\frac{sin(n \omega_c)}{n \omega_c}$ | +| Highpass | $-2f_c\frac{sin(n \omega_c)}{n \omega_c}$ | +| Bandpass | $2f_c\frac{sin(n \omega_2)}{n \omega_2}-2f_c\frac{sin(n \omega_1)}{n \omega_1}$ | +| Bandstop | $2f_c\frac{sin(n \omega_1)}{n \omega_1}-2f_c\frac{sin(n \omega_2)}{n \omega_2}$ | + +### Lowpass + +```c +for (i=0;i<filter_N;i++) { + arg = (double)i-(double)(filter_N-1)/2.0; + h[i] = omega_c * sinc(omega_c*arg*M_PI); +} +``` + +### Highpass + +```c +for (i=0;i<filter_N;i++) { + arg = (double)i-(double)(filter_N-1)/2.0; + if (arg == 0.0) { + h[i] = 0.0; + } else { + + h[i] = cos(omega_c*arg*M_PI)/M_PI/arg + cos(arg*M_PI); + } +} +``` + +### Bandpass + +```c +for (i=0;i<filter_N;i++) { + arg = (double)i-(double)(filter_N-1)/2.0; + if (arg==0.0) { + h[i] = 0.0; + } else { + h[i] = (cos(omega_c1*arg*M_PI) - cos(omega_c2*arg*M_PI))/M_PI/arg; + } + } +``` + +### Bandstop + +```c + for (i=0;i<filter_N;i++) { + arg = (double)i-(double)(filter_N-1)/2.0; + if (arg==0.0) { + h[i] = 0.0; + } else { + h[i] = sinc(arg*M_PI) - omega_c2*sinc(omega_c2*arg*M_PI) - omega_c1*sinc(omega_c1*arg*M_PI); + } + } +``` + ## Windowing methods Here is most common windows for window methods that can give you better results then naive rectangular windows filter. @@ -253,3 +312,6 @@ https://ccrma.stanford.edu/~jos/st/FFT_Simple_Sinusoid.html https://ccrma.stanford.edu/~jos/st/Example_Applications_DFT.html https://ccrma.stanford.edu/~jos/st/Use_Blackman_Window.html http://www.iowahills.com/A7ExampleCodePage.html +Digital Signal Processing: A Practical Approach by (Emmanuel Ifeachor, Barrie Jervis) + + |