Understanding the DSP module
Note: This article needs a number of diagrams to finish it off. If after reading this you think you can create appropriate diagrams (.jpg or .gif files) then please send them to me.
Understanding the DSP Modules Operation.
What we describe as our Digital Signal Processing (DSP) module performs the task of transforming the series of numbers obtained from the A/D, into the amplitudes and phases of each relevant frequency that makes up the signal. The series of numbers obtained from the A/D is called a Pulse Code Modulated (PCM) data stream.
The objective of this series of articles is not only to give an understanding of how our DSP module works but to describe it mathematically accurately. While this is fully sufficient for it to be programmed, we have maintained all descriptions to requiring no more than general high school mathematics.
This first article describes the principles without mathematics. The next at http://humanise.org/demining/underlying-maths demonstrates the exact mathematics. The last at http://humanise.org/demining/averaging documents the requirements of the averaging part of the process.
In most other DSP programs, the task is accomplished using a Fast Fourier Transform (FFT) algorithm. The FFT is generally the most efficient method of finding all of the frequencies that exist over a range of frequencies and obtaining the amplitudes of these.
A good introductory article based on the FFT is found at http://people.bath.ac.uk/masjpf/CDP/operpvoc.htm
This project differs from most other DSP programs in that in this project we know almost exactly each of the frequencies that we're interested in, previous to any calculations, and further, the number of actual frequencies of interest is comparatively small. All we need do is measure the phase and amplitude of these specific frequencies, each over a very narrow frequency range.
In order to get the most accurate and efficient processing the method documented here can be described as a Discrete Fourier Transform (DFT) approach. The Discrete Fourier Transform similarly analyses a string of samples by searching separately for each discrete target frequency.
In the particular case of our use of the algorithm, it is better described as a digital implementation of a Two Channel Lock-in Amplifier. In the general case of DFTs, there is no requirement for the computer to have a reference waveform available that is exactly synchronised with the waveform of interest. In our case we have this as we created the initial transmit signal in the first place. In the two channel lock-in amplifier, if not directly available, this is obtained using a Phase Lock Loop (PLL). It is a consequence of this similarity that makes the analysis of two channel lock-in amplifiers to be the same as the analysis of our simple algorithm.
Note on AC/DC terminology:
With Electronics we talk about currents being DC (Direct Current) or AC (Alternating Current) or a mixture of both. When a waveform is converted to numbers and graphed on a typical X and Y axis graph, the DC is represented as a shift of the graph on the Y axis while the AC is a continuing alternation on the Y axis without any overall shift.
Throughout the discussion and mathematics on this website we will continue to use the term DC and AC for similar actions on streams of numbers representing waveforms even though there is no actual current still involved. Similarly we assume that the typical X and Y axis graphs exist for each waveform with the Y axis showing the wave's Amplitude and the X axis being used for Time.
Phase and Amplitude
The terms Phase and Amplitude are terms that are used extensively in describing the DSP module and in describing how a metal detector works.
The phase of a waveform is the fraction of a complete cycle corresponding to an offset in the displacement from a specified reference point. It is effectively a measurement of the lag or lead of a waveform compared to a reference waveform except that instead of measuring it in terms of time, it is measured as a fraction of one cycle of the waveform. Consequently, a 10 degree phase shift in a waveform would represent a bigger change in the time of the waveform than a 90 degree phase shift of a waveform that was 10 times faster.
Normally the amplitude of a sine waveform is a measure from the center point between the maximum and minimum value in each cycle to the maximum value. It is half the maximum (peak) to minimum (trough) value. A separate Peak to Peak Amplitude is often also specified which is double the normal amplitude.
Phase Locked Loops (PLL)
To understand the principles of extracting frequency and phase information it is easier to start with understanding a Phase Lock Loop implementation. While we don't have to do this in our initial design, we would if we used an external oscillator for driving the transmit coil.
Assume we have an input signal containing one frequency of interest amongst the various frequencies that are part of this input signal. We first find the current phase of the frequency of interest. We do this by creating internally a waveform of the frequency of interest and then multiplying this with the input signal.
Both the input signal and the internally created waveform are AC only signals. The waveforms are symmetrical about the X axis so that there's no DC component.
Initially, we didn't know the phase so we have to guess to create the internal waveform.
Lets assume that we happened to get it so that the internally created waveform was exactly in phase with the waveform in the input signal. In this case, when the internally created waveform is at its maximum negative value, the waveform in the input signal has a similar negative value. A negative multiplied by a negative is positive. When the internally created waveform is positive, the waveform in the input signal is also positive. A positive multiplied by a positive is also positive. When either waveform is crossing the zero point the other is also crossing the zero point so the output, zero multiplied by zero, is also zero.
Both the negative and the positive parts of the input waveforms create resultant waveform parts that are positive. Consequently the resulting waveform (after the multiplication) now sits above the X axis, alternating between zero and its maximum positive value creating an overall positive DC bias to the result.
Lets assume instead that the internally created sine waveform was exactly 180 degrees out of phase with the waveform in the input signal. In this case when the internally created waveform is negative, the waveform in the input signal is positive. A negative multiplied by a positive is negative. Similarly, when the internally created waveform is positive, the waveform in the input signal is negative which also results in a negative output. Consequently the resulting waveform now sits completely below the X axis creating an overall negative DC bias to the resultant waveform.
Halfway between the 180 degrees out of phase and being exactly inphase, that is, at both 90 degrees before and 90 degree after, the multiplication of the internally created wave with the input signal will result in a waveform that has no DC bias.
We can find any DC bias in the result by averaging the result. If the DC bias in the result is positive we shift the phase of our internally created waveform forward. If the DC bias is negative we shift the internally created waveform back. By continuing to do this we quickly reach a point where the DC bias is zero.
Following this, when the phase of the input waveform changes, we continue to readjust our internally created waveform. Thus the internally created waveform remains at 90 degrees ahead of the waveform of interest within the input. The continuing adjustment is often referred to as locking the internally created waveform to the input waveform.
It should be noted that when you multiply a waveform of one frequency against a waveform of a different frequency or a number of different frequencies, with all frequencies being different, the resultant waveform will not contain any DC bias. As a consequence of this, the above PLL algorithm has effectively locked our internally created waveform to the one frequency of interest in amongst all the frequencies that the input signal contained. The output of this provides a clean signal that synchronised with the frequency of interest from within the input signal, exactly 90 degrees ahead of it, and is without the addition of all the other frequencies or noise within the input signal.
The shifting (forward or back) of the phase of the internally created waveform is equivalent to increasing or decreasing the frequency of the internally created waveform. In electronic hardware implementations of the PLL, the internally created waveform is created with a Voltage Controlled Oscillator (VCO). The averaging of the resultant DC voltage bias creates a DC voltage which is used as the control input to the frequency of the Voltage Controlled Oscillator so that VCO follows the frequency of interest in the input waveform.
Phase Locked Loops are very common in electronics. They are now the basis of most radio receivers and they are a central part of most computer communications such as the electronics in a LAN or to connect to the Internet.
Single Channel Lock-in Amplifier
When creating the above internally created waveform with the PLL, it is easy to also create a second copy that is 90 degrees behind the first. This now provides a clean signal that is exactly in phase with the frequency of interest. If we now multiply this second internally created waveform with a second copy of the input signal, then we are multiplying two waveforms that we know are both of the same frequency and are exactly in phase. We can do this and then measure the resultant DC bias in order to find the amplitude of the frequency of interest within the input signal. In this case the amplitude of the resultant DC bias is proportional to the amplitude of the frequency of interest within the input signal
Two Channel Lock-In Amplifiers
In our case we have a reference waveform used to create the Transmit frequency. Without looking at the resulting input waveform we don't know the current phase difference between the reference waveform and resulting input waveform but we know that they will stay with the same phase difference under the same external circumstances.
This is different to the situation with receiving a radio signal or communicating between computers. The oscillator creating a frequency within a radio cannot with certainty create a frequency that we know is exactly the same as the frequency at the radio station. Although only a fraction out, over time, without some form of lock in, the overall phase of the internally created frequency and the externally created one is almost certain to drift.
We can use our reference frequency to find the phase and frequency of the waveform in the input with an algorithm that is more efficient than the Phase Lock Loop. We simply create a second waveform that is 90 degrees ahead the reference waveform. That is, the cosine of the reference sine waveform.
Note that our reference waveform and our cosine waveform are just based on the transmitted frequency. There is no continuing adjustment algorithm as in the PLL. We can in our case use these directly, even though we don't know the phase relationship between them the frequency of interest in the input signal.
We multiply the reference waveform by the input waveform and average the result in order to measure any resulting DC bias. We call this DC bias measurement the Inphase Component.
We also multiply a copy of the input waveform to the second internally created waveform that is 90 degrees ahead of the reference waveform. Again we average the result in order to measure any resulting DC bias. We call this DC bias measurement the Quadrature Component.
Using these two measurements it is easy to convert these two values to the actual amplitude and phase of the frequency of interest in the input waveform. The phase can now be easily specified as being in reference to the Transmit signal. The maths for this, including the derivation of the maths is covered completely in the next article at
http://humanise.org/demining/underlying-maths
You will find a number of external articles on Two Channel Lock-in Amplifiers at the following address:
http://www.cpm.uncc.edu/lock_in_1.htm
Particularly note the lock-in amplifier article at the following address:
http://www.cpm.uncc.edu/programs/LIA_Primer.pdf
That's the type of documentation I'd like for this project.