There is a reference de-emphasis equation on this page (Thanks miguelito-san) : https://forums.stevehoffman.tv/threads/cd-dat-with-pre-emphasis-how-to-de-emphasize-correctly.88541/
This decibel is root power quantity therefore actual gain magnitude value T(f) is:
Note 1: Math equations of this article uses MathML and it seems it is displayed correctly only on Firefox (as of November 2020).
Note 2: It seems 0.00005 and 0.000015 of equation 1 means 50 microseconds and 15 microseconds respectively and it is called 50/15 microsec emphasis.
On this article, equation (2) is used to create frequency sampling FIR digital filter.
Calculation steps are very similar to Part 2.
Example : Calculation of M=9 taps FIR filter coeffs using equation
Following is the procedure to design a linear-phase FIR filter using frequency sampling method. All the following calculation can be performed using Excel spreadsheet.
When sampling frequency==44100 Hz and Desired FIR filter taps M==9,
Frequency sampling index
We design de-emphasis filter for CD, therefore PCM sampling frequency = 44100Hz.
Frequency sampling angle frequency and its respective frequency is:
Get filter gain on those frequencies using Equation (2):
Hr( ) = T(4900) = 0.60004356ω 1 Hr( ) = T(9800) = 0.420524967ω 2 Hr( ) = T(14700) = 0.361602897ω 3 Hr( ) = T(19600) = 0.336724814ω 4
Then G(k) is calculated from
G(0) = Hr((-1) 0 ) = 1ω 0 G(1) = Hr((-1) 1 ) = -0.60004356ω 1 G(2) = Hr((-1) 2 ) = 0.420524967ω 2 G(3) = Hr((-1) 3 ) = -0.361602897ω 3 G(4) = Hr((-1) 4 ) = 0.336724814ω 4
FIR filter coefficients h(k) can be calculated by
h(0) = 0.030212113446082472 h(1) = 0.040656939222222181 h(2) = 0.063594885887469199 h(3) = 0.11899203499978166 h(4) = 0.49308805288888891
Finally, this FIR filter is symmetry (linear phase), therefore h(8) = h(0), h(7) = h(1), h(6) = h(2), h(5) = h(3).
h(0) = 0.030212113446082472 h(1) = 0.040656939222222181 h(2) = 0.063594885887469199 h(3) = 0.11899203499978166 h(4) = 0.49308805288888891 h(5) = 0.11899203499978166 h(6) = 0.063594885887469199 h(7) = 0.040656939222222181 h(8) = 0.030212113446082472
We've got all the 9 FIR filter coefficients h(n) where n=0, 1, 2, ..., 8
Evaluating Frequency Response of the FIR filter obtained
Now one FIR filter is available for testing. FIR filter gain of arbitrary angular frequency ω can be calculated using the following equation:
Equation (5) is complex number, which provides more info than we'd like to have (we need only frequency-gain response of the filter: the frequency-phase response is known to be linear with 4 samples of delay, this means frequency-phase error is zero for all frequencies when output signal is shifted by 4 samples to align to input signal). Real part and imaginary part of (5) can be calculated separately:
And the FIR filter Gain magnitude is calculated as follows:
Finally Gain in decibel is:
For our M=9 FIR filter, frequency response can be calculated using equation (7). Using the reference equation (1), desirable gain of any frequency can be calculated, it is possible to compare gain values at as many frequency points as you wish. I compared 10Hz to 22040Hz semitone step frequency points and created Fig.1.
Fig.1. 9 taps FIR de-emphasis filter frequency response.
Comparing to the original de-emphasis table, max error of this FIR filter is 0.878 dB on 7360Hz, It is poor. The filtering quality can be improved by increasing M.
Searching the optimal FIR filter tap number M
FIR Filter Taps M | Max Error (dB) |
9 | 0.878 |
15 | 0.1704 |
17 | 0.115 |
19 | 0.0631 |
21 | 0.0522 |
23 | 0.0231 |
25 | 0.0272 |
27 | 0.00882 |
Table 1: FIR Filter taps and max error
Fig.2 : Frequency Response of FIR Filter, taps=19 note: frequency axis is logarithmic.
Fig.3 : Frequency Response of FIR Filter, taps=27 note: frequency axis is logarithmic.
Fig.4 : Gain Error of FIR Filter, taps=27
From the Table 1,
- If the max error should be below 0.1 dB, use 19-tap FIR filter.
- If the max error should be below 0.01 dB, use 27-tap FIR filter.
De-emphasis FIR Filter Coefficients for 44.1kHz PCM data
19-tap linear-phase FIR filter coefficients h(k) of max error < 0.1 dB is as follows:
0.0022333652179533105,
0.0027676001211334594,
0.0042218013139663415,
0.0065438712761329912,
0.011312237381544295,
0.01877355043394098,
0.03398288954901494,
0.059120380386441337,
0.11593361915957012,
0.49022137032060437,
0.11593361915957012,
0.059120380386441337,
0.03398288954901494,
0.01877355043394098,
0.011312237381544295,
0.0065438712761329912,
0.0042218013139663415,
0.0027676001211334594,
0.0022333652179533105,
27-tap linear-phase FIR filter coefficients h(k) of max error < 0.01 dB is as follows:
0.00031102739649091732,
0.00036885685453166665,
0.00057659816229764602,
0.00082952248115418167,
0.001449970925925961,
0.0022387507393955598,
0.0039420948394406248,
0.0063363475292175873,
0.011215231698621361,
0.018685854350970088,
0.033951734838472802,
0.059076192885731141,
0.11592376177923121,
0.49018811103703697,
0.11592376177923121,
0.059076192885731141,
0.033951734838472802,
0.018685854350970088,
0.011215231698621361,
0.0063363475292175873,
0.0039420948394406248,
0.0022387507393955598,
0.001449970925925961,
0.00082952248115418167,
0.00057659816229764602,
0.00036885685453166665,
0.00031102739649091732,
Performing de-emphasis filtering to the pre-emphasised sound file using sox
With sox, it is possible to use those FIR filter coefficients rather direct fashion to filter the 44.1kHz PCM sound files. The following examples inputs inFile.flac and apply 27-tap de-emphasis FIR filter and output it as outFile.flac:sox inFile.flac outFile.flac fir 0.00031102739649091732 0.00036885685453166665 0.00057659816229764602 0.00082952248115418167 0.001449970925925961 0.0022387507393955598 0.0039420948394406248 0.0063363475292175873 0.011215231698621361 0.018685854350970088 0.033951734838472802 0.059076192885731141 0.11592376177923121 0.49018811103703697 0.11592376177923121 0.059076192885731141 0.033951734838472802 0.018685854350970088 0.011215231698621361 0.0063363475292175873 0.0039420948394406248 0.0022387507393955598 0.001449970925925961 0.00082952248115418167 0.00057659816229764602 0.00036885685453166665 0.00031102739649091732
This is an excellent job! Is there a way of using your 27 taps FIR filter with software like sox of ffmpeg? Thansk!
ReplyDeleteHi I created FIR Filter app for FLAC files, FIRFilterConsole https://sourceforge.net/p/playpcmwin/wiki/FIRFilterConsole/
DeleteAdded sox command example on the article.
Delete