Monday, November 9, 2020

Designing De-emphasis Digital Filter for Old CDs Part 2 : Frequency Sampling Method

On the previous blog post, we've got a 6th degree polynomial function of de-emphasis curve Equation 1:

fdB(x) = -0.0000029212346025337816x6 +0.00020291497408909238x5 -0.0054888099286801205x4 +0.071110615465301924x3 -0.40078216359333169x2 -0.11354738870338571x

x : frequency (kHz)
fdB(x): filter gain (dB)

Note: Math equations of this article uses MathML and it seems it is displayed correctly only on Firefox (as of November 2020).

This decibel is root power quantity therefore actual gain value f(x) is:

f(x) = 10fdB(x)/20…(2)

Next step is to create filter gain table of equal spacing frequency using this function.

And create the filter, evaluate its frequency response error from original de-emphasis table and choose the best FIR filter tap number M.

 

Example : Calculation of M=9 taps FIR filter coeffs

When sampling frequency==44100 Hz and Desired FIR filter taps M==9,

Frequency sampling index k=0,1,2, .., M-12=4

k=0,1,2,3 and 4

Frequency sampling angle frequency ωk=2πkM :

  • k=0:  ω0 = 0,  freq0 = 0 Hz
  • k=1:  ω1 = 2π/9,  freq1 = (44100/2π)(2π/9) = 44100 / 9 Hz = 4900 Hz
  • k=2:  ω2 = 4π/9,  freq2 = (44100/2π)(4π/9) = 44100 * 2 / 9 Hz = 9800 Hz
  • k=3:  ω3 = 6π/9,  freq3 = (44100/2π)(6π/9) = 44100 * 3 / 9 Hz = 14700 Hz
  • k=4:  ω4 = 8π/9,  freq4 = (44100/2π)(8π/9) = 44100 * 4 / 9 Hz = 19600 Hz

Get filter gain on those frequencies Hr(ωk) using Equation (2):

  • Hr(ω0) = f(0) = 1
  • Hr(ω1) = f(4.9) = 0.599479869
  • Hr(ω2) = f(9.8) = 0.419371436
  • Hr(ω3) = f(14.7) = 0.359695479
  • Hr(ω4) = f(19.6) = 0.33620803

Then G(k) is calculated from Hr(ωk) by G(k) = (-1)k Hr(ωk) ……(3) :

  • G(0) = (-1)0 Hr(ω0) = 1
  • G(1) = (-1)1 Hr(ω1) = -0.599479869
  • G(2) = (-1)2 Hr(ω2) = 0.419371436
  • G(3) = (-1)3 Hr(ω3) = -0.359695479
  • G(4) = (-1)4 Hr(ω4) = 0.33620803

FIR filter coefficients h(n) can be calculated by h(n) = 1M{G(0)+2 k=1 (M-1)/2 G(k)cos2πk(n+1/2)M} …(4)

  • h(0) = 0.0303254491484693
  • h(1) = 0.0404812914444444
  • h(2) = 0.0639379770301665
  • h(3) = 0.119171414154698
  • h(4) = 0.492167736444444

And finally, This FIR filter is symmetry shape, therefore h(8) = h(0), h(7) = h(1), h(6) = h(2), h(5) = h(3).

  • h(0) = 0.0303254491484693
  • h(1) = 0.0404812914444444
  • h(2) = 0.0639379770301665
  • h(3) = 0.119171414154698
  • h(4) = 0.492167736444444
  • h(5) = 0.119171414154698
  • h(6) = 0.0639379770301665
  • h(7) = 0.0404812914444444
  • h(8) = 0.0303254491484693

We've got all the 9 FIR coefficient values h(n).

Evaluating Frequency Response of FIR filter

Now one FIR filter coefficients h(n) is available for testing. FIR filter gain of arbitrary angular frequency ω can be calculated using the following equation:

Gain(ω) = k=0 M-1 h(k)e-jkω ……(5)

Real part and imaginary part of (5) can be calculated separately:

Gainreal(ω) = k=0 M-1 h(k)cos(-kω) ……(5r)
Gainimaginary(ω) = k=0 M-1 h(k)sin(-kω) ……(5i)

And FIR filter Gain magnitude is calculated as follows: Gainmagnitude(ω) = Gainreal(ω)2 + Gainimaginary(ω)2 ……(6)

Finally Gain in decibel is: GaindB(ω) = 20log10{Gainmagnitude(ω)} ……(7)

For our M=9 FIR filter, frequency response can be calculated using equation (7):

Frequency(kHz)GaindB(ω)
00
1-0.214929748
2-0.847460501
3-1.855702469
4-3.153141013
5-4.58835657
6-5.939107409
7-6.960958392
8-7.506314657
9-7.624120111
10-7.521831664
11-7.433783042
12-7.52486218
13-7.862458657
14-8.419180318
15-9.081142015
16-9.670162018
17-10.00514702
18-9.997371674
19-9.707880014
20-9.30607583
21-8.974681539
22-8.840811148
Table 1

Comparing to the original de-emphasis table, max error of this FIR filter is 0.87 dB on 7kHz, It is poor and may be M=9 is too small.

Finding Optimal FIR filter taps M

I'd like to have < 0.1 dB error of FIR filter with minimum filter taps. Calculated error from the original table on several M using DesignFrequencySamplingFilter and compared their performance.

Filter taps MMax error from the original table
90.871 dB
170.217 dB
190.140 dB
210.172 dB
230.104 dB
250.118 dB
270.0779 dB
290.0802 dB
310.0795 dB
330.0770 dB
Table 2

From the table 2, M=27 is the most desirable one.

On M=27,  maximum error from the original table is 0.0779 dB on 2kHz.

Resulted linear-phase FIR filter coefficients h(n) of M=27 for 44.1kHz PCM is as follows:

0.00087829953598830856,
0.00073354073461322569,
0.0013059505528472161,
0.00089158366884379073,
0.0022743712962963354,
0.0017509721612062167,
0.0046856769010995523,
0.0049418323357026065,
0.011621996337245248,
0.017825153275235591,
0.034805918374128435,
0.057946349576219941,
0.11652885832464696,
0.48761899385185181,
0.11652885832464696,
0.057946349576219941,
0.034805918374128435,
0.017825153275235591,
0.011621996337245248,
0.0049418323357026065,
0.0046856769010995523,
0.0017509721612062167,
0.0022743712962963354,
0.00089158366884379073,
0.0013059505528472161,
0.00073354073461322569,
0.00087829953598830856


Fig.1 M=27 de-emphasis FIR Filter frequency response

This linear-phase de-emphasis FIR filter is available on DSP menu of PlayPcmWin 5.0.79. Source code is https://sourceforge.net/p/playpcmwin/code/HEAD/tree/PlayPcmWin/WasapiIODLL/WWAudioFilterDeEmphasis.cpp

 

 

 Reference

 J.G. Proakis & D.G. Manolakis: Digital Signal Processing, 4th edition, 2007, Chapter 10, pp. 671-678

No comments:

Post a Comment