Digital Signal Processing (Part 2)
Turn your ZX Spectrum into an echo machine with sound sampling capabilities using this month's unique project
Echo times of two seconds at a bandwidth of about 7kHz; choice of delay time in intervals of one millisecond; choice of bandwidth allowing over five seconds delay for voice and similar applications; freezing of sounds or phrases up to the delay length set; single shot replay; sequencing of sounds created or captured which may then be shifted in pitch prior to playback manually or using virtually any low frequency oscillator; forwards or backwards playback from memory; and Fourier synthesis of sounds. Seems like a dream effects unit? Well, these are some of the additional facilities now available by adding a digital to analogue converter to the analogue to digital converter described last month. In fact the system contains a number of unique features and because many of the capabilities are generated with software there is remarkably little hardware in addition to the Sinclair 'Spectrum' microcomputer and its usual ancillaries.
For readers who may have missed Part 1 in the July 1983 issue of E&MM we will give a very brief summary of the objectives for the series. First, digital techniques are becoming commonplace and it behoves musicians to have a working knowledge of these techniques. Next, digital processing is becoming increasingly associated with microprocessor techniques, as distinct from hardware manipulation, and our main objective is to encourage exploration of micro techniques using a learning by doing approach. The software developed for the series is completely accessible to the user and additional information is provided with the cassettes containing the programs. Likewise the hardware is made as flexible as possible, particularly at the interfacing level, so that the more experimentally orientated users can add additional parts to suit their specific interests. Last, but by no means least, our emphasis will be on music making techniques as shown by the facilities described above.
The overall arrangement of the signal processing scheme was shown in the Block Diagram in Part 1 but the processing of audio signals should also become clear by reference to the simplified circuit for the Digital to Analogue Controller, as shown in Figure 1. The signal to be treated is connected to J1 and amplified by IC2A using the Gain control, RV2. This amplifier will cope with line level inputs as well as most microphones. After amplification the signal is split two ways with part going to IC2B which connects with the analogue to digital converter described last month. This puts the signal into the memory of the microcomputer where it may be manipulated to provide a variety of effects, for example, delaying the signal in memory to produce an echo. After manipulation, the digital information has to be converted back to analogue form using, believe it or not, a digital to analogue converter which is described later. The reconstituted analogue signal returns, via a low pass filter, to IC2C which again allows the signal to be split. For repeat echo, and similar effects, a proportion of the signal may be re-cycled using the feedback control, RV3, connected to IC2B. The treated signal may also be mixed with the original signal by means of RV4 and IC2D. The output of the latter is connected to an amplifier. The Digital to Analogue Controller described above is in fact a fairly conventional 'front end' of the type found on most digital and analogue delay units. Another feature often found on digital units is the HOLD push button, S2, which is used for 'freezing' samples in memory. In the current design, however, it should be observed that this push button connects with one of the inputs of Port C of the 8255 PPI and so its function may be varied, by the software, to suit particular requirements.
The signal from the microprocessor, via the D to A converter need not originate from a signal applied to the input at IC2A. For example, in the A to D system described in Part 1 the program allowed samples of sound to be stored on cassette. Now these samples may be replayed from cassette and the signals will come via the memory of the micro direct to the D to A converter. In this situation only IC2C and IC2D are in use. We may also generate waveforms mathematically - more on this next time - and again only the D to A signal path is used.
In view of the growing use of digital processing techniques it is worth mentioning some of the main features of digital to analogue converters in respect of their influence on performance/quality. Perhaps the first consideration is the number of bits used. The early digital delay units were based on 8 bits, as are the majority of low cost microcomputers available today. An 8 bit converter can only provide 28 (256) discrete steps whereas an original analogue signal will have infinite resolution. The difference between an original signal and the digitised reconstitution is shown in Figure 2. The black area between the voltage of the digital output and the original analogue voltage, shown by the smooth line, is known as the quantisation error and it manifests itself in much the same way as white noise in analogue systems. A little thought will make it obvious that if the width of the step is decreased then the 'volume' of the error (noise) will be reduced. In fact it can be proved that the maximum signal to noise ratio of a digital converter is equal to 6dB times the number of bits. Thus an 8-bit converter will give a signal to noise ratio of 48dB. This may seem very low but it is better, or comparable to, many recordings and AM broadcasts.
The choice of converter is not governed by the word (bit) size of the microprocessor. For example, we could use a companding 8-bit digital to analogue converter, as employed in the E&MM 'Digital Delay' and 'Transpozer' projects, and thus provide a theoretical 72dB signal to noise ratio. In other words such a converter has a performance comparable to a 12-bit D to A device and maintains a 35dB S/N ratio over a 35dB signal input range. This companding type DAC is not, however, very convenient for some of the applications provided with this project. The alternative would be to use, say, a straight 12-bit DAC and many such devices are designed for easy interfacing to eight bit micros. Such a converter would nevertheless reduce the sampling rates - which we cannot afford to do with the 'Spectrum' - and it would also effectively halve the amount of free memory available for storage or treatment. In view of these latter problems we have kept to the normal 8-bit type since they are capable of providing satisfactory quality for many situations.
We have stressed the point that the theoretical signal to noise ratio for a DAC represents the best performance that could be obtained and there are several aspects of conversion which can detract from its performance. The most serious is the lack of headroom in the conversion processes with the result that overloading immediately causes clipping and invariably this will result in severe distortion as modulation products are formed (this may be verified with the unit described in this article since it contains a precise overload indicator). There are also other sources of noise in digital conversion and most of it is of high frequency. The result is that although a digital effect unit may have a measured signal to noise ratios of, say, 72dB in practice it may not sound any better than an analogue unit with a S/N ratio of some 60dB.
The actual digital to analogue converter system used is shown in Figure 3. The data bits come from Port A of the 8255 PPI on the interface board described last month. The ZN 425 used has an on-chip voltage reference whose output at pin 16 is connected to the reference input at pin 15. C5 is for decoupling. The output of the ZN 425 goes to the non-inverting amplifier built around IC2. This has a fixed gain of about 1.55 to produce about 15mV per step, or about 3V8 full scale. RV1 is provided so that the offset of the op amp may be cancelled out and this is necessary when the converter is used for synthesiser control applications. In the latter event the D to A output is taken to a separate controller where, amongst other things, the output is further amplified to give 83.33 mV/step, ie., 1 step per semitone.
Signal overload indicators are provided on the digital inputs thus ensuring a very accurate response. IC 4 is connected to the two high bits and so the green LED, D2, will illuminate when these two bits are 'ON'. When lit it means that three quarters of the maximum signal input is present and so there is less than 3dB of headroom left prior to clipping. IC 3 is connected to the highest seven bits and so when the red LED, D1, illuminates the input is either clipping, or within one step (0.39% of total signal capability) of clipping.
Output 2 of Port C of the 8255 goes to the comparator IC 5 to generate a positive going gate pulse of about 10V5. Input 4 of Port C is used to accept the 'HOLD' input from the D to A Controller. These latter items are located on the D to A PCB so as to facilitate their connection to the PPI on the interface board.
When a signal is converted to digital form it may be represented as shown in Figure 4, that is, a series of pulses whose number will depend on sampling rate while the width of the pulse depends on conversion time. When this same signal is output from a D to A converter the waveform is continuous, as shown by Figure 5, since its output remains constant until new digital data is supplied. The waveform therefore contains high frequency components, which are related to the sampling frequency, and these components have to be removed by low pass filtering to leave the smooth waveform, shown by the dotted line in Figure 5. Removal of these high frequency components is essential, irrespective of the sampling rate, since even if they are not audible they can create problems with audio equipment, such as overheating of speakers. Filtering becomes even more important when some of the output is fed back into the analogue to digital converter for repeat effects and the like. In the latter circumstances the higher frequencies can form cross products with the sampling frequency to produce sounds within the audio spectrum which are not harmonically related to the signal input.
It will be evident from the foregoing that a filter with a steep cut-off will allow the widest signal bandwidth. The circuit diagram for a 24dB/octave filter used in the D to A Controller is shown in Figure 6. It is based on the CEM 3320 voltage controlled filter IC produced by Curtis Electromusic Specialties. It is a low noise, low distortion device and its use greatly simplifies design as well as providing some useful features for the user. A single potentiometer, RV1, allows the cut-off frequency to be adjusted anywhere between 20Hz and 20kHz whereas most digital effect units often only provide one output filter with a fixed cut-off frequency. The latter approach may be somewhat lower in cost but they are often restrictive in use. For example, the delay time is a function of memory capacity and sampling rate and in many units the latter is reduced to provide a long delay. If, therefore, only one filter is used then it must be set to limit bandwidth for this slowest sampling rate whereas the bandwidth could be increased for shorter delays. Similarly, manufacturers usually set the cut-off frequency of the filter significantly lower than dictated by sampling theory this being a trade off between cut-off rate and the type of signals that may be encountered. For some signals the filter cut-off could be set higher. In the software controlled system described in this article we have the capability to alter sampling rates over a wide range and so a variable filter is especially useful.
Another feature of the CEM 3320 is that it contains a separate gain cell whose output is connected to the input of the filter and this facility is often used to control resonance. In the present application resistor, R16, feeds a proportion of the output signal to the gain cell and by applying a current, via R17, the filter will oscillate at, or close to, its cut-off frequency. The current is obtained by closing switch S1 which connects +12 volts to R17. One of the programs provided allows the measurement of frequency, as described in Part 1, and so by putting the filter into oscillation the user can set the filter to specific cut-off frequency points. This is an extremely useful feature for those wishing to understand the mechanics of digital signal processing.
The final piece of hardware is another filter which is incorporated into the A to D Controller described in the previous issue. It was mentioned at that time that the signal entering the A to D converter should not contain any components with a frequency greater than half the sampling rate. Failure to observe this rule will result in foldover distortion and we will discuss this effect in a later article. The filter used is exactly the same as that described for the D to A converter so that it may be set to provide maximum bandwidth for specific circumstances. Fitting of the filter is only required when the system is used for treatment of audio signals. It does not have to be fitted for the storage oscilloscope nor when the A to D is used for DC or Keyboard sequencing applications. In fact, the filter would be bypassed for the latter.
Construction of the three parts described above is very straightforward so long as the usual care is taken with orientation of the IC's and the electrolytic capacitors.
First, for the Digital to Analogue Converter PCB, whose component overlay is shown in Figure 7. Install and solder the components in order of increasing height. The wire links may be made with unscreened tinned copper wire so long as the links are taut so that there is no likelihood of them touching one another. Orientation of the LED's is indicated in Figure 7 by the 'flat' on one side of the component representation which corresponds to the 'flat' on the lens of the LED. The final component to be soldered is the 10-pin Molex connector which should be properly seated onto the PCB. Now carefully check the underside of the PCB for potential shorts caused by solder blobs and splashes. If everything is satisfactory then solder the fifteen wires at the rear of the board. 1/0.6mm wire is preferred for this step and each piece should be about 6 to 7 cms. long. The D to A PCB is now mounted above the interface PCB using plastic mounting pillars. The pointed end of these pillars go into the four holes in the interface PCB and the D to A board sits on these pillars and is secured with four plastic studs which should be firmly pressed home. Lastly, neatly bend, cut and strip the free ends of the fifteen wires so that they may be neatly soldered to the corresponding holes in the interface board. There are two rows of holes on the latter and those furthest from the edge should be used so as to facilitate other additions. The positions of the holes on the D to A PCB line up with those on the interface PCB but double check the connections by reference to Figure 7 and to Figure 4 of Part 1. Placing the D to A above the interface board has been made in such a way as to allow easy access to the latter if required.
The component overlay for the D to A Controller is shown in Figure 8 and the only additional point to observe is ensuring that the potentiometers are properly seated on the PCB prior to soldering. After installation of the components on the PCB then prepare a piece of 10-way ribbon cable, about a metre long. At one end, six of the wires are soldered to Molex pins and inserted into a 10-way Molex shell. The selection of wires and their sequence is shown by the component overlay of Figure 7 and note that no connections are made to the 'GATE' pin or to pins marked 'NC' and these represent the four unused wires which may be shortened. The other end of the ribbon cable passes through a slot made in the rear of the case and the later should be about 12 to 15 mm wide and in the middle of the case on the curved portion. The free ends of the wire connect up with the appropriate holes on the Controller PCB. These connections are in the same sequence as those on the D to A PCB so there should not be any crossing or twisting of wires. Next place an extra nut on each of the four potentiometers and secure to the panel - the component side of the PCB faces towards the top of the panel. Very little wiring remains: a connection from the points shown in Figure 8 to the corresponding jack sockets: a ground wire to each of the four sockets; a wire from '+12V TO S1' to switch S1 and the return wire to the point marked 'FROM S1'; and a wire from point marked '+5V TO S2' and a return wire to 'HOLD FROM S2'.
Lastly, if the anti-aliasing filter is being installed into the A to D Controller then the components should be installed on the PCB in accordance with the overlay shown in Figure 9. Including power there are seven connections to be made and it will be easier if the wires are connected to the filter PCB prior to using the potentiometer, RV1, to secure the unit to the panel. The power supplies are readily accessible on RV4 (see Figure 6 of Part 1) while the 0V is available on the A to D Controller PCB (see Figure 5 of Part 1) or at the ground of the jack sockets. Wiring of the 'IN', 'OUT', 'RES 1' and 'RES 2' is to switches S4 and S5 which should already be installed in the Controller, the exact connections shown in Figure 6 of Part 1.
To configure the system for treatment of audio signals the units should be set up as follows -
1. The interface remains as in Part 1 and if a printer is available it could be usefully connected up since the programs contain facilities for plotting and printing of the waveform in memory, or at least the first few hundred bytes of memory. The A to D Controller should be connected to Channel A on the interface board (normal position).
2. The D to A Controller is connected to the Molex on the D to A PCB (check orientation). At this time set trimmer, RV1, on the latter board to its mid position.
3. Connect a signal source, such as a microphone or musical instrument, to the INPUT of the D to A Controller and turn the GAIN control anti-clockwise. The approximate setting of the GAIN control will quickly become a matter of experience and in use its setting can be adjusted by reference to the LED's on the D to A board. In general the green LED should be 'ON' most of the time but illumination of the red LED should be intermittent and for very short duration. Set the MIX control mid-way at this time so that you will hear both the original and the treated signal. Start with the FEEDBACK control anticlockwise and FILTER f control at about setting 6. The OSC(illator) switch, S1, should be off. The remaining connections are from OUTPUT to an amplifier and from 'TO ADC' to the input of the A to D Controller. The filter on the latter should be switched to 'ON' and the frequency again at position 6 to begin with. The input of the A to D Controller should be set to AC, its attenuator to 2V full scale, and the 'ZERO' and 'f TEST' switches off.
Screened cable should be used for all signal leads, although, if a 'hum' occurs it is likely to be due to a ground loop being formed with the two Controllers. In this event remove the screened wire from one of the plugs making the connection between the two Controllers.
Check that the power is connected to the interface board and the usual connections (power, cassette, TV, etc.) made to the 'Spectrum' and switch on all power simultaneously. The copyright message should appear on the TV screen. If not switch off quickly and re-check connections.
The combination of analogue to digital and digital to analogue converters together with their Controllers provides extremely versatile and flexible hardware. Additionally, the DIGISCOPE 3 programs described fully last month plus the DIGISOUNDER 3 programs this month provide a wealth of software. There is in fact a danger of users being overwhelmed and so discussion is confined to using the 'echo' program on the DIGISOUNDER 3 cassette. This program is ideal since it allows full experimentation of the various controls. Note, however, that these latest programs will only operate with a 48K 'Spectrum'.
With the system connected up as described above load the DIGISOUNDER 3 program by entering LOAD " " followed by ENTER. After a successful load a menu will appear on the screen and selecting "e" will initialise the echo program. The screen will display the messages: 'real time echo'; 'sample rate = 14.8kHz'; 'delay = ms'; and at the bottom a response is required to 'delay (1 to 2000ms)'. The required delay time is entered and after pressing ENTER the screen will now display the delay time and also show the message 'press HOLD to return'. To start with we suggest you enter the maximum delay, ie., 2000 (milliseconds) since the effect of the controls will be most obvious with a high delay time. At any time, however, the delay program may be terminated by pressing the HOLD button on the D to A Controller. If you then re-enter "e" a new delay time may be set. The cassette also contains a routine for altering the sampling rate which in turn will affect the maximum delay time. This and the many other features will be fully discussed in Part 3 but in the meantime you can become familiar with the effect of the various hardware controls including filter settings. Have fun!