diff options
author | FreeArtMan <dos21h@gmail.com> | 2021-07-11 12:11:14 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2021-07-11 12:11:14 +0100 |
commit | a8f7d139b814d6da2b95c6731ae9b0da1785c705 (patch) | |
tree | 217a5be319709214846150be5aa2d8648a844b98 | |
parent | 1b5b615c0ffd29e6826e8caf3f0a891f779d06e0 (diff) | |
download | md-content-a8f7d139b814d6da2b95c6731ae9b0da1785c705.tar.gz md-content-a8f7d139b814d6da2b95c6731ae9b0da1785c705.zip |
Update calculate fir
-rw-r--r-- | md/writeup/calculate_fir_coefficients_with_c.md | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/md/writeup/calculate_fir_coefficients_with_c.md b/md/writeup/calculate_fir_coefficients_with_c.md index c8c9552..e364eb4 100644 --- a/md/writeup/calculate_fir_coefficients_with_c.md +++ b/md/writeup/calculate_fir_coefficients_with_c.md @@ -29,16 +29,26 @@ MathJax = { </script> Low pass ideal impulse response -Impulse response of the filter +Ideal impulse response of the filter $$2f_c\frac{sin(n \omega_c)}{n \omega_c}$$ + + ```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); } ``` +Sinc function implementation + +```c +double sinc(double x) { + if (x>-1.0E-5 && x < 1.0E-5) return (1.0); + return sin(x)/x; +} +``` Rectangular window for low pass filter @@ -70,6 +80,12 @@ How to use calculated coefficients Here is most common windows for window methods that can give you better results then naive rectangular windows filter. There is better ways how to calculate filters, but that for laters. +|Name|Main lobe|Stop band attenuation|Window function| +|---|---|---|---| +| Rectangluar | 13dB | 21dB | 1 | +| Hanning | 31dB | 44dB | $0.5+0.5cos(\frac{2\pi n}{N})$ | +| Hamming | 41dB | 53dB | $0.54 + 0.46 cos\frac{2\pi n}{N}$ | +| Blackman | 57dB | 74dB | $0.42+0.5cos(\frac{2\pi n}{N-1}) + 0.08 cos(\frac{4\pi n }{N-1})$ | ### Rectangular ```c @@ -232,6 +248,7 @@ run program [main.lv/writeup/dsp_lp_filter.md](/writeup/dsp_lp_filter.md) [http://git.main.lv/cgit.cgi/code-snippets.git/tree/fir1](http://git.main.lv/cgit.cgi/code-snippets.git/tree/fir1) +https://en.wikipedia.org/wiki/Sinc_function 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 |