Richard Evans - 2015-08-04

I thaught some people might like to know more about what my program actually does.

The basic idea, for DolbyB, was to build a software equivilent of the noise
reducer described in this article:
http://www.keith-snook.info/wireless-world-magazine/Wireless-World-1975/Wireless%20World%20Dolby%20noise%20reducer.pdf

This article gives a circit diagram of a DolbyB encoder/decoder, and also describes how it works. So I wrote software equivalents of most of the parts of the circuit.

A few things I didn't do.

The Dolby circuit feeds a bit of audio into the gain controll voltage.
I think this is just to get around a problem with the analoge circuit. As the audio waveform goes up and down, in an analoge circuit, this changes the voltage across Vgs, and that causes a bit of distortion.
However this doesn't need to happen in a digital circuit, I just didn't include the audio in my calculation of the FET resistance.

I left out the ocilator etc. used to put a test tone on a tape, and then adjust the levels on playback.

I left out the 19Khz filter, used to supress the pilot tone when taking the input from an fm tuner.

High and Low pass filters

Much of the circuit involves high and low pass RC filters. To implement these I started with the following Wikipedia articles about RC filters:

https://en.wikipedia.org/wiki/High-pass_filter
https://en.wikipedia.org/wiki/Low-pass_filter

These describe how to create an alpha value for the filter, and then do a bit of mathematics on the sample values. The result is a good emulation of an RC filter.
There are however 2 problems they don't seem to mention in the Wikipedia
articles.

1: The filters tend to be at slightly the wrong frequency, in other words fc for the filter is not correct. The error is not huge, but it is significant. From more resarch I found that this is one of the problems with digital filters. However I figured that the error must be related to the ratio of fc and sample rate. My logic was that if you doubled fc, but you also doubled the sample rate, then you would effectivly end up designing the same filter.
So my solution was to work out corrections an put them into tables. So I work out the value of fc/<SampleRate>, and put that into a function which looks up the correction. In this way I got my filters to always be at the right frequency.

2: The sample rate needs to be high compared to fc. Otherwise the filter either doesn't work well, or doesn't work at all. Again I found that this is another issue with digital filters. So basically if the filter needed to have a high value for fc, then I had to upsample the audio to a higher sample rate. I did this by repeating each sample several times. Then I down sampled again, after the filter, by taking the average of several samples.

For DolbyB this is only an issue with the sliding filter, which can go up to a
very high fc. For DolbyC this will also be an issue for the Spectral Scew filter.
The DolbyC anti anti saturation filter will probably work at 44.1khz, but I can't
be sure untill I finish writing it.

Stricty speaking, when changing the sample rate, a low pass filter should
be used. However I would have needed to use a very sharp filter, and this
would have been hard to design, and would have slowed the program down a
great deal, and had some effect on the audio.

I figured that because I am sampling down exactly the same samples that I am sampling
up, a filter is probably not necessary. There aren't any problems that I can hear in
the audio, so I concluded that I was probably right and that a filter was not
necessary here.

FET resistance

Another big problem was how to calculate the resistance of an FET. The Dolby
circuit uses the resistance of 2 FETs (one for each channel), as part of the
sliding filters. This allows the filters to be changed by a controll voltage,
therefore they can slide up and down.

After much web seaching I found quite a complicated formula for the resistance.
I can no longer find the web page or the full formula, but I remember that I
could greatly simplify it, as a large part was multiplied by Vds.

Vds would be very small in the analog Dolby circuit, and for the digital
circuit, we can actually treat it as 0. Hence that part of the formula became
0, and so could be ignored. I was then left with:

1/rDS = 2IDSS / -Vgs(off) * ( 1- vgs/Vgs(off) + Vds / Vgs(off) )

This just left the problem of finding values for IDSS and Vgs(off).
These are part of the specifcation of an FET.
Looking up the specifications for the FETs listed in the Wireless World
article, there was actually a range of possible values.
However I worked out that the choice of values wouldn't be too critical,
as carrying out the Calibration process described in the Wireless World
article would account for most of the differences in the FETs.

I did however realize that picking values too low, would mean the FET could
not go to such low resistances. This would mean the Dolby sliding filters
could not go to such a high frequency, so the side path could not get rid of
enough high frequencies. This would make the decode slightly lacking in high
frequenies.

I decided on IDSS =6 and Vgs(off) =-4, which meant the resistance
of the FET could go as low as 333 1/3 ohms, which allowed the side path to block
most of the high frequencies.

Diode current & resistance

I quite easily found a formula for the current through a diode.

I = Is * ( e ** (n Vd / Vt ) -1 );

Is is approx. 10 -12 for silicon diodes, at room temperature
(I believe it is 10
-9 for germainium diodes).
e is a standard mathematical constant of approx. 2.71828;
n is 1.0 for an ideal diode.
Vt is about 0.02585 at room temperature.
Vd is the voltage across the diode.

To change this into resistance I just used R=V/I
Deviding Vd by the current.

A tiny complication is that the values get extreme, if Vd is too
low or too high, causing the program to crash. But basically,
If Vd was low, I used 1M ohm instead of doing the calculation.
If Vd was high, it would be a low resistance, but in practice my
program didn't need to do this.
If Vd was somewhere in between, I used the calculation.

Sliding Filters

One problem was deciding how to model the Dolby sliding filters.
They have a resistor and a capacitor in parallel, making them more like
a cross between a potentiometer and a high pass filter.
So when the FET resistance is high, the circuit is more like a potentiometer,
but when the FET resistance is low, the circuit is more like a high pass filter.

I decided that the high pass filter part, effectivly provides another path
for signals that did not get through potentiometer.

So I first attenuate the samples, (depending upon the FET resistance,
this emulates the potentiometer). Then I get everything that did not go through
the attenuater, by subtracting it's output from it's input, and fed that into
a high pass filter (alpha is chosen by the FET resistance). Then I just added
together the output of the attenuator and the output of the high pass filter.

I actually use tables to give an attenuation, and an alpha for the filter,
depending upon the control voltage.

DC correction

I not certain whether this is needed, but there was no harm in adding it.
Basically high pass filters do not pass any dc. Therefore it's possible that
rounding errors might gradually add up, adding a significant, unwanted, dc
component to the output of a high pass filter.

To make sure this didn't happen, I took outputs from the high pass filters,
and fed them into low pass filters, with fc set to a low frequency. Therefore
if there was any dc component in the output of the high pass filter, then
that would pass through the low pass filter. I then simply subtracted the
output of the low pass filter, from the previous output sample (which was part
of the high pass filter). Therefore any drift in the dc output will be corrected.

Gain adjustment

The Dolby circuit takes the output from the side path, and feeds it through
various components, to create a controll voltage. This control voltage
controlls the sliding filter, by feding the controll voltage to the gate
pin of the FET.

To model the gain control circuit, I saw it as a potentiometer, and 2 low
pass filters.

Modeling a diode in series with a resistor is not quite as easy as it sounds,
as the resistance of the diode depends on the voltage across it, but this
depends upon the current through the resistor.
So bascally I used a binary search to find the overall resistance, and I
used that value to create tables.

Input to the circuit is via the resistor and diode in series, with another
drain resistor going to earth. This is effectivly a potentiometer, that
varies because the resistance of the diode, which varies depending upon the
voltage difference. So I created a table giving attenuation depending
upon voltage difference.

The first half of the circuit is also a low pass filter. The input
resistance to this filter is effectivly via 2 resistances in parallel,
one of which is the diode resistor combination. So I created a table
giving alpha for the filter depending upon the voltage difference in
the input.

The second, and last, part of the gain controll circuit is a low
pass filter, but with a diode in parallel with the resistor. I considered
that the diode effectivly changes the input resistance, and therefore
the frequency, of the filter, depending upon the voltage difference.
So I created another table for that, giving alpha for the filter. However I
set an upper limit on the frequency of the filter, to keep the values sane.
I decided that 5Khz was high enough as an upper limit.

Deciding output value

This is a much bigger problem than it may first seem.

When DolbyB is in decode mode, the input to the side path, is connected
to the final output. This is all very well for an analoge circuit, but
doing it digitally, you don't know what sample value to feed into the
side path, as you don't yet know what the final output value will be.

The only way I could see to solve this was a trial and error method.
Basically guess what the output value might be, then run all the
calculations to see if that guess was correct. If not, then refine the
guess and try again. I then came up with a method that usually gets to
the correct value without too many guesses.

The guessing still makes decoding significantly slower than encoding,
but at least it works.

DolbyC

Unfortunately I can't find a detailed description of exactly
what DolbyC does. But I have found enough to make an attempt, and
hopefully there will only be a few details left that I can find by
trial and error.

The folling page gives quite a lot of information:
http://educypedia.karadimov.info/library/212_Dolby_B,_C_and_S_Noise_Reduction_Systems.pdf

From what I have found so far, it looks like there are 4 stages.

Spectal Scew: This is basically a steep filter. On record it cuts down
frequencies above about 10 Khz, and on playback it puts them back again.
I think a Rectngular FIR filter seems to get close to what I need for this.
Although the decode will be a bit of a problem.

High Level Stage: This is basically a lot like DolbyB, but I assume that the
1st high pass filter in the side path is 1/4 of the frequency.

Low level stage: This seems to be a lot like DolbyB, but with different
parameters, to make it respond to much quieter sounds. The main problem
here is that I don't know exactly how much quieter, so I will have to
try and find out through experimentation. Also I think the filter has to
slide more slowly.

Anti Saturation: When the audio is quite loud, anti saturation reduces
the high frequencies slightly, on record, and increases them again on play
back. The anti saturation is removed when the audo is quiet. I think a
reasonable approximation of this could be done with simple RC filters,
and reducing the amount of filtering by taking some of the input as output.

 

Last edit: Richard Evans 2015-08-04