1 # 15/50us EIAJ de-emphasis filter for CD/DAT
3 # 09/02/98 (c) Heiko Eissfeldt
5 # 18/03/07 robs@users.sourceforge.net: changed to biquad for slightly
8 # License: LGPL (Lesser Gnu Public License)
10 # This implements the inverse filter of the optional pre-emphasis stage
11 # as defined by IEC 60908 (describing the audio cd format).
13 # Background: In the early days of audio cds, there were recording
14 # problems with noise (for example in classical recordings). The high
15 # dynamics of audio cds exposed these recording errors a lot.
17 # The commonly used solution at that time was to 'pre-emphasize' the
18 # trebles to have a better signal-noise-ratio. That is trebles were
19 # amplified before recording, so that they would give a stronger signal
20 # compared to the underlying (tape) noise.
22 # For that purpose the audio signal was prefiltered with the following
23 # frequency response (simple first order filter):
28 # |~10dB _________________
31 # | 20dB / decade ->/ |
33 # |____________________/_ _ |_ _ _ _ _ _ _ _ _ Frequency
39 # So the recorded audio signal has amplified trebles compared to the
40 # original. HiFi cd players do correct this by applying an inverse
41 # filter automatically, the cd-rom drives or cd burners used by digital
42 # sampling programs (like cdda2wav) however do not.
44 # So, this is what this effect does.
46 # This is the gnuplot file for the frequency response of the deemphasis.
48 # The absolute error is <=0.04dB up to ~12kHz, and <=0.06dB up to 20kHz.
50 # First define the ideal filter:
53 T = 1. / 441000. # we use the tenfold sampling frequency
55 OmegaL = 15. / 50. * OmegaU
57 # Calculate filter coefficients
60 B = V0 * tan(OmegaU * T / 2.)
61 A1 = (B - 1.) / (B + 1.)
62 B0 = (1. + (1. - A1) * H0 / 2.)
63 B1 = (A1 + (A1 - 1.) * H0 / 2.)
69 # Ideal transfer function
70 Hi(f) = B0*sqrt((1 + 2*cos(f*O)*D + D*D)/(1 + 2*cos(f*O)*A1 + A1*A1))
72 # Now use a biquad (RBJ high shelf) with sampling frequency of 44100Hz
73 # to approximate the ideal curve:
81 # Calculate filter coefficients
82 A = exp(gain / 40. * log(10.))
84 alpha = sin(w0) / 2. * sqrt((A + 1. / A) * (1. / slope - 1.) + 2.)
85 b0 = A * ((A + 1.) + (A - 1.) * cos(w0) + 2. * sqrt(A) * alpha)
86 b1 = -2. * A * ((A - 1.) + (A + 1.) * cos(w0))
87 b2 = A * ((A + 1.) + (A - 1.) * cos(w0) - 2. * sqrt(A) * alpha)
88 a0 = (A + 1.) - (A - 1.) * cos(w0) + 2. * sqrt(A) * alpha
89 a1 = 2. * ((A - 1.) - (A + 1.) * cos(w0))
90 a2 = (A + 1.) - (A - 1.) * cos(w0) - 2. * sqrt(A) * alpha
100 # Best fit transfer function
101 Hb(f) = sqrt((b0*b0 + b1*b1 + b2*b2 +\
102 2.*(b0*b1 + b1*b2)*cos(f*o) + 2.*(b0*b2)* cos(2.*f*o)) /\
103 (1. + a1*a1 + a2*a2 + 2.*(a1 + a1*a2)*cos(f*o) + 2.*a2*cos(2.*f*o)))
105 # plot real, best, ideal, level with halved attenuation,
106 # level at full attentuation, 10fold magnified error
108 set grid xtics ytics mxtics mytics
110 plot [f=1000:20000] [-12:2] \
113 20 * log10(OmegaL/(2 * pi * f)),\
114 .5 * 20 * log10(V0),\
116 200 * log10(Hb(f)/Hi(f))
118 pause -1 "Hit return to continue"