SlideShare a Scribd company logo
1 of 45
Download to read offline
Microcontrolled Real-Time Audio DSP
with ARM Cortex Processors
Pavel Solomein
SID: 1210769
MOD002691 Final Project
Final Project Report
BEng (Hons) Electronics
Supervisor: Dr. Domenico Vicinanza
Submitted: 12 December 2015
ii
Abstract
Applications of real-time audio Digital Signal Processing (DSP) devices in show business
vary from voice effects to guitar distortion. However, most of these effects are controlled in
traditional ways. An alternative way to control sound is to measure distance between two
objects, and use acquired data to influence the DSP. The aim of this work is to develop and
build a real-time DSP device based on the ARM mbed LPC1768 Development Board and
controlled by the ultrasonic range sensor. Device must take analog audio signal, apply echo
effect to it and play back processed audio in real time using a speaker. Range sensor readings
must influence feedback gain of echo effect. Measured distance and feedback gain must be
shown on the LCD display. Relevant topics like delay effect concept and embedded systems
theory are addressed. Hardware components are reasonably selected and interconnection
schematics created. Then software part is developed and circuit is implemented onto the
breadboard. The device is tested by means of auditions (critical listening) and oscilloscope
measurements. Most of the time device behaved as was predicted. Aims of the work were
achieved, as well as design specification. Results are interpreted and such issues as noise and
sound distortion are addressed and recommendations given. Further modification possibilities
are also discussed.
iii
Table of contents
ABSTRACT.............................................................................................................................II
TABLE OF CONTENTS .....................................................................................................III
TABLE OF FIGURES............................................................................................................V
1. INTRODUCTION................................................................................................................1
1.1 Aim of the work ..............................................................................................................................................1
1.2 Order of material............................................................................................................................................2
2. LITERATURE REVIEW ...................................................................................................3
2.1 Delay (Echo) Audio Effect..............................................................................................................................3
2.2 Audio DSPs......................................................................................................................................................3
2.3 Alternative Ways to Control Sound ..............................................................................................................4
2.4 Embedded Systems and LPC1768 Microcontroller.....................................................................................5
3. METHODOLOGY ..............................................................................................................7
3.1 Hardware.........................................................................................................................................................7
3.1.1 Microcontroller .........................................................................................................................................9
3.1.2 Audio input ...............................................................................................................................................9
3.1.3 Audio output .............................................................................................................................................9
3.1.4 Speaker ...................................................................................................................................................11
3.1.5 Range sensor...........................................................................................................................................11
3.1.6 Display....................................................................................................................................................12
iv
3.2 Software.........................................................................................................................................................12
3.2.1 Range sensor initialization and control...................................................................................................14
3.2.2 Display Initialization...............................................................................................................................15
3.2.3 Data averaging ........................................................................................................................................16
3.2.4 Echo effect program and range mapping ................................................................................................17
3.2.5 Main program .........................................................................................................................................22
4. IMPLEMENTATION .......................................................................................................23
5. RESULTS ...........................................................................................................................25
6. ANALYSIS AND DISCUSSION ......................................................................................28
6.1 Noise...............................................................................................................................................................28
6.1.1 Breadboard noise ....................................................................................................................................28
6.1.2 Industrial noise........................................................................................................................................29
6.1.3 Noise leakage..........................................................................................................................................29
6.1.4 Noise accumulation.................................................................................................................................30
6.2 Sound distortion............................................................................................................................................31
7. CONCLUSION ..................................................................................................................33
8. REFERENCES.................................................................................................................. VI
APPENDIX I. IMPLEMENTATION.............................................................................. VIII
APPENDIX II. SOURCE CODE ........................................................................................ IX
APPENDIX III. POSTER ...................................................................................................XII
v
Table of figures
Figure 1. Hardware functional diagram....................................................................................1
Figure 2. Device interconnections schematic ............................................................................8
Figure 3. Simple LM386 op-amp schematic ............................................................................10
Figure 4. Software functional diagram....................................................................................13
Figure 5. Proposed echo effect DSP scheme ...........................................................................18
Figure 6. Modified echo effect DSP scheme ............................................................................18
Figure 7. Photographs demonstrating the display operation ..................................................25
Figure 8. Oscilloscope measurements of audio input/output signals ......................................27
Figure 9. Oscilloscope measurements of the echoed noise......................................................31
Figure 10. Oscilloscope measurements of noise accumulation ...............................................31
Figure 11. Maximum output voltage swing for LM386 op-amp ..............................................31
1
1. Introduction
1.1 Aim of the work
The aim of this work is to develop and build a real-time audio digital signal
processing (DSP) device based on the ARM mbed LPC1768 Development Board (hereinafter
MBED) and controlled by the ultrasonic range sensor.
The device must be able to:
 Take the analogue audio signal from computer’s standard audio output.
 Apply an “echo” effect to the signal and play back processed audio in real time using
a speaker.
 Use the ultrasonic range sensor to measure distance between the sensor and
acoustically reflective surface. Use the acquired distance data to control the feedback
gain for echo effect.
 Show measured distance and feedback amount on the LCD display.
Hardware functional diagram can be seen below (Figure 1)
Figure 1. Hardware functional diagram
2
1.2 Order of material
The material of this work is delivered in the following order:
- Select hardware components, justify the choice, make reasonable interconnections between
components and MBED and produce relevant schematics.
- Develop software code using C++ language for the device to meet specification.
- Test the device, analyse and discuss results, give recommendations and propose further
improvements.
The assembled circuit, like it is presented on Figure 1, is referred to as “Device”
throughout this work.
3
2. Literature Review
2.1 Delay (Echo) Audio Effect
Sound effects play very important role in media in our days. Various sound
processing tools are incorporated in radio, television, recorded music and live performances.
Since the 1970’s recorded music involved a massive amount of sound processing. List of
must-have effects included compression, EQ, delay and reverb. This required a vast number
of knobs and faders provided by an analogue mixing desks (Milner, 2010). Being one of the
most valuable effects, delay is the act of copying a sound and then playing it back after a
pause. If that “copy” of sound is played a short while later, it will sound like and echo (Kirk,
1999). Before the days of digital audio, a common approach to creating this sort of effect was
to use a spare analog tape machine as a generator of delay. Choices of a tape speed were
limited to 2 or 3. Then, tape delays were created. These are tape machines with a loop of tape
inside and an adjustable spacing between a record and playback heads, which gives more
flexibility in timing the delay. Nowadays, digital delays are easily adjustable and very
flexible, and can exist in a pulldown menu of a digital audio workstation (Case, 2007). Using
sound effects and especially delay is very important from the artistic point of view. These
treatments saturate the song, give its own signature and make it “breathe”. Cook (2009) takes
the stance that equally enmeshed with the musical syntax and performances on modern
recordings are the myriad effects created by the digital delay (echo), many of which have
become common in the current lexicon of record making.
2.2 Audio DSPs
When the sound is recorded digitally it becomes a collection of numbers. Therefore
the task of DSP is to manipulate those numbers with a help of mathematical operations to
4
achieve needed result. Nowadays, as contemporary music is likely digital, creation process
relies heavily on such mathematical manipulations. Audio DSP is of specific interest because
manipulating digital audio data is relatively simple. Mathematically, this data is 1-
dimensional array information, representing a function of time (Kamenov, 2014). Using DSP
systems instead of analog devices has many strong advantages. First, DSP’s are
programmable. Hardware can be simply reprogrammed to perform a different task, for
example low-pass filter can be changed to high-pass without any change in hardware.
Second, digital system is much more stable than analog one, since its characteristics does not
change with temperature. DSP’s are also less subjectable to component ageing. Other pros
include repeatability, error correction codes, data transmission and storage, and many more
(Marven, 1993). DSP’s are developing rapidly and satisfy a big demand on the highly
competitive market. For instance, in 2014 Texas Instruments introduced the next-generation
DSP TMS320C5517. New DSP delivers up to 200MHz performance with low power
consumption for demanding applications, such as face detection or voice recognition. It offers
a compelling combination of low stand-by and low active power making it the best choice for
battery-powered, portable systems requiring analytics (ENP Newswire, 2014).
2.3 Alternative Ways to Control Sound
People have thought about and found alternative ways of playing instruments and
controlling sound way back in the era of analogue devices. For instance, using gestural
control to affect the output of electronic instruments is a principle that was already firmly
established in 1919 by the Russian scientist Lev Termen with his “Aetherphone”, later called
“Theremine”. The instrument produces monophonic music with a quasi-sine wave timbre and
is played by moving two hands in the vicinity of antennae controlling pitch and amplitude
(Rowe, 1993). New possibilities arose with the developing of digital technologies, especially
5
DSP’s. Nowadays there is a big interest in developing augmented instruments incorporating
DSP’s. Augmented instruments, also referred to as extended or hybrid instruments, are
acoustic (sometimes electric) musical instruments extended by the addition of several
sensors, providing performers the ability to control extra sound or musical parameters. One of
the examples include the “meta-trumpet”, augmented trumpet that uses several sensors to
extend its classical design. Ultrasound transmitters are placed at the bell of the trumpet and
receivers are placed below and on the side of the performer in order to measure direction and
speed of movement (Miranda, 2006). Progress went even further to develop so-called
alternate controllers. These controllers are not directly modelled on or necessarily inspired by
existing acoustic instruments. This makes a great variety of design possibilities. For example,
“Hands” prototype created by Michel Waisvisz was based on two aluminium plates and
provided sensing of the distance between the hands through time-of-flight ultrasound sensing
in order to control the sound (Miranda, 2006).
2.4 Embedded Systems and LPC1768 Microcontroller
Embedded systems represent a class of dedicated computer systems designed for
specific purposes. The devices that embed them are convenient, user-friendly and dependable
(Li, 2003). A suitable microcontroller must be utilized to build an effective real-time
embedded audio DSP. There is a wide range of various microcontrollers available today,
which are designed for different tasks. However, some specific criteria for the
microcontroller should be met to perform real-time DSP tasks. First, fast multiply and
accumulate (MAC) units are required, as it is required in most audio DSP functions, such as
filtering, FFT, correlation. Second, multiple memory access is needed. Most DSP processors
adopt modified Harvard architectures to allow simultaneous fetch of instructions and data.
Others include optimized instruction set, special program control and effective peripheral
6
interface (Kuo, 2013). If one takes LPC1768 Microcontroller with Cortex-M3 Core by ARM
as a candidate, it can be seen that it is suitable for such applications. It has a pipelining
applied to its instruction fetch, allowing instructions to be executed in parallel, which
improves efficiency and speed. Also, reduced instruction set computer (RISC) approach is
used, which allows to execute code rapidly and keep instructions within one binary word. It
also has relevant I/O interfaces to interact with analog and digital devices (Toulson, 2012).
The importance of sound effects in nowadays media, along with the development of
fast and effective audio DSP’s and demand for devices, which can utilize alternative ways of
controlling sounds, justify the creation of a real-time audio processing device controlled by
the ultrasonic range sensor and based on the LPC1768 Microcontroller with ARM Cortex-M3
Core.
7
3. Methodology
Methodology process is divided into three sections: Hardware, Software and
Implementation. Hardware section describes and justifies all physical interconnections
between device components. Software section explains program code developed to meet the
design specifications. Implementation section clarifies some aspects of mounting the circuit
onto the prototyping breadboard.
3.1 Hardware
This section describes device assembly process. Actual electronic components are
selected and connected to the MBED and between each other. Selection process is justified,
all connections are reasoned and explained, and use of additional components is clarified.
Remarks and precautions are given where necessary. Fully assembled device
interconnections schematic can be seen on the next page (Figure 2). It is followed by a
detailed description, which constantly references to the schematic. All component numbers,
pins and connections mentioned in the description fully correspond to those appearing on the
schematic.
8
Figure 2. Device interconnections schematic
9
3.1.1 Microcontroller
ARM mbed LPC1768 Development Board incorporates LPC1768 chip which is based
on Cortex-M3 core by ARM. This microcontroller (LPC1768) would not be commonly used
for commercial audio processing device, since resolution of its converters is low for such
applications (12-bit ADC and 10-bit DAC). In addition, having only one DAC limits
application to only one audio channel, thus limiting audio signal to be mono (Toulson, 2012).
However, simplicity and flexibility of programming is advantageous for the project.
3.1.2 Audio input
Personal computer (PC) will act as a source for initial audio signal. Standard audio
output of the PC is wired to the MBED analogue input, using cable with 3.5mm mono jack
connector on one side and positive and negative clips on the other. Positive clip is connected
to MBED pin “p15” (analogue I/O of the MBED), while negative is wired to the common
ground.
Audio signal from PC output oscillates around 0V. Since MBED’s ADC is capable of
reading only positive values, all data below 0V would be lost at the MBED input. Therefore,
coupling and biasing circuit is applied to offset the signal to a 1.65V midpoint (Toulson,
2012).
3.1.3 Audio output
Texas Instruments LM386N-1 audio op-amp is chosen to effectively drive a
8500mW speaker. According to the datasheet, LM386N-1 (LM386 later in this work)
typically provides 325mW of power if supply voltage VS = 6V and load resistance RL =
8National Semiconductor Corporation, 2000). It is slightly lower power than required by
10
the speaker, but enough to suit needs of this work. Schematics of the simple amplifier circuit
with minimum parts and Gain = 20 is given in the LM386 datasheet (Figure 3)
Figure 3. Simple LM386 op-amp schematic
National Semiconductor Corporation, 2000)
This option is implemented in the device with some minor changes. First, 250uF
capacitor (see pin 8 on Figure 3) was not available at the time of circuit construction. It was
decided to use closest capacitor value available, which was 220uF (C3 on Figure 2). The
same problem occurred with 0.05uF (50nF) capacitor, which was replaced by 47nF capacitor
available (C4 on Figure 2). Another solution is to use several capacitors in parallel to get
closer to the desired capacitance, because the equivalent capacitance of two capacitors
connected in parallel is the sum of the individual capacitances. However, in order to keep the
circuitry as simple as possible to minimise noise, it was decided to stick to the closest
capacitor values available. Another correction is to use a simple voltage divider instead of
potentiometer at “+IN” pin of the LM386. To get more stable and predicted results, number
of varying factors should be minimised. Potentiometer allows greater flexibility and ability to
control the speaker volume, however in terms of this work stability seems to be more
11
important. Therefore, constant value is preferred over a variable. Voltage divider
implemented have a following equation (Equation 1):
𝑉𝑂𝑈𝑇 =
𝑅6
𝑅5+𝑅6
∗ 𝑉𝐼𝑁 =
1𝑘Ω
1𝑘Ω+ 10𝑘Ω
∗ 𝑉𝐼𝑁 =
𝑉 𝐼𝑁
11
(1)
Where Vout – Signal going from potential divider to op-amp input, Vin – signal
coming from MBED pin “p18”
According to MBED specification, only pin “p18” can act as analogue out, so it is
used as an audio output of the device. Pin 18 is connected to “+IN” pin of the LM386 op-
amp. MBED “VU” pin, which provides +5V USB power supply, is connected to “Vs” pin of
the LM386.
3.1.4 Speaker
“Sparkfun Speaker (8500mW)” is chosen to play back the processed audio signal.
Its negative pin is connected to common ground. Speaker’s positive pin is connected to the
“VOUT” pin of the LM386 op-amp in series with the 250uF capacitor (C3 on the Figure 2)
and in parallel with series of capacitor and resistor (C4 and R7 of Figure 2). These
interconnections are done according to the schematics in LM386 datasheet (National
Semiconductor Corporation, 2000).
3.1.5 Range sensor
“TruSens SRF08 High Performance Ultrasonic Range Finder” is chosen to act as a
range sensor. Its required power supply is 5V, and sensing range is between 3cm and 6m,
which perfectly suits the project needs. Moreover, this sensor uses I2
C bus for
communications, which is supported by the MBED. GND pin of the sensor is connected to
common ground. Serial Data Line (SDA) and Serial Clock Line (SCL) pins of the sensor are
connected to MBED pins “p9” and “p10” correspondingly, as these MBED pins are reserved
for either I2
C or Serial communications. SDA and SCL are also connected to +5V power
12
supply (MBED “VU” pin) through 2 pull-up resistors (R1=R2=1k8on Figure 2), as
recommended by “SRF08” datasheet (TruSens, n.d.). “VCC” pin of the sensor is connected
to +5V power supply. “NC” pin of the sensor remains unconnected. Therefore, the sensor is
prepared to work, and can be used as soon as software part is done.
3.1.6 Display
Adafruit Monochrome 128x32 SPI OLED Graphic Display is chosen to display
feedback and range data. The display has SSD1306 driver chip that communicates by the
Serial Peripheral Interface (SPI), which is supported by MBED (Solomon Systech Limited,
2008). Since display will act as a slave device in SPI communication, “DATA” pin of the
display is connected to MBED pin “p5”, which is reserved for SPI Master Output Slave Input
(MOSI). “CLK” pin of the display is connected to MBED pin “p7”, which is reserved for
Serial Clock (SCK). The wiring of another 3 pins is highly relevant to the software program.
Looking ahead, 3 Pulse Width Modulation (PWM) pins on the MBED are used in the
initialization and service functions in the provided libraries for the display. Thus, choice of
the pins is dictated by the software. Pins “CS”, “RST” and “D/C” of the display are
connected respectively to PWM pins “p24”, “p25” and “p26” of the MBED. “CS” pin is used
for selecting a slave device for communicating. It is not of much concern to this work, as
only one slave SPI device is used. “RST” pin is device reset and is used in the initialization
procedure in a display software library. MBED pin “p6” remains unconnected, since MBED
does not act as a slave in this design.
3.2 Software
Program basement for the project was collected using different sources. As a starting
point for the core part of the project, C++ code examples from the book “Fast and Effective
Embedded Systems Design” (FEESD) are taken (Toulson, 2012). These code pieces include
“echo” effect and SRF08 range finder communication programs. Another source of
13
information is the official developer website of MBED where open source libraries used to
control Adafruit OLED display were found. Some parts were written from scratch, like the 5-
point moving average filter, that averages signal coming from the range finder, or scaling
program that ties range sensor readings to the feedback gain of echo effect. All those
collected pieces of code work fine on their own, however they have to be readjusted and
interconnections have to be made between them to meet a device specification. Full code can
be found in Appendix II. Software functional diagram can be seen on Figure 4 below.
Figure 4. Software functional diagram
14
3.2.1 Range sensor initialization and control
This code is based on the example from FEESD. Range sensor initialization starts
with I2
C class declarations and assigning MBED pins “p9” and “p10” as SDA and SCL
interfaces. According to the datasheet, the default shipped address of the SRF08 is 0xE0. This
address is assigned to the constant “addr” and used later during communications. Pointers
“config_r” and “range_read” of type “char” are declared to address registers and read data.
Variable for the readings “range” of type “float” is declared. This is very useful, because the
amount of echo effect is controlled by a variable of type “float” as well, which makes it easier
to create a correlation range measures and amount of echo effect. The code is provided
below:
I2C rangefinder(p9, p10); //sda, sc1
const int addr = 0xE0;
char config_r[2];
char range_read[2];
The following part is put inside the function (void acquire()), so it can be used across
the program conveniently. Inside the “acquire” function, an infinite loop is declared. Inside
the loop, pointer “config_r[0]” is set to command register “0x00” and “config_r[1]” is set to
“0x52”. According to the datasheet, this will initialize the sensor and make the ranging result
appear in microseconds (us). The amount of microseconds will show how much time it takes
for the beam to reach acoustically reflective surface and come back (considering speed of
sound in air). Microseconds are chosen because of the measure steps which are small enough
to be operated as integers, without any decimal points. It will be more convenient to scale
down integer value to control amount of echo effect, than to deal with a floating point. Then
pointers are used to send command to sensor, using “rangefinder.write”. It takes some time to
complete the ranging. The default and recommended time for completion of ranging is 65ms,
15
so slightly higher waiting time is considered and set to 70ms. After 70ms of waiting, pointer
“config_r[0]” is set to data register “0x02” and sent to the sensor. Right after,
“rangefinder.read” command is given and two-byte range data is written to the “range_read”
pointer. Finally, two 8-byte pieces of the data are concatenated into “range” variable and
program waits for 50ms before beginning a new loop. The code is provided below:
void acquire()
{
config_r[0] = 0x00; //set pointer reg to ‘cmd register'
config_r[1] = 0x52; //config data byte1; result in us
rangefinder.write(addr, config_r, 2);
wait(0.07);
config_r[0] = 0x02; //set pointer reg to 'data register'
rangefinder.write(addr, config_r, 1); //send to pointer 'read range'
rangefinder.read(addr, range_read, 2); //read the two-byte range data
range = ((range_read[0] << 8) + range_read[1]); //Concatenate 2 bytes of data
wait(0.05);
}
3.2.2 Display Initialization
Control of the Adafruit display involves communicating with the libraries. As
previously mentioned, they are open source and can be found on the MBED developer
website (Horman, 2014). The library (Adafruit_SSD1306.h) is declared at the very beginning
of the code (see Appendix II). Display initialization includes creating the SPI master “SPI2”
connected to the “mosi”, “miso” and “clk” pins. Communication frequency is set to 2MHz
and data transmission format is configured. The corresponding code is shown below:
class SPI2 : public SPI
{
public:
SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
format(8,3);
frequency(2000000);
};
};
16
MBED pins “p5” and “p7” are attached to “mosi” and “clk” respectively, which
corresponds to the hardware connections made. Through function “gOled” of file
“Adafruit_SSD1306.h”, pins “p26”, “p25” and “p24” are assigned respectively to “DC”,
“RST” and “CS” interfaces of the display. This corresponds to the hardware connections
made. The only part of the software where functions relevant to the display are used is
“main” program. Thus, used functions are discussed in the relevant chapter.
3.2.3 Data averaging
Moving point average filter, which calculates mean value of 5 last range finder data
samples, is implemented. The corresponding function is called “rangecalc”. This is done to
minimize possible noise disturbances from the range sensor, increase stability and linearity.
Filter incorporates “for” loop, which counts up to 5 and then resets. During each count, range
sensor data acquiring procedure “void acquire()” is called in order to get current range
reading. Acquired data is put to “rng5” point of a filter (“rng5” is 5th
point, therefore “rng4”
would be 4th
point e.t.c), which serves as a pointer for every current variable. However, this
happens at the bottom of a moving average. Current data reading cannot be assigned to the
top point of the moving average, as each next variable copies the previous one. Thus, if put
on top, current variable will fill the whole filter during one count, which will become useless.
Counter wise, first 4 points of moving average filter are assigned (2nd
point to 1st
point, 3rd
point to 2nd
point, 4th
point to 3rd
point and 5th
point to 4th
point) and only then current value is
assigned to the 5th
point. Therefore, on the next count this value will go up to the 4th
point and
a new value would be assigned to the 5th
point, thus making filter work effectively. All points
are summed and put into “rangetot” variable, which is later divided into 5 and put into
“rangeav” variable, providing the mean value of 5 samples. The code is provided below:
17
void rangecalc()
{
float rangetot = 0;
for (int ii= 0; ii<5; ii++) {
acquire(); //Acquire data for averaging
rng1 = rng2;
rng2 = rng3;
rng3 = rng4; //5-point moving average
rng4 = rng5;
rng5 = range;
rangetot = rng1 + //Accumulate samples
rng2 +
rng3 +
rng4 +
rng5;
}
rangeav=rangetot/ 5; //Compute the average of 5 samples
}
3.2.4 Echo effect program and range mapping
The basic idea of creating an echo effect is providing a feedback delay, which makes
a single sound to be repeated a number of times. Each time the signal is repeated it is
attenuated until it decays away (Toulson, 2012). The simple delay unit schematics is
proposed in FEESD. Initially, it is proposed to control the speed of repetition and feedback
gain by external potentiometers (Figure 5). The initial design is modified to meet the project
needs. Variable Time Delay is changed to the constant value of 0.5 and feedback gain
potentiometer is replaced with the range sensor data measurements (Figure 6).
18
Figure 5. Proposed echo effect DSP scheme
(Toulson, 2012)
Figure 6. Modified echo effect DSP scheme
(See original on Figure 5)
To implement the design shown on Figure 6 it is necessary to store previous data
samples and allow a desired amount of them to mix with the present data samples. To achieve
this, sampled data is copied into a large array (buffer), so the feedback data is always
available. The feedback gain determines how much buffer data is mixed with the sampled
data. The length of time between current and previous samples is determined by the size of
buffer, which is controlled by the constant time delay value. “AnalogIn” and “AnalogOut”
19
classes are declared and assigned to “Ain” and “Aout” variables respectively, which
correspond to MBED pins “p15” and “p18”, again, respectively. This is done according to the
connections made in the hardware chapter. Class “Ticker” is declared, as the process will be
triggered by an interrupt. Variables for data processing, delay and feedback are declared as
well as maximum buffer value and counter variable.
Function for echo effect is created (void echo_task()). This procedure starts with
reading 16bit unsigned integer data from input Ain (MBED pin “p15”). Data is normalized
by subtracting “0x7FFF” from it. Hex value “0x7FFF” equals to 32767 in decimal, which is
half the range of 16-bit unsigned integer (2^16 = 65536). Therefore, the signal is normalized
to an average value of zero, so that it oscillates positive and negative, which is needed for the
DSP calculation. Code can be seen below:
data_in=Ain.read_u16()-0x7FFF; //Read data and normalize
buffer[i]=data_in+(buffer[i]*feedback); //Combine current sample with previous
data_out=buffer[i]+0x7FFF; //Output data buffer
Aout.write_u16(data_out); //Write to output
Buffer filling is implemented, where “buffer” array is filled with the current data
sample plus “buffer” multiplied by the feedback. In simple words, current data is blended
with a certain amount of previous data. That amount is controlled by variable “feedback”.
Finally, buffer is compensated for normalizing (“0x7FFF” is added) and written to the output
(MBED pin “p18”). Then control routine for buffer, delay and feedback amount is described.
Program watches if buffer is full (if i>delay). If it is false, then counter counts up. If it is true,
then counter resets (i = 0). Floating point value “delay” is constant, since “delay_pot” is
constant and set to 0.5. Value “MAX_BUFFER” is 14000 by the default, hence “delay” is
14000*0.5 = 7000. Therefore, buffer size is 7000 samples. Finally, “feedback” amount is
calculated (feedback=feedback_pot*0.9). Where “feedback_pot” is feedback gain controlled
20
by the range finder. It is multiplied into 0.9 to prevent the final feedback value from ever
reaching 1. Code can be seen below:
if(i>(delay)) {
i=0;
///// Range mapping code here (see below)/////
//Reset counter
delay=delay_pot*MAX_BUFFER; //Calculate new delay buffer size
feedback=feedback_pot*0.9; //Calculate feedback gain value
} else {
i=i+1;
}
Range mapping routine is simply tying up “rangeav” variable with “feedback”
variable, to make range sensor data to control feedback gain. It is needed to calculate
maximum range value, which will refer to maximum feedback gain value. Max. range value
(Drange) must be convenient in terms of later tests. It must be big enough to test the relation of
feedback and range and not too big at the same time. Therefore, consider Drange = 50cm. This
value must be converted to microseconds, as it is a chosen measure for range sensor. As
already mentioned, readings from the range sensor in microseconds refer to the time it takes
for ultrasonic beam to travel from the sensor, reflect from acoustically reflective surface and
come back. Therefore, knowing the speed of sound in dry air at 20C0
, the time for ultrasonic
beam to travel desired distance (50 cm) is calculated (Equation 2):
𝑇 =
𝐷 𝑟𝑎𝑛𝑔𝑒
𝐶
=
0.5 m
343.21 𝑚/𝑠
= 0.001457 𝑠 = 1457 𝜇𝑠 (2)
Where T – travel time for the ultrasonic beam, Drange – travel distance, C – speed of sound in
dry air at 20C0
21
However, corresponding sensor reading must be twice the travel time, to cover time
that beam takes to travel back (Equation 3):
𝑇2 = 𝑇 ∗ 2 = (1457 ∗ 2) 𝜇𝑠 = 2914 𝜇𝑠 ≈ 3000 𝜇𝑠 (3)
Where: T – travel time for the ultrasonic beam, T2 – total travel time for the ultrasonic beam
Taking 3000 us as a reference point for the maximum range reading, program code is
created. Program checks if current range sensor reading is less than 3000us. If it is true, then
the current value is divided by 3000 and put into “feedback_pot” variable. If it is not true
(current range reading exceeds 3000 us) then “feedback_pot” is kept 1. Therefore, current
range reading is being scaled to the value in range from 0 to 1 and fed into “feedback_pot” to
control the echo effect. In case sensor reading value is greater than 3000 us, “feedback_pot”
variable is protected from overflowing (becoming greater than 1). Such overflowing can
cause distortion at audio output, since feedback value is multiplied into buffer values, as
mentioned before. Thus, being greater than 1, feedback values would cause the buffer data to
reach highest values, which would cause distortion. Code can be seen below:
if (rangeav < 3000) { //Scale feedback if range is less 3000 us
feedback_pot = rangeav / 3000;
} else { //Highest feedback gain if range > 3000
feedback_pot = 1;
}
It is necessary to mention that mapping range readings to a value from 0 to 1 is an
idealistic approach. However, according to the SRF08 datasheet, minimum range
measurement for the sensor is 3 cm (TruSens, n.d.). This means that sensor readings will
never get the value of 0, thus feedback gain value will never reach 0 as well.
Minimum range measurement is calculated in microseconds (Equation 4):
22
𝑇 𝑚𝑖𝑛 = 2 ∗
𝐷 𝑚𝑖𝑛
𝐶
= 2 ∗
0.03 𝑚
343.21
𝑚
𝑠
= 0.000175 𝑠 = 175 𝜇𝑠 (4)
Where Tmin – minimum total travel time for the ultrasonic beam, Dmin – minimum
travel distance, C- speed of sound in dry air at 20C0
Minimum feedback gain value is calculated (Equation 5):
𝐹 𝑚𝑖𝑛 =
𝑇 𝑚𝑖𝑛
3000 𝜇𝑠
=
175 𝜇𝑠
3000 𝜇𝑠
= 0.05833 ≈ 0.06 (5)
Where Fmin – minimum feedback gain value, Tmin – minimum total travel time for the
ultrasonic beam
3.2.5 Main program
The main program incorporates all functions described above and brings them
together in one place for the device to work effectively. First, command to clear the display is
executed. By the default, Adafruit OLED display shows “Adafruit” logo on a start-up, and if
it is not cleared it can prevent necessary information from being displayed. Ticker is attached
to the “echo_task” program, which is responsible for echo effect. The ticker period is 50 us,
therefore its frequency is 20kHz. It means that interrupt will occur every 50 us and
“echo_effect” will be executed 20.000 times a second. This can be thought as a sampling rate
of the DSP. Infinite “while” loop is implemented. First function executed inside a loop is
“rangecalc”, which acquires data from range sensor, averages it and scales “feedback_pot”
value according to that data. Remaining code lines control the display. Initial position on the
display is set (which is 0, 0). Thus, data will be displayed starting in the top left corner of the
23
display. Then actual text to be displayed is written. Range will be displayed at the top
accompanied by the “us” measure after a value with 0 decimal points. Feedback is displayed
at the bottom, incorporating two decimal points in its value. The last command is to display
the selected data. Code can be seen below:
int main()
{
gOled.clearDisplay(); //Clear LCD
s20khz_tick.attach_us(&echo_task,50); //Attach 20khz ticker to the echo task
while (1) {
rangecalc();
gOled.setCursor(0, 0);
gOled.printf(" Range = %.0f us nr n Feedback = %.2fn ", rangeav,
feedback_pot);
gOled.display();
}
}
3.3 Implementation
The device is assembled on a solderless prototyping breadboard based on the
developed schematics (See Figure 2). In fact, two breadboards are used, which are
interconnected with each other to form one bigger breadboard. So when a reference made to a
“breadboard” later in this work, it actually means two adjacent breadboards. Use of a
solderless breadboard provides high flexibility, since components can be readjusted quickly
at any time, which saves time while constructing prototype devices like one discussed in this
work. Power rails on the breadboard are also used to provide power supply and ground to all
parts of the circuit in a convenient way using less wires. “VOUT” pin of the MBED, which
provides 3.3V supply, is wired to the red power rail to give easy access to power supply
across the breadboard. “GND” pin of the MBED is wired to black power rail to provide a
common ground for all components across the breadboard.
Each chosen electronic component has pins attached to it, allowing the component to
be inserted into the breadboard holes easily. MBED and LM386 op-amp are Dual In-Line
24
Packages (DIP’s), so DIP ravine is used on the board to accommodate these. Opposite pins of
DIP’s are not meant to be wired to each other, as they have separate functions. Therefore, the
ravine acts as a border which divides two sides of DIP component into two sections. Audio
input (MBED pin “p15”) is wired to the red binding post with a green cable (goes under the
display). Ground is wired to the black binding post. Use of binding posts is justified by
greater flexibility, when either oscilloscope, sound or power source can be connected through
them easily. Wiring between components on the board is done using simple solid core wires,
with a diameter of 0.644 mm. These cables fit tightly into breadboard’s holes and their
diameter is sufficient for the use in this work, since there are no big currents and maximum
applied voltage is 5 volts. Wires are kept as short as possible to reduce noise and unwanted
fluctuations. MBED is connected to the PC with mini-USB cable. The C++ program is
compiled and downloaded onto the MBED.
25
5. Results
As device is powered up a hissing noise is heard from the speaker. Display initializes
and, after a couple of seconds, range and feedback values are displayed (See Figure 7).
Human hand (which belongs to the researcher) acts as acoustically reflective surface, and is
used to test the ultrasonic sensor. If hand is placed close to the sensor, range and feedback
readings on display are small and noise from the speaker becomes quieter. As hand moves
further from the sensor, readings on the display increase as does noise hiss from the speaker.
The minimum feedback gain achieved is Fmin = 0.06. Sound of the ultrasonic beam, produced
by the range sensor, can be heard. Another noise in form of clicks is heard from the speaker.
The periodicity of clicks corresponds to the periodicity of beam sounds from the range finder.
Photo 1 Photo 2
Figure 7. Photographs demonstrating the display operation
Audio sample was recorded to test the functionality of the device. The sample is a
recording of a person saying “uh”. Recording length is 1 second and it is in mono. This short
audio clip can be thought of as a pulse. It is convenient to use a pulse to test the given device,
as recurring pulses (echoes of the initial pulses) will be clearly heard through the speaker and
seen on the oscilloscope if measured. Laboratory stance with a clamp was utilized to hold a
piece of carton, which acted as acoustically reflective surface. The distance between a piece
of carton and a range sensor was varied to test 7 different range and feedback values, in
26
ascending order. Therefore, 7 feedback gain coefficients were tested (F = 0.06, 0.20, 0.40,
0.60, 0.80, 0.95, 1.00). For each mentioned distance, an audio sample was fed to audio input.
The level of hiss noise has lowered as sound source (PC) was connected.
As observed by the auditions, device functioned according to the predictions. At the
minimum feedback gain (Fmin= 0.06) no echoes can be heard after the pulse. As gain value
rise, echoes become louder and their number increase. At the maximum feedback gain (F =
1.00), audio sample is being repeated many times, while the volume fades away very slow
comparing to the lower feedback auditions. It is necessary to mention that slight distortion of
the output signal was present. The intensity of distortion tend to increase along with the
feedback gain value. However, the output signal is still intelligent to the listener and can be
identified as a male person saying “uh”. The clicking noise mentioned above, along with the
hiss noise, is still present during audio sample playback, however its amount is tolerable.
All mentioned feedback gain device configurations were tested using the oscilloscope
(OSC). Channel 1 of the OSC was connected directly to the audio input red binding post
(thus, in parallel with the audio input) to measure the input signal. Additional wire from the
LM-386 op-amp output was connected to the free binding post, which was wired to the
Channel 2 of the OSC to measure output signal. Grounding from both channels of the OSC
was wired to the black ground bay, where audio input cable ground was already attached. At
the time of measurement, speaker was functioning. The first thing to mention after
connecting the OSC is that noise levels have increased. In addition to hiss and clicks, crackle
noise has appeared. Similar feedback gain configurations were used to play audio sample and
measure the result using OSC. Auditioning results were relatively similar to the ones gathered
without the connected OSC. Exception are high feedback gains 0.95 and 1, when noise
became dominant and audio output was unintelligible. Results of the measuring are presented
on Figure 8 (note that yellow signal is input and blue signal is output).
27
Range = 200us
Feedback = 0.06
Amplitude vs. Time
Range = 595us
Feedback = 0.20
Amplitude vs. Time
Range = 1200us
Feedback = 0.40
Amplitude vs. Time
Range = 1800us
Feedback = 0.60
Amplitude vs. Time
Range = 2385us
Feedback = 0.80
Amplitude vs. Time
Range = 2850us
Feedback = 0.95
Amplitude vs. Time
Range = 3220us
Feedback = 1.00
Amplitude vs. Time
Figure 8. Oscilloscope measurements of audio input/output signals
28
6. Analysis and Discussion
Overall performance of the constructed device is close to the predictions. Minimum
measured feedback gain is equal to the calculated one. However, there are several issues
identified that have to be addressed and explained.
6.1 Noise
There are different types of noise observed at different testing stages. These noise
types include hiss, crackle and noise leakage from another source (from range finder).
Sources of noise can be divided into two classes: internal and external. Parasitic
effects across the breadboard, thermal and shot noise and substrate coupling contribute to the
internal sources of noise. Industrial noise could act as an external source of noise.
6.1.1 Breadboard noise
A basic principle of a breadboard structure is that it is a temporary one, designed to
test performance of electronic circuit. Unfortunately breadboards have excessively high
parasitic resistance, inductance and capacitance levels. This can influence the circuit
behaviour and create noise. Paying equal attention to signal routing, component placement,
coupling and decoupling may help to minimize negative effects. (Jung, p.751, 2004) For
example, components that can influence each other’s work can be moved further apart same
as their transmission lines. Also, length of the cables increase noise. Cables were shortened
even more and noise level decreased.
29
6.1.2 Industrial noise
This noise is common for industrialized areas. It is caused by electric motors, leakage
from high voltage lines and heavy electrical machinery. To avoid industrial noise, power
sources such as fluorescent lights should be avoided at the place where sensitive testing takes
place (Rao p.2, 2010). Testing of the circuit was conducted in an electronics lab, where a lot
of electrical equipment is operating. This fact could have caused hissing noise in the speaker
and have an impact on the results. To minimize industrial noise effect, better insulation of the
entire circuit could be used, for example circuit could be put in a metal box.
6.1.3 Noise leakage
Noise leakage from the range sensor could be heard through the speaker as clicks,
which periodicity is similar to the periodicity of the ultrasonic beam emitted from the range
sensor. Both LM386 audio op-amp and SRF08 ultrasonic range sensor require +5V power
supply (Figure 2). This is supplied by the “VU” pin on the MBED (power from the USB).
Both components are connected to this pin in parallel. Interconnections inside SRF08
ultrasonic range sensor can influence the power common power supply line behaviour. A
reason for that might be poor circuit design which permits substrate coupling. The range
sensor is an integration of a digital and analogue circuitry, which can create substrate
coupling. It might be caused by fast switching of the digital circuitry via common substrate.
High current peaks are drawn from the power supply network, which results in ringing on the
supply lines. This ringing is injected into the substrate in a resistive way through the substrate
contacts. When substrate noise couples into an analog circuit, residing on the same die, it can
severely affect circuit’s performance (Bronckers, 2010). As a result, noise from emitting
ultrasonic beam affects the “VCC” power supply pin of the range sensor, making
30
disturbances for the LM386 op-amp, which uses the same power supply. Solutions for this
problem may include using different range sensor or separated power supplies.
6.1.4 Noise accumulation
Due to the specifics of constructed circuit, there is also a strong concern for
accumulation of noise of any type which is coming into the signal input (MBED pin “p15”)
or appearing somewhere across the circuit. Since one of the main functions of the device is to
produce “echo” effect, this effect can be applied not only to the wanted signal, but to noise as
well. Therefore, unwanted spikes and fluctuations can not only be present, but are multiplied
and repeated several times. According to the design specification, the intensity and power of
those repetitions increase along with the increasing feedback gain value. Echoes of noise
spikes can overlay new spikes and each other, thus creating noise accumulation. The example
of an echoed noise is seen on the OSC measurement (Figure 9). It is seen that there is no
input signal, however output signal is present and has a form of the echoes. On another OSC
measurement the time division is 250ms and the accumulation of noise is seen, where spikes
of various amplitudes follow each other (Figure 10). Both measurements are taken with
highest feedback gain (F=1.00) and without input signal to demonstrate the effect of noise at
the highest feedback gain. Therefore, noise accumulation could contribute to the unpredicted
behaviour of a circuit at high feedback gains (F = 0.95, F = 1.00) observed during OSC
measurements. It can be assumed that additional cables used to connect OSC caused the noise
level to increase, which led to massive noise accumulation (at high feedback gains), which
was unexpected.
31
Figure 9. Oscilloscope measurements of the
echoed noise
Figure 10. Oscilloscope measurements of
noise accumulation
6.2 Sound distortion
Slight sound distortion mentioned in the Results section is relevant to the
characteristics of LM386 op-amp. The distortion can be caused if a signal of excessively high
amplitude is fed into the input of an op-amp. The distortion appears when amplified signal
exceeds permitted maximum output voltage swing of an op-amp. This swing for LM386N-1
op-amp is given in its datasheet (Figure 11). As can be seen from the graph, peak-to-peak
output swing for load resistance RL = 8Ω (speaker resistance) and Vs = 5V (supply voltage,
MBED pin “VU”) equals to approximately 2.55V.
Figure 11. Maximum output voltage swing for LM386 op-amp
National Semiconductor Corporation, 2000)
32
Therefore, maximum input voltage for the designed LM386 op-amp configuration can
be calculated (Equations 6 and 7).
𝑉𝑠𝑤 = 𝑉𝑚𝑎𝑥 ∗
𝑅6
𝑅5+𝑅6
∗ 𝐺 (6)
𝑉𝑚𝑎𝑥 =
𝑅5+𝑅6
𝑅6
∗
1
𝐺
∗ 𝑉𝑠𝑤 =
11Ω
1Ω
∗
1
20
∗ 2.55𝑉 = 1.4025𝑉 ≈ 1.4𝑉 (7)
Where Vmax – maximum peak-to-peak voltage at MBED pin “p18”, R5 and R6 –
voltage divider resistor values at op-amp input, G – op-amp gain, Vsw – maximum output
voltage swing
Therefore, audio signal output from MBED must be kept within 1.4V p-p range
to avoid op-amp saturation which leads to distortion during playback. It is relatively hard to
do, since the initial signal is mixed with its echoes during DSP processing, which makes
signal levels to change unpredictably. The recommendation can be either increasing the value
of R5 resistor to lower the input voltage or decreasing the output signal amplitude from the
signal source (PC) until distortion disappears.
33
7. Conclusion
Aims of this work have been achieved. The device incorporating ARM mbed
LPC1768 Development Board has been built and is able to take audio signal, apply “echo”
effect to it in real time and play it back through the speaker. Although sound from the speaker
is subject to noise, it is still intelligible and applied effect can be clearly heard. Feedback gain
value is correctly controlled by the range sensor measurements. Display is able to show range
and feedback gain values in a correct way. Analysis and discussion of the results showed
weak parts of the device which can be improved to increase sound quality. These
improvements may include transferring the device from prototyping breadboard to Printed
Circuit Board (PCB), applying additional shielding, improving decoupling and controlling the
amplitude of input signal. Further modifications may embrace adding more DSP effects to the
device (such as reverb or pitch correction), using more range sensors to control various
parameters or using external DAC’s to improve sound quality and work with stereo sound.
Microcontroller can be also upgraded to the one with ARM Cortex-M4 core, since it is more
powerful and suitable for real time audio DSP applications.
8. References
Bronckers, S. and Van der Plas, G., 2010. Substrate Noise Coupling in Analog/RF Circuits.
[e-book] Norwood, MA, USA: Artech House. Available through: ebrary; ebrary
<http://site.ebrary.com/lib/anglia/docDetail.action?docID=10393278&ppg=20>
[Accessed 12/9/2015 2:25:23 AM].
Case, A.U., 2007. Sound FX : unlocking the creative potential of recording studio effects. [e-
book] Amsterdam ; London: Amsterdam ; London : Focal. Available through: Primo;
Primo [Accessed 12/10/2015 12:00:09 PM].
Cook, N., 2009. The Cambridge companion to recorded music. [e-book] Cambridge:
Cambridge : Cambridge University Press. Available through: Primo; Primo [Accessed
12/10/2015 12:04:33 PM].
Crecraft, D.I. and Gergely, S., 2002. Analog Electronics : Circuits, Systems and Signal
Processing. [e-book] Jordan Hill, GBR: Butterworth-Heinemann. Available through:
ebrary; ebrary
<http://site.ebrary.com/lib/anglia/docDetail.action?docID=10185890&ppg=318>
[Accessed 12/9/2015 12:20:26 PM].
ENP Newswire, 2014. Power-hungry audio and video analytic applications have met their
match with next-generation ultra-low-power DSP from TI. [e- ]. Available through:
Primo; Primo, [Accessed: 12/10/2015 1:07:07 PM].
Horman, N., 2014. A derived version of the BSD licensed Adafrut GFX library for the
SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C. [on-line]
Available at: <https://developer.mbed.org/users/nkhorman/code/Adafruit_GFX/>.
Jung, W.G., 2004. Op Amp Applications Handbook. [e-book] Saint Louis, MO, USA:
Elsevier Science & Technology. Available through: ebrary; ebrary
<http://site.ebrary.com/lib/anglia/docDetail.action?docID=10128146&ppg=768>
[Accessed 12/9/2015 2:55:51 PM].
Kamenov, A., 2014. Digital signal processing for audio applications. [e-book] Second
edition.. ed. United States? : Anton Kamenov?. Available through: Primo; Primo
[Accessed 12/10/2015 12:43:19 PM].
Kirk, R., 1999. Digital sound processing for music and multimedia. [e-book] Oxford: Oxford
Focal. Available through: Primo; Primo [Accessed 12/10/2015 11:44:43 AM].
Kuo, S.M., 2013. Real-Time Digital Signal Processing Fundamentals, Implementations and
Applications. [e-book] 3rd ed.. ed. Hoboken: Hoboken : Wiley. Available through:
Primo; Primo [Accessed 12/10/2015 2:05:14 PM].
Li, Q., 2003. Real-time concepts for embedded systems. [e-book] San Francisco, Calif.: San
Francisco, Calif. : CMP. Available through: Primo; Primo [Accessed 12/10/2015 2:06:07
PM].
vii
Marven, C., 1993. A simple approach to digital signal processing. [e-book] Texas
Instruments. Available through: Primo; Primo [Accessed 12/10/2015 12:53:43 PM].
Milner, G., 2010. Perfecting sound forever : the story of recorded music. [e-book] London:
London : Granta. Available through: Primo; Primo [Accessed 12/10/2015 11:25:19 AM].
Miranda, E.R., 2006. New digital musical instruments : control and interaction beyond the
keyboard. [e-book] Middleton, Wis.: Middleton, Wis. : A-R Editions. Available through:
Primo; Primo [Accessed 12/10/2015 10:58:28 AM].
National Semiconductor Corporation, 2000. LM386 Low Voltage Audio Power Amplifier.
[on-line] Available at: <http://www.ti.com/lit/ds/symlink/lm386.pdf>.
Rao, B.Y.N. and Anand, K., 2010. Electronics. [e-book] Mumbai, IND: Himalaya Publishing
House. Available through: ebrary; ebrary
<http://site.ebrary.com/lib/anglia/docDetail.action?docID=10415084&ppg=6>
[Accessed 12/9/2015 1:48:48 PM].
Rob Toulson, T.W., 2012. Fast and Effective Embedded Systems Design. [e-book] GB:
Newnes. Available through: dawsonera Name; dawsonera Name [Accessed 12/6/2015
10:04:54 AM].
Rowe, R., 1993. Interactive music systems : machine listening and composing. [e-book]
Cambridge, Mass.: Cambridge, Mass. : MIT Press. Available through: Primo; Primo
[Accessed 12/10/2015 10:46:29 AM].
Solomon Systech Limited, 2008. 128 x 64 Dot Matrix OLED/PLED Segment/Common
Driver with Controller. [on-line] Available at:
<https://www.adafruit.com/datasheets/SSD1306.pdf> [Accessed: 09/12/2015].
TruSens, n.d. TruSens SRF08 High Performance Ultrasonic Range Finder Datasheet. [on-
line] Available at: <http://www.rapidonline.com/pdf/78-1086.pdf> [Accessed:
09/12/2015].
viii
Appendix I. Implementation
ix
Appendix II. Source Code
#include "mbed.h"
#include "Adafruit_SSD1306.h"
//// Display SPI setup
class SPI2 : public SPI
{
public:
SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
format(8,3);
frequency(2000000);
};
};
SPI2 gSpi(p5,NC,p7);
Adafruit_SSD1306 gOled(gSpi,p26,p25,p24);
//// Range sensor initialization
I2C rangefinder(p9, p10); //sda, sc1
const int addr = 0xE0;
char config_r[2];
char range_read[2];
//// Analog Input and Output
AnalogIn Ain(p15); // Analog In at pin 15
AnalogOut Aout(p18); // Analog Out at pin 18
//// DSP Echo Effect Declarations
Ticker s20khz_tick; // Declare Ticker name
#define MAX_BUFFER 14000 // Max data samples
signed short data_in; // Signed input (positive and negative)
unsigned short data_out; // Unsigned output (only positive)
float delay = 0;
float feedback =0;
signed short buffer[MAX_BUFFER]= {0};
int i =0;
//// Variables
float range, rangeav; // Used by Ultrasonic Sensor
float rng1, rng2, rng3, rng4, rng5; // Used to average data from the sensor
float feedback_pot; // Feedback amount controlled by the sensor
float delay_pot = 0.5; // Delay period. Constant. 0.5
//// Function - Range sensor control
void acquire()
{
config_r[0] = 0x00; //set pointer reg to ‘cmd register'
config_r[1] = 0x52; //config data byte1; result in us
x
rangefinder.write(addr, config_r, 2);
wait(0.07);
config_r[0] = 0x02; //set pointer reg to 'data register'
rangefinder.write(addr, config_r, 1); //send to pointer 'read range'
rangefinder.read(addr, range_read, 2); //read the two-byte range data
range = ((range_read[0] << 8) + range_read[1]); //Concatenate 2 bytes of data
wait(0.05);
}
/// Function - Average data acquired from the sensor
void rangecalc()
{
float rangetot = 0;
for (int ii= 0; ii<5; ii++) {
acquire(); //Acquire data for averaging
rng1 = rng2;
rng2 = rng3;
rng3 = rng4; //5-point moving average
rng4 = rng5;
rng5 = range;
rangetot = rng1 + //Accumulate samples
rng2 +
rng3 +
rng4 +
rng5;
}
rangeav=rangetot/ 5; //Compute the average of 5 samples
}
/// Function - Echo Effect
void echo_task()
{
data_in=Ain.read_u16()-0x7FFF; //Read data and normalize
buffer[i]=data_in+(buffer[i]*feedback); //Combine current sample with
//previous samples
data_out=buffer[i]+0x7FFF; //Output data buffer
Aout.write_u16(data_out); //Write to output
if(i>(delay)) {
i=0;
//// Range mapping
//// Form feedback pot depending on sensor readings
if (rangeav < 3000) { //Scale feedback if range is less 3000 us
feedback_pot = rangeav / 3000;
} else { //Highest feedback gain if range > 3000
feedback_pot = 1;
}
//Reset counter
xi
delay=delay_pot*MAX_BUFFER; //Calculate new delay buffer size
feedback=feedback_pot*0.9; //Calculate feedback gain value
} else {
i=i+1;
}
}
//// Main
int main()
{
gOled.clearDisplay(); //Clear LCD
s20khz_tick.attach_us(&echo_task,50); //Attach 20khz ticker to the echo task
//// Infinite loop
while (1) {
rangecalc(); //Calculate range
gOled.setCursor(0, 0); //Set cursor for the display at initial position
gOled.printf(" Range = %.0f us nr n Feedback = %.2fn ", rangeav, feedback_pot);
//Data to display
gOled.display(); //Command to display
}
}
xii
Appendix III. Poster

More Related Content

What's hot

Real-Time Signal Processing: Implementation and Application
Real-Time Signal Processing:  Implementation and ApplicationReal-Time Signal Processing:  Implementation and Application
Real-Time Signal Processing: Implementation and Applicationsathish sak
 
Company profile - Elekso
Company profile - EleksoCompany profile - Elekso
Company profile - Eleksojiwaniaziz
 
Application of digital_signal_processing_in_audio_processing[1]
Application of digital_signal_processing_in_audio_processing[1]Application of digital_signal_processing_in_audio_processing[1]
Application of digital_signal_processing_in_audio_processing[1]Sveris COE Pandharpur
 
DIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEWDIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEWsathish sak
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processingLiving Online
 
Introduction to Digital Signal Processing
Introduction to Digital Signal ProcessingIntroduction to Digital Signal Processing
Introduction to Digital Signal Processingop205
 
3F3 – Digital Signal Processing (DSP) - Part1
3F3 – Digital Signal Processing (DSP) - Part13F3 – Digital Signal Processing (DSP) - Part1
3F3 – Digital Signal Processing (DSP) - Part1op205
 
presentation on digital signal processing
presentation on digital signal processingpresentation on digital signal processing
presentation on digital signal processingsandhya jois
 
Digital Signal Processor
Digital Signal ProcessorDigital Signal Processor
Digital Signal ProcessorParakram Chavda
 
Research perspectives in biomedical signal processing
Research perspectives in biomedical signal processingResearch perspectives in biomedical signal processing
Research perspectives in biomedical signal processingajayhakkumar
 
digital signal processing
digital signal processing digital signal processing
digital signal processing Marmik Kothari
 
Digital Signal Processing
Digital Signal Processing Digital Signal Processing
Digital Signal Processing Sri Rakesh
 
Rloynd ig2 t1 ws
Rloynd ig2 t1 wsRloynd ig2 t1 ws
Rloynd ig2 t1 wsrosstapher
 
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...ijcsa
 
ประเภทของคอมพิวเตอร์
ประเภทของคอมพิวเตอร์ประเภทของคอมพิวเตอร์
ประเภทของคอมพิวเตอร์Moo Fay Kiki
 

What's hot (16)

Real-Time Signal Processing: Implementation and Application
Real-Time Signal Processing:  Implementation and ApplicationReal-Time Signal Processing:  Implementation and Application
Real-Time Signal Processing: Implementation and Application
 
Company profile - Elekso
Company profile - EleksoCompany profile - Elekso
Company profile - Elekso
 
Application of digital_signal_processing_in_audio_processing[1]
Application of digital_signal_processing_in_audio_processing[1]Application of digital_signal_processing_in_audio_processing[1]
Application of digital_signal_processing_in_audio_processing[1]
 
DIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEWDIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEW
 
Digital signal processing
Digital signal processingDigital signal processing
Digital signal processing
 
Introduction to Digital Signal Processing
Introduction to Digital Signal ProcessingIntroduction to Digital Signal Processing
Introduction to Digital Signal Processing
 
3F3 – Digital Signal Processing (DSP) - Part1
3F3 – Digital Signal Processing (DSP) - Part13F3 – Digital Signal Processing (DSP) - Part1
3F3 – Digital Signal Processing (DSP) - Part1
 
presentation on digital signal processing
presentation on digital signal processingpresentation on digital signal processing
presentation on digital signal processing
 
Digital Signal Processor
Digital Signal ProcessorDigital Signal Processor
Digital Signal Processor
 
Research perspectives in biomedical signal processing
Research perspectives in biomedical signal processingResearch perspectives in biomedical signal processing
Research perspectives in biomedical signal processing
 
digital signal processing
digital signal processing digital signal processing
digital signal processing
 
Digital Signal Processing
Digital Signal Processing Digital Signal Processing
Digital Signal Processing
 
Lesson1
Lesson1Lesson1
Lesson1
 
Rloynd ig2 t1 ws
Rloynd ig2 t1 wsRloynd ig2 t1 ws
Rloynd ig2 t1 ws
 
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...
REAL TIME SPECIAL EFFECTS GENERATION AND NOISE FILTRATION OF AUDIO SIGNAL USI...
 
ประเภทของคอมพิวเตอร์
ประเภทของคอมพิวเตอร์ประเภทของคอมพิวเตอร์
ประเภทของคอมพิวเตอร์
 

Similar to Pavel_Solomein_Final_Project_2015

Sean Barowsky - Electronic Normalizer
Sean Barowsky - Electronic NormalizerSean Barowsky - Electronic Normalizer
Sean Barowsky - Electronic NormalizerSean Barowsky
 
Sonar Project Report
Sonar Project ReportSonar Project Report
Sonar Project ReportSumit Sapra
 
Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Editor IJARCET
 
Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Editor IJARCET
 
Co-op Report Nishant Final
Co-op Report Nishant FinalCo-op Report Nishant Final
Co-op Report Nishant FinalNishant Khanna
 
Richard_Final_Poster
Richard_Final_PosterRichard_Final_Poster
Richard_Final_PosterRichard Jung
 
Arduino bộ vi điều khiển cho tất cả chúng ta part 1
Arduino bộ vi điều khiển cho tất cả chúng ta part 1Arduino bộ vi điều khiển cho tất cả chúng ta part 1
Arduino bộ vi điều khiển cho tất cả chúng ta part 1tungdientu
 
DELPH Sonar Advanced Notes
DELPH Sonar Advanced NotesDELPH Sonar Advanced Notes
DELPH Sonar Advanced NotesIXSEA-DELPH
 
[PFE] Design and implementation of an AoA, AS and DS estimator on FPGA-based...
[PFE]  Design and implementation of an AoA, AS and DS estimator on FPGA-based...[PFE]  Design and implementation of an AoA, AS and DS estimator on FPGA-based...
[PFE] Design and implementation of an AoA, AS and DS estimator on FPGA-based...Yassine Selmi
 
Industrial training report
Industrial training reportIndustrial training report
Industrial training reportReshmi R
 
iaetsd Software defined am transmitter using vhdl
iaetsd Software defined am transmitter using vhdliaetsd Software defined am transmitter using vhdl
iaetsd Software defined am transmitter using vhdlIaetsd Iaetsd
 
thesis2005
thesis2005thesis2005
thesis2005Jim Wu
 

Similar to Pavel_Solomein_Final_Project_2015 (20)

Sean Barowsky - Electronic Normalizer
Sean Barowsky - Electronic NormalizerSean Barowsky - Electronic Normalizer
Sean Barowsky - Electronic Normalizer
 
Final paper0
Final paper0Final paper0
Final paper0
 
Sonar Project Report
Sonar Project ReportSonar Project Report
Sonar Project Report
 
Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397
 
Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397Ijarcet vol-2-issue-7-2389-2397
Ijarcet vol-2-issue-7-2389-2397
 
Co-op Report Nishant Final
Co-op Report Nishant FinalCo-op Report Nishant Final
Co-op Report Nishant Final
 
Richard_Final_Poster
Richard_Final_PosterRichard_Final_Poster
Richard_Final_Poster
 
thesis_SaurabhPanda
thesis_SaurabhPandathesis_SaurabhPanda
thesis_SaurabhPanda
 
VoIP-Technologies_T0507
VoIP-Technologies_T0507VoIP-Technologies_T0507
VoIP-Technologies_T0507
 
Arduino bộ vi điều khiển cho tất cả chúng ta part 1
Arduino bộ vi điều khiển cho tất cả chúng ta part 1Arduino bộ vi điều khiển cho tất cả chúng ta part 1
Arduino bộ vi điều khiển cho tất cả chúng ta part 1
 
DELPH Sonar Advanced Notes
DELPH Sonar Advanced NotesDELPH Sonar Advanced Notes
DELPH Sonar Advanced Notes
 
Audio equalizer
Audio equalizerAudio equalizer
Audio equalizer
 
[PFE] Design and implementation of an AoA, AS and DS estimator on FPGA-based...
[PFE]  Design and implementation of an AoA, AS and DS estimator on FPGA-based...[PFE]  Design and implementation of an AoA, AS and DS estimator on FPGA-based...
[PFE] Design and implementation of an AoA, AS and DS estimator on FPGA-based...
 
poster
posterposter
poster
 
Industrial training report
Industrial training reportIndustrial training report
Industrial training report
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
iaetsd Software defined am transmitter using vhdl
iaetsd Software defined am transmitter using vhdliaetsd Software defined am transmitter using vhdl
iaetsd Software defined am transmitter using vhdl
 
BDL_project_report
BDL_project_reportBDL_project_report
BDL_project_report
 
report
reportreport
report
 
thesis2005
thesis2005thesis2005
thesis2005
 

Pavel_Solomein_Final_Project_2015

  • 1. Microcontrolled Real-Time Audio DSP with ARM Cortex Processors Pavel Solomein SID: 1210769 MOD002691 Final Project Final Project Report BEng (Hons) Electronics Supervisor: Dr. Domenico Vicinanza Submitted: 12 December 2015
  • 2. ii Abstract Applications of real-time audio Digital Signal Processing (DSP) devices in show business vary from voice effects to guitar distortion. However, most of these effects are controlled in traditional ways. An alternative way to control sound is to measure distance between two objects, and use acquired data to influence the DSP. The aim of this work is to develop and build a real-time DSP device based on the ARM mbed LPC1768 Development Board and controlled by the ultrasonic range sensor. Device must take analog audio signal, apply echo effect to it and play back processed audio in real time using a speaker. Range sensor readings must influence feedback gain of echo effect. Measured distance and feedback gain must be shown on the LCD display. Relevant topics like delay effect concept and embedded systems theory are addressed. Hardware components are reasonably selected and interconnection schematics created. Then software part is developed and circuit is implemented onto the breadboard. The device is tested by means of auditions (critical listening) and oscilloscope measurements. Most of the time device behaved as was predicted. Aims of the work were achieved, as well as design specification. Results are interpreted and such issues as noise and sound distortion are addressed and recommendations given. Further modification possibilities are also discussed.
  • 3. iii Table of contents ABSTRACT.............................................................................................................................II TABLE OF CONTENTS .....................................................................................................III TABLE OF FIGURES............................................................................................................V 1. INTRODUCTION................................................................................................................1 1.1 Aim of the work ..............................................................................................................................................1 1.2 Order of material............................................................................................................................................2 2. LITERATURE REVIEW ...................................................................................................3 2.1 Delay (Echo) Audio Effect..............................................................................................................................3 2.2 Audio DSPs......................................................................................................................................................3 2.3 Alternative Ways to Control Sound ..............................................................................................................4 2.4 Embedded Systems and LPC1768 Microcontroller.....................................................................................5 3. METHODOLOGY ..............................................................................................................7 3.1 Hardware.........................................................................................................................................................7 3.1.1 Microcontroller .........................................................................................................................................9 3.1.2 Audio input ...............................................................................................................................................9 3.1.3 Audio output .............................................................................................................................................9 3.1.4 Speaker ...................................................................................................................................................11 3.1.5 Range sensor...........................................................................................................................................11 3.1.6 Display....................................................................................................................................................12
  • 4. iv 3.2 Software.........................................................................................................................................................12 3.2.1 Range sensor initialization and control...................................................................................................14 3.2.2 Display Initialization...............................................................................................................................15 3.2.3 Data averaging ........................................................................................................................................16 3.2.4 Echo effect program and range mapping ................................................................................................17 3.2.5 Main program .........................................................................................................................................22 4. IMPLEMENTATION .......................................................................................................23 5. RESULTS ...........................................................................................................................25 6. ANALYSIS AND DISCUSSION ......................................................................................28 6.1 Noise...............................................................................................................................................................28 6.1.1 Breadboard noise ....................................................................................................................................28 6.1.2 Industrial noise........................................................................................................................................29 6.1.3 Noise leakage..........................................................................................................................................29 6.1.4 Noise accumulation.................................................................................................................................30 6.2 Sound distortion............................................................................................................................................31 7. CONCLUSION ..................................................................................................................33 8. REFERENCES.................................................................................................................. VI APPENDIX I. IMPLEMENTATION.............................................................................. VIII APPENDIX II. SOURCE CODE ........................................................................................ IX APPENDIX III. POSTER ...................................................................................................XII
  • 5. v Table of figures Figure 1. Hardware functional diagram....................................................................................1 Figure 2. Device interconnections schematic ............................................................................8 Figure 3. Simple LM386 op-amp schematic ............................................................................10 Figure 4. Software functional diagram....................................................................................13 Figure 5. Proposed echo effect DSP scheme ...........................................................................18 Figure 6. Modified echo effect DSP scheme ............................................................................18 Figure 7. Photographs demonstrating the display operation ..................................................25 Figure 8. Oscilloscope measurements of audio input/output signals ......................................27 Figure 9. Oscilloscope measurements of the echoed noise......................................................31 Figure 10. Oscilloscope measurements of noise accumulation ...............................................31 Figure 11. Maximum output voltage swing for LM386 op-amp ..............................................31
  • 6. 1 1. Introduction 1.1 Aim of the work The aim of this work is to develop and build a real-time audio digital signal processing (DSP) device based on the ARM mbed LPC1768 Development Board (hereinafter MBED) and controlled by the ultrasonic range sensor. The device must be able to:  Take the analogue audio signal from computer’s standard audio output.  Apply an “echo” effect to the signal and play back processed audio in real time using a speaker.  Use the ultrasonic range sensor to measure distance between the sensor and acoustically reflective surface. Use the acquired distance data to control the feedback gain for echo effect.  Show measured distance and feedback amount on the LCD display. Hardware functional diagram can be seen below (Figure 1) Figure 1. Hardware functional diagram
  • 7. 2 1.2 Order of material The material of this work is delivered in the following order: - Select hardware components, justify the choice, make reasonable interconnections between components and MBED and produce relevant schematics. - Develop software code using C++ language for the device to meet specification. - Test the device, analyse and discuss results, give recommendations and propose further improvements. The assembled circuit, like it is presented on Figure 1, is referred to as “Device” throughout this work.
  • 8. 3 2. Literature Review 2.1 Delay (Echo) Audio Effect Sound effects play very important role in media in our days. Various sound processing tools are incorporated in radio, television, recorded music and live performances. Since the 1970’s recorded music involved a massive amount of sound processing. List of must-have effects included compression, EQ, delay and reverb. This required a vast number of knobs and faders provided by an analogue mixing desks (Milner, 2010). Being one of the most valuable effects, delay is the act of copying a sound and then playing it back after a pause. If that “copy” of sound is played a short while later, it will sound like and echo (Kirk, 1999). Before the days of digital audio, a common approach to creating this sort of effect was to use a spare analog tape machine as a generator of delay. Choices of a tape speed were limited to 2 or 3. Then, tape delays were created. These are tape machines with a loop of tape inside and an adjustable spacing between a record and playback heads, which gives more flexibility in timing the delay. Nowadays, digital delays are easily adjustable and very flexible, and can exist in a pulldown menu of a digital audio workstation (Case, 2007). Using sound effects and especially delay is very important from the artistic point of view. These treatments saturate the song, give its own signature and make it “breathe”. Cook (2009) takes the stance that equally enmeshed with the musical syntax and performances on modern recordings are the myriad effects created by the digital delay (echo), many of which have become common in the current lexicon of record making. 2.2 Audio DSPs When the sound is recorded digitally it becomes a collection of numbers. Therefore the task of DSP is to manipulate those numbers with a help of mathematical operations to
  • 9. 4 achieve needed result. Nowadays, as contemporary music is likely digital, creation process relies heavily on such mathematical manipulations. Audio DSP is of specific interest because manipulating digital audio data is relatively simple. Mathematically, this data is 1- dimensional array information, representing a function of time (Kamenov, 2014). Using DSP systems instead of analog devices has many strong advantages. First, DSP’s are programmable. Hardware can be simply reprogrammed to perform a different task, for example low-pass filter can be changed to high-pass without any change in hardware. Second, digital system is much more stable than analog one, since its characteristics does not change with temperature. DSP’s are also less subjectable to component ageing. Other pros include repeatability, error correction codes, data transmission and storage, and many more (Marven, 1993). DSP’s are developing rapidly and satisfy a big demand on the highly competitive market. For instance, in 2014 Texas Instruments introduced the next-generation DSP TMS320C5517. New DSP delivers up to 200MHz performance with low power consumption for demanding applications, such as face detection or voice recognition. It offers a compelling combination of low stand-by and low active power making it the best choice for battery-powered, portable systems requiring analytics (ENP Newswire, 2014). 2.3 Alternative Ways to Control Sound People have thought about and found alternative ways of playing instruments and controlling sound way back in the era of analogue devices. For instance, using gestural control to affect the output of electronic instruments is a principle that was already firmly established in 1919 by the Russian scientist Lev Termen with his “Aetherphone”, later called “Theremine”. The instrument produces monophonic music with a quasi-sine wave timbre and is played by moving two hands in the vicinity of antennae controlling pitch and amplitude (Rowe, 1993). New possibilities arose with the developing of digital technologies, especially
  • 10. 5 DSP’s. Nowadays there is a big interest in developing augmented instruments incorporating DSP’s. Augmented instruments, also referred to as extended or hybrid instruments, are acoustic (sometimes electric) musical instruments extended by the addition of several sensors, providing performers the ability to control extra sound or musical parameters. One of the examples include the “meta-trumpet”, augmented trumpet that uses several sensors to extend its classical design. Ultrasound transmitters are placed at the bell of the trumpet and receivers are placed below and on the side of the performer in order to measure direction and speed of movement (Miranda, 2006). Progress went even further to develop so-called alternate controllers. These controllers are not directly modelled on or necessarily inspired by existing acoustic instruments. This makes a great variety of design possibilities. For example, “Hands” prototype created by Michel Waisvisz was based on two aluminium plates and provided sensing of the distance between the hands through time-of-flight ultrasound sensing in order to control the sound (Miranda, 2006). 2.4 Embedded Systems and LPC1768 Microcontroller Embedded systems represent a class of dedicated computer systems designed for specific purposes. The devices that embed them are convenient, user-friendly and dependable (Li, 2003). A suitable microcontroller must be utilized to build an effective real-time embedded audio DSP. There is a wide range of various microcontrollers available today, which are designed for different tasks. However, some specific criteria for the microcontroller should be met to perform real-time DSP tasks. First, fast multiply and accumulate (MAC) units are required, as it is required in most audio DSP functions, such as filtering, FFT, correlation. Second, multiple memory access is needed. Most DSP processors adopt modified Harvard architectures to allow simultaneous fetch of instructions and data. Others include optimized instruction set, special program control and effective peripheral
  • 11. 6 interface (Kuo, 2013). If one takes LPC1768 Microcontroller with Cortex-M3 Core by ARM as a candidate, it can be seen that it is suitable for such applications. It has a pipelining applied to its instruction fetch, allowing instructions to be executed in parallel, which improves efficiency and speed. Also, reduced instruction set computer (RISC) approach is used, which allows to execute code rapidly and keep instructions within one binary word. It also has relevant I/O interfaces to interact with analog and digital devices (Toulson, 2012). The importance of sound effects in nowadays media, along with the development of fast and effective audio DSP’s and demand for devices, which can utilize alternative ways of controlling sounds, justify the creation of a real-time audio processing device controlled by the ultrasonic range sensor and based on the LPC1768 Microcontroller with ARM Cortex-M3 Core.
  • 12. 7 3. Methodology Methodology process is divided into three sections: Hardware, Software and Implementation. Hardware section describes and justifies all physical interconnections between device components. Software section explains program code developed to meet the design specifications. Implementation section clarifies some aspects of mounting the circuit onto the prototyping breadboard. 3.1 Hardware This section describes device assembly process. Actual electronic components are selected and connected to the MBED and between each other. Selection process is justified, all connections are reasoned and explained, and use of additional components is clarified. Remarks and precautions are given where necessary. Fully assembled device interconnections schematic can be seen on the next page (Figure 2). It is followed by a detailed description, which constantly references to the schematic. All component numbers, pins and connections mentioned in the description fully correspond to those appearing on the schematic.
  • 13. 8 Figure 2. Device interconnections schematic
  • 14. 9 3.1.1 Microcontroller ARM mbed LPC1768 Development Board incorporates LPC1768 chip which is based on Cortex-M3 core by ARM. This microcontroller (LPC1768) would not be commonly used for commercial audio processing device, since resolution of its converters is low for such applications (12-bit ADC and 10-bit DAC). In addition, having only one DAC limits application to only one audio channel, thus limiting audio signal to be mono (Toulson, 2012). However, simplicity and flexibility of programming is advantageous for the project. 3.1.2 Audio input Personal computer (PC) will act as a source for initial audio signal. Standard audio output of the PC is wired to the MBED analogue input, using cable with 3.5mm mono jack connector on one side and positive and negative clips on the other. Positive clip is connected to MBED pin “p15” (analogue I/O of the MBED), while negative is wired to the common ground. Audio signal from PC output oscillates around 0V. Since MBED’s ADC is capable of reading only positive values, all data below 0V would be lost at the MBED input. Therefore, coupling and biasing circuit is applied to offset the signal to a 1.65V midpoint (Toulson, 2012). 3.1.3 Audio output Texas Instruments LM386N-1 audio op-amp is chosen to effectively drive a 8500mW speaker. According to the datasheet, LM386N-1 (LM386 later in this work) typically provides 325mW of power if supply voltage VS = 6V and load resistance RL = 8National Semiconductor Corporation, 2000). It is slightly lower power than required by
  • 15. 10 the speaker, but enough to suit needs of this work. Schematics of the simple amplifier circuit with minimum parts and Gain = 20 is given in the LM386 datasheet (Figure 3) Figure 3. Simple LM386 op-amp schematic National Semiconductor Corporation, 2000) This option is implemented in the device with some minor changes. First, 250uF capacitor (see pin 8 on Figure 3) was not available at the time of circuit construction. It was decided to use closest capacitor value available, which was 220uF (C3 on Figure 2). The same problem occurred with 0.05uF (50nF) capacitor, which was replaced by 47nF capacitor available (C4 on Figure 2). Another solution is to use several capacitors in parallel to get closer to the desired capacitance, because the equivalent capacitance of two capacitors connected in parallel is the sum of the individual capacitances. However, in order to keep the circuitry as simple as possible to minimise noise, it was decided to stick to the closest capacitor values available. Another correction is to use a simple voltage divider instead of potentiometer at “+IN” pin of the LM386. To get more stable and predicted results, number of varying factors should be minimised. Potentiometer allows greater flexibility and ability to control the speaker volume, however in terms of this work stability seems to be more
  • 16. 11 important. Therefore, constant value is preferred over a variable. Voltage divider implemented have a following equation (Equation 1): 𝑉𝑂𝑈𝑇 = 𝑅6 𝑅5+𝑅6 ∗ 𝑉𝐼𝑁 = 1𝑘Ω 1𝑘Ω+ 10𝑘Ω ∗ 𝑉𝐼𝑁 = 𝑉 𝐼𝑁 11 (1) Where Vout – Signal going from potential divider to op-amp input, Vin – signal coming from MBED pin “p18” According to MBED specification, only pin “p18” can act as analogue out, so it is used as an audio output of the device. Pin 18 is connected to “+IN” pin of the LM386 op- amp. MBED “VU” pin, which provides +5V USB power supply, is connected to “Vs” pin of the LM386. 3.1.4 Speaker “Sparkfun Speaker (8500mW)” is chosen to play back the processed audio signal. Its negative pin is connected to common ground. Speaker’s positive pin is connected to the “VOUT” pin of the LM386 op-amp in series with the 250uF capacitor (C3 on the Figure 2) and in parallel with series of capacitor and resistor (C4 and R7 of Figure 2). These interconnections are done according to the schematics in LM386 datasheet (National Semiconductor Corporation, 2000). 3.1.5 Range sensor “TruSens SRF08 High Performance Ultrasonic Range Finder” is chosen to act as a range sensor. Its required power supply is 5V, and sensing range is between 3cm and 6m, which perfectly suits the project needs. Moreover, this sensor uses I2 C bus for communications, which is supported by the MBED. GND pin of the sensor is connected to common ground. Serial Data Line (SDA) and Serial Clock Line (SCL) pins of the sensor are connected to MBED pins “p9” and “p10” correspondingly, as these MBED pins are reserved for either I2 C or Serial communications. SDA and SCL are also connected to +5V power
  • 17. 12 supply (MBED “VU” pin) through 2 pull-up resistors (R1=R2=1k8on Figure 2), as recommended by “SRF08” datasheet (TruSens, n.d.). “VCC” pin of the sensor is connected to +5V power supply. “NC” pin of the sensor remains unconnected. Therefore, the sensor is prepared to work, and can be used as soon as software part is done. 3.1.6 Display Adafruit Monochrome 128x32 SPI OLED Graphic Display is chosen to display feedback and range data. The display has SSD1306 driver chip that communicates by the Serial Peripheral Interface (SPI), which is supported by MBED (Solomon Systech Limited, 2008). Since display will act as a slave device in SPI communication, “DATA” pin of the display is connected to MBED pin “p5”, which is reserved for SPI Master Output Slave Input (MOSI). “CLK” pin of the display is connected to MBED pin “p7”, which is reserved for Serial Clock (SCK). The wiring of another 3 pins is highly relevant to the software program. Looking ahead, 3 Pulse Width Modulation (PWM) pins on the MBED are used in the initialization and service functions in the provided libraries for the display. Thus, choice of the pins is dictated by the software. Pins “CS”, “RST” and “D/C” of the display are connected respectively to PWM pins “p24”, “p25” and “p26” of the MBED. “CS” pin is used for selecting a slave device for communicating. It is not of much concern to this work, as only one slave SPI device is used. “RST” pin is device reset and is used in the initialization procedure in a display software library. MBED pin “p6” remains unconnected, since MBED does not act as a slave in this design. 3.2 Software Program basement for the project was collected using different sources. As a starting point for the core part of the project, C++ code examples from the book “Fast and Effective Embedded Systems Design” (FEESD) are taken (Toulson, 2012). These code pieces include “echo” effect and SRF08 range finder communication programs. Another source of
  • 18. 13 information is the official developer website of MBED where open source libraries used to control Adafruit OLED display were found. Some parts were written from scratch, like the 5- point moving average filter, that averages signal coming from the range finder, or scaling program that ties range sensor readings to the feedback gain of echo effect. All those collected pieces of code work fine on their own, however they have to be readjusted and interconnections have to be made between them to meet a device specification. Full code can be found in Appendix II. Software functional diagram can be seen on Figure 4 below. Figure 4. Software functional diagram
  • 19. 14 3.2.1 Range sensor initialization and control This code is based on the example from FEESD. Range sensor initialization starts with I2 C class declarations and assigning MBED pins “p9” and “p10” as SDA and SCL interfaces. According to the datasheet, the default shipped address of the SRF08 is 0xE0. This address is assigned to the constant “addr” and used later during communications. Pointers “config_r” and “range_read” of type “char” are declared to address registers and read data. Variable for the readings “range” of type “float” is declared. This is very useful, because the amount of echo effect is controlled by a variable of type “float” as well, which makes it easier to create a correlation range measures and amount of echo effect. The code is provided below: I2C rangefinder(p9, p10); //sda, sc1 const int addr = 0xE0; char config_r[2]; char range_read[2]; The following part is put inside the function (void acquire()), so it can be used across the program conveniently. Inside the “acquire” function, an infinite loop is declared. Inside the loop, pointer “config_r[0]” is set to command register “0x00” and “config_r[1]” is set to “0x52”. According to the datasheet, this will initialize the sensor and make the ranging result appear in microseconds (us). The amount of microseconds will show how much time it takes for the beam to reach acoustically reflective surface and come back (considering speed of sound in air). Microseconds are chosen because of the measure steps which are small enough to be operated as integers, without any decimal points. It will be more convenient to scale down integer value to control amount of echo effect, than to deal with a floating point. Then pointers are used to send command to sensor, using “rangefinder.write”. It takes some time to complete the ranging. The default and recommended time for completion of ranging is 65ms,
  • 20. 15 so slightly higher waiting time is considered and set to 70ms. After 70ms of waiting, pointer “config_r[0]” is set to data register “0x02” and sent to the sensor. Right after, “rangefinder.read” command is given and two-byte range data is written to the “range_read” pointer. Finally, two 8-byte pieces of the data are concatenated into “range” variable and program waits for 50ms before beginning a new loop. The code is provided below: void acquire() { config_r[0] = 0x00; //set pointer reg to ‘cmd register' config_r[1] = 0x52; //config data byte1; result in us rangefinder.write(addr, config_r, 2); wait(0.07); config_r[0] = 0x02; //set pointer reg to 'data register' rangefinder.write(addr, config_r, 1); //send to pointer 'read range' rangefinder.read(addr, range_read, 2); //read the two-byte range data range = ((range_read[0] << 8) + range_read[1]); //Concatenate 2 bytes of data wait(0.05); } 3.2.2 Display Initialization Control of the Adafruit display involves communicating with the libraries. As previously mentioned, they are open source and can be found on the MBED developer website (Horman, 2014). The library (Adafruit_SSD1306.h) is declared at the very beginning of the code (see Appendix II). Display initialization includes creating the SPI master “SPI2” connected to the “mosi”, “miso” and “clk” pins. Communication frequency is set to 2MHz and data transmission format is configured. The corresponding code is shown below: class SPI2 : public SPI { public: SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(2000000); }; };
  • 21. 16 MBED pins “p5” and “p7” are attached to “mosi” and “clk” respectively, which corresponds to the hardware connections made. Through function “gOled” of file “Adafruit_SSD1306.h”, pins “p26”, “p25” and “p24” are assigned respectively to “DC”, “RST” and “CS” interfaces of the display. This corresponds to the hardware connections made. The only part of the software where functions relevant to the display are used is “main” program. Thus, used functions are discussed in the relevant chapter. 3.2.3 Data averaging Moving point average filter, which calculates mean value of 5 last range finder data samples, is implemented. The corresponding function is called “rangecalc”. This is done to minimize possible noise disturbances from the range sensor, increase stability and linearity. Filter incorporates “for” loop, which counts up to 5 and then resets. During each count, range sensor data acquiring procedure “void acquire()” is called in order to get current range reading. Acquired data is put to “rng5” point of a filter (“rng5” is 5th point, therefore “rng4” would be 4th point e.t.c), which serves as a pointer for every current variable. However, this happens at the bottom of a moving average. Current data reading cannot be assigned to the top point of the moving average, as each next variable copies the previous one. Thus, if put on top, current variable will fill the whole filter during one count, which will become useless. Counter wise, first 4 points of moving average filter are assigned (2nd point to 1st point, 3rd point to 2nd point, 4th point to 3rd point and 5th point to 4th point) and only then current value is assigned to the 5th point. Therefore, on the next count this value will go up to the 4th point and a new value would be assigned to the 5th point, thus making filter work effectively. All points are summed and put into “rangetot” variable, which is later divided into 5 and put into “rangeav” variable, providing the mean value of 5 samples. The code is provided below:
  • 22. 17 void rangecalc() { float rangetot = 0; for (int ii= 0; ii<5; ii++) { acquire(); //Acquire data for averaging rng1 = rng2; rng2 = rng3; rng3 = rng4; //5-point moving average rng4 = rng5; rng5 = range; rangetot = rng1 + //Accumulate samples rng2 + rng3 + rng4 + rng5; } rangeav=rangetot/ 5; //Compute the average of 5 samples } 3.2.4 Echo effect program and range mapping The basic idea of creating an echo effect is providing a feedback delay, which makes a single sound to be repeated a number of times. Each time the signal is repeated it is attenuated until it decays away (Toulson, 2012). The simple delay unit schematics is proposed in FEESD. Initially, it is proposed to control the speed of repetition and feedback gain by external potentiometers (Figure 5). The initial design is modified to meet the project needs. Variable Time Delay is changed to the constant value of 0.5 and feedback gain potentiometer is replaced with the range sensor data measurements (Figure 6).
  • 23. 18 Figure 5. Proposed echo effect DSP scheme (Toulson, 2012) Figure 6. Modified echo effect DSP scheme (See original on Figure 5) To implement the design shown on Figure 6 it is necessary to store previous data samples and allow a desired amount of them to mix with the present data samples. To achieve this, sampled data is copied into a large array (buffer), so the feedback data is always available. The feedback gain determines how much buffer data is mixed with the sampled data. The length of time between current and previous samples is determined by the size of buffer, which is controlled by the constant time delay value. “AnalogIn” and “AnalogOut”
  • 24. 19 classes are declared and assigned to “Ain” and “Aout” variables respectively, which correspond to MBED pins “p15” and “p18”, again, respectively. This is done according to the connections made in the hardware chapter. Class “Ticker” is declared, as the process will be triggered by an interrupt. Variables for data processing, delay and feedback are declared as well as maximum buffer value and counter variable. Function for echo effect is created (void echo_task()). This procedure starts with reading 16bit unsigned integer data from input Ain (MBED pin “p15”). Data is normalized by subtracting “0x7FFF” from it. Hex value “0x7FFF” equals to 32767 in decimal, which is half the range of 16-bit unsigned integer (2^16 = 65536). Therefore, the signal is normalized to an average value of zero, so that it oscillates positive and negative, which is needed for the DSP calculation. Code can be seen below: data_in=Ain.read_u16()-0x7FFF; //Read data and normalize buffer[i]=data_in+(buffer[i]*feedback); //Combine current sample with previous data_out=buffer[i]+0x7FFF; //Output data buffer Aout.write_u16(data_out); //Write to output Buffer filling is implemented, where “buffer” array is filled with the current data sample plus “buffer” multiplied by the feedback. In simple words, current data is blended with a certain amount of previous data. That amount is controlled by variable “feedback”. Finally, buffer is compensated for normalizing (“0x7FFF” is added) and written to the output (MBED pin “p18”). Then control routine for buffer, delay and feedback amount is described. Program watches if buffer is full (if i>delay). If it is false, then counter counts up. If it is true, then counter resets (i = 0). Floating point value “delay” is constant, since “delay_pot” is constant and set to 0.5. Value “MAX_BUFFER” is 14000 by the default, hence “delay” is 14000*0.5 = 7000. Therefore, buffer size is 7000 samples. Finally, “feedback” amount is calculated (feedback=feedback_pot*0.9). Where “feedback_pot” is feedback gain controlled
  • 25. 20 by the range finder. It is multiplied into 0.9 to prevent the final feedback value from ever reaching 1. Code can be seen below: if(i>(delay)) { i=0; ///// Range mapping code here (see below)///// //Reset counter delay=delay_pot*MAX_BUFFER; //Calculate new delay buffer size feedback=feedback_pot*0.9; //Calculate feedback gain value } else { i=i+1; } Range mapping routine is simply tying up “rangeav” variable with “feedback” variable, to make range sensor data to control feedback gain. It is needed to calculate maximum range value, which will refer to maximum feedback gain value. Max. range value (Drange) must be convenient in terms of later tests. It must be big enough to test the relation of feedback and range and not too big at the same time. Therefore, consider Drange = 50cm. This value must be converted to microseconds, as it is a chosen measure for range sensor. As already mentioned, readings from the range sensor in microseconds refer to the time it takes for ultrasonic beam to travel from the sensor, reflect from acoustically reflective surface and come back. Therefore, knowing the speed of sound in dry air at 20C0 , the time for ultrasonic beam to travel desired distance (50 cm) is calculated (Equation 2): 𝑇 = 𝐷 𝑟𝑎𝑛𝑔𝑒 𝐶 = 0.5 m 343.21 𝑚/𝑠 = 0.001457 𝑠 = 1457 𝜇𝑠 (2) Where T – travel time for the ultrasonic beam, Drange – travel distance, C – speed of sound in dry air at 20C0
  • 26. 21 However, corresponding sensor reading must be twice the travel time, to cover time that beam takes to travel back (Equation 3): 𝑇2 = 𝑇 ∗ 2 = (1457 ∗ 2) 𝜇𝑠 = 2914 𝜇𝑠 ≈ 3000 𝜇𝑠 (3) Where: T – travel time for the ultrasonic beam, T2 – total travel time for the ultrasonic beam Taking 3000 us as a reference point for the maximum range reading, program code is created. Program checks if current range sensor reading is less than 3000us. If it is true, then the current value is divided by 3000 and put into “feedback_pot” variable. If it is not true (current range reading exceeds 3000 us) then “feedback_pot” is kept 1. Therefore, current range reading is being scaled to the value in range from 0 to 1 and fed into “feedback_pot” to control the echo effect. In case sensor reading value is greater than 3000 us, “feedback_pot” variable is protected from overflowing (becoming greater than 1). Such overflowing can cause distortion at audio output, since feedback value is multiplied into buffer values, as mentioned before. Thus, being greater than 1, feedback values would cause the buffer data to reach highest values, which would cause distortion. Code can be seen below: if (rangeav < 3000) { //Scale feedback if range is less 3000 us feedback_pot = rangeav / 3000; } else { //Highest feedback gain if range > 3000 feedback_pot = 1; } It is necessary to mention that mapping range readings to a value from 0 to 1 is an idealistic approach. However, according to the SRF08 datasheet, minimum range measurement for the sensor is 3 cm (TruSens, n.d.). This means that sensor readings will never get the value of 0, thus feedback gain value will never reach 0 as well. Minimum range measurement is calculated in microseconds (Equation 4):
  • 27. 22 𝑇 𝑚𝑖𝑛 = 2 ∗ 𝐷 𝑚𝑖𝑛 𝐶 = 2 ∗ 0.03 𝑚 343.21 𝑚 𝑠 = 0.000175 𝑠 = 175 𝜇𝑠 (4) Where Tmin – minimum total travel time for the ultrasonic beam, Dmin – minimum travel distance, C- speed of sound in dry air at 20C0 Minimum feedback gain value is calculated (Equation 5): 𝐹 𝑚𝑖𝑛 = 𝑇 𝑚𝑖𝑛 3000 𝜇𝑠 = 175 𝜇𝑠 3000 𝜇𝑠 = 0.05833 ≈ 0.06 (5) Where Fmin – minimum feedback gain value, Tmin – minimum total travel time for the ultrasonic beam 3.2.5 Main program The main program incorporates all functions described above and brings them together in one place for the device to work effectively. First, command to clear the display is executed. By the default, Adafruit OLED display shows “Adafruit” logo on a start-up, and if it is not cleared it can prevent necessary information from being displayed. Ticker is attached to the “echo_task” program, which is responsible for echo effect. The ticker period is 50 us, therefore its frequency is 20kHz. It means that interrupt will occur every 50 us and “echo_effect” will be executed 20.000 times a second. This can be thought as a sampling rate of the DSP. Infinite “while” loop is implemented. First function executed inside a loop is “rangecalc”, which acquires data from range sensor, averages it and scales “feedback_pot” value according to that data. Remaining code lines control the display. Initial position on the display is set (which is 0, 0). Thus, data will be displayed starting in the top left corner of the
  • 28. 23 display. Then actual text to be displayed is written. Range will be displayed at the top accompanied by the “us” measure after a value with 0 decimal points. Feedback is displayed at the bottom, incorporating two decimal points in its value. The last command is to display the selected data. Code can be seen below: int main() { gOled.clearDisplay(); //Clear LCD s20khz_tick.attach_us(&echo_task,50); //Attach 20khz ticker to the echo task while (1) { rangecalc(); gOled.setCursor(0, 0); gOled.printf(" Range = %.0f us nr n Feedback = %.2fn ", rangeav, feedback_pot); gOled.display(); } } 3.3 Implementation The device is assembled on a solderless prototyping breadboard based on the developed schematics (See Figure 2). In fact, two breadboards are used, which are interconnected with each other to form one bigger breadboard. So when a reference made to a “breadboard” later in this work, it actually means two adjacent breadboards. Use of a solderless breadboard provides high flexibility, since components can be readjusted quickly at any time, which saves time while constructing prototype devices like one discussed in this work. Power rails on the breadboard are also used to provide power supply and ground to all parts of the circuit in a convenient way using less wires. “VOUT” pin of the MBED, which provides 3.3V supply, is wired to the red power rail to give easy access to power supply across the breadboard. “GND” pin of the MBED is wired to black power rail to provide a common ground for all components across the breadboard. Each chosen electronic component has pins attached to it, allowing the component to be inserted into the breadboard holes easily. MBED and LM386 op-amp are Dual In-Line
  • 29. 24 Packages (DIP’s), so DIP ravine is used on the board to accommodate these. Opposite pins of DIP’s are not meant to be wired to each other, as they have separate functions. Therefore, the ravine acts as a border which divides two sides of DIP component into two sections. Audio input (MBED pin “p15”) is wired to the red binding post with a green cable (goes under the display). Ground is wired to the black binding post. Use of binding posts is justified by greater flexibility, when either oscilloscope, sound or power source can be connected through them easily. Wiring between components on the board is done using simple solid core wires, with a diameter of 0.644 mm. These cables fit tightly into breadboard’s holes and their diameter is sufficient for the use in this work, since there are no big currents and maximum applied voltage is 5 volts. Wires are kept as short as possible to reduce noise and unwanted fluctuations. MBED is connected to the PC with mini-USB cable. The C++ program is compiled and downloaded onto the MBED.
  • 30. 25 5. Results As device is powered up a hissing noise is heard from the speaker. Display initializes and, after a couple of seconds, range and feedback values are displayed (See Figure 7). Human hand (which belongs to the researcher) acts as acoustically reflective surface, and is used to test the ultrasonic sensor. If hand is placed close to the sensor, range and feedback readings on display are small and noise from the speaker becomes quieter. As hand moves further from the sensor, readings on the display increase as does noise hiss from the speaker. The minimum feedback gain achieved is Fmin = 0.06. Sound of the ultrasonic beam, produced by the range sensor, can be heard. Another noise in form of clicks is heard from the speaker. The periodicity of clicks corresponds to the periodicity of beam sounds from the range finder. Photo 1 Photo 2 Figure 7. Photographs demonstrating the display operation Audio sample was recorded to test the functionality of the device. The sample is a recording of a person saying “uh”. Recording length is 1 second and it is in mono. This short audio clip can be thought of as a pulse. It is convenient to use a pulse to test the given device, as recurring pulses (echoes of the initial pulses) will be clearly heard through the speaker and seen on the oscilloscope if measured. Laboratory stance with a clamp was utilized to hold a piece of carton, which acted as acoustically reflective surface. The distance between a piece of carton and a range sensor was varied to test 7 different range and feedback values, in
  • 31. 26 ascending order. Therefore, 7 feedback gain coefficients were tested (F = 0.06, 0.20, 0.40, 0.60, 0.80, 0.95, 1.00). For each mentioned distance, an audio sample was fed to audio input. The level of hiss noise has lowered as sound source (PC) was connected. As observed by the auditions, device functioned according to the predictions. At the minimum feedback gain (Fmin= 0.06) no echoes can be heard after the pulse. As gain value rise, echoes become louder and their number increase. At the maximum feedback gain (F = 1.00), audio sample is being repeated many times, while the volume fades away very slow comparing to the lower feedback auditions. It is necessary to mention that slight distortion of the output signal was present. The intensity of distortion tend to increase along with the feedback gain value. However, the output signal is still intelligent to the listener and can be identified as a male person saying “uh”. The clicking noise mentioned above, along with the hiss noise, is still present during audio sample playback, however its amount is tolerable. All mentioned feedback gain device configurations were tested using the oscilloscope (OSC). Channel 1 of the OSC was connected directly to the audio input red binding post (thus, in parallel with the audio input) to measure the input signal. Additional wire from the LM-386 op-amp output was connected to the free binding post, which was wired to the Channel 2 of the OSC to measure output signal. Grounding from both channels of the OSC was wired to the black ground bay, where audio input cable ground was already attached. At the time of measurement, speaker was functioning. The first thing to mention after connecting the OSC is that noise levels have increased. In addition to hiss and clicks, crackle noise has appeared. Similar feedback gain configurations were used to play audio sample and measure the result using OSC. Auditioning results were relatively similar to the ones gathered without the connected OSC. Exception are high feedback gains 0.95 and 1, when noise became dominant and audio output was unintelligible. Results of the measuring are presented on Figure 8 (note that yellow signal is input and blue signal is output).
  • 32. 27 Range = 200us Feedback = 0.06 Amplitude vs. Time Range = 595us Feedback = 0.20 Amplitude vs. Time Range = 1200us Feedback = 0.40 Amplitude vs. Time Range = 1800us Feedback = 0.60 Amplitude vs. Time Range = 2385us Feedback = 0.80 Amplitude vs. Time Range = 2850us Feedback = 0.95 Amplitude vs. Time Range = 3220us Feedback = 1.00 Amplitude vs. Time Figure 8. Oscilloscope measurements of audio input/output signals
  • 33. 28 6. Analysis and Discussion Overall performance of the constructed device is close to the predictions. Minimum measured feedback gain is equal to the calculated one. However, there are several issues identified that have to be addressed and explained. 6.1 Noise There are different types of noise observed at different testing stages. These noise types include hiss, crackle and noise leakage from another source (from range finder). Sources of noise can be divided into two classes: internal and external. Parasitic effects across the breadboard, thermal and shot noise and substrate coupling contribute to the internal sources of noise. Industrial noise could act as an external source of noise. 6.1.1 Breadboard noise A basic principle of a breadboard structure is that it is a temporary one, designed to test performance of electronic circuit. Unfortunately breadboards have excessively high parasitic resistance, inductance and capacitance levels. This can influence the circuit behaviour and create noise. Paying equal attention to signal routing, component placement, coupling and decoupling may help to minimize negative effects. (Jung, p.751, 2004) For example, components that can influence each other’s work can be moved further apart same as their transmission lines. Also, length of the cables increase noise. Cables were shortened even more and noise level decreased.
  • 34. 29 6.1.2 Industrial noise This noise is common for industrialized areas. It is caused by electric motors, leakage from high voltage lines and heavy electrical machinery. To avoid industrial noise, power sources such as fluorescent lights should be avoided at the place where sensitive testing takes place (Rao p.2, 2010). Testing of the circuit was conducted in an electronics lab, where a lot of electrical equipment is operating. This fact could have caused hissing noise in the speaker and have an impact on the results. To minimize industrial noise effect, better insulation of the entire circuit could be used, for example circuit could be put in a metal box. 6.1.3 Noise leakage Noise leakage from the range sensor could be heard through the speaker as clicks, which periodicity is similar to the periodicity of the ultrasonic beam emitted from the range sensor. Both LM386 audio op-amp and SRF08 ultrasonic range sensor require +5V power supply (Figure 2). This is supplied by the “VU” pin on the MBED (power from the USB). Both components are connected to this pin in parallel. Interconnections inside SRF08 ultrasonic range sensor can influence the power common power supply line behaviour. A reason for that might be poor circuit design which permits substrate coupling. The range sensor is an integration of a digital and analogue circuitry, which can create substrate coupling. It might be caused by fast switching of the digital circuitry via common substrate. High current peaks are drawn from the power supply network, which results in ringing on the supply lines. This ringing is injected into the substrate in a resistive way through the substrate contacts. When substrate noise couples into an analog circuit, residing on the same die, it can severely affect circuit’s performance (Bronckers, 2010). As a result, noise from emitting ultrasonic beam affects the “VCC” power supply pin of the range sensor, making
  • 35. 30 disturbances for the LM386 op-amp, which uses the same power supply. Solutions for this problem may include using different range sensor or separated power supplies. 6.1.4 Noise accumulation Due to the specifics of constructed circuit, there is also a strong concern for accumulation of noise of any type which is coming into the signal input (MBED pin “p15”) or appearing somewhere across the circuit. Since one of the main functions of the device is to produce “echo” effect, this effect can be applied not only to the wanted signal, but to noise as well. Therefore, unwanted spikes and fluctuations can not only be present, but are multiplied and repeated several times. According to the design specification, the intensity and power of those repetitions increase along with the increasing feedback gain value. Echoes of noise spikes can overlay new spikes and each other, thus creating noise accumulation. The example of an echoed noise is seen on the OSC measurement (Figure 9). It is seen that there is no input signal, however output signal is present and has a form of the echoes. On another OSC measurement the time division is 250ms and the accumulation of noise is seen, where spikes of various amplitudes follow each other (Figure 10). Both measurements are taken with highest feedback gain (F=1.00) and without input signal to demonstrate the effect of noise at the highest feedback gain. Therefore, noise accumulation could contribute to the unpredicted behaviour of a circuit at high feedback gains (F = 0.95, F = 1.00) observed during OSC measurements. It can be assumed that additional cables used to connect OSC caused the noise level to increase, which led to massive noise accumulation (at high feedback gains), which was unexpected.
  • 36. 31 Figure 9. Oscilloscope measurements of the echoed noise Figure 10. Oscilloscope measurements of noise accumulation 6.2 Sound distortion Slight sound distortion mentioned in the Results section is relevant to the characteristics of LM386 op-amp. The distortion can be caused if a signal of excessively high amplitude is fed into the input of an op-amp. The distortion appears when amplified signal exceeds permitted maximum output voltage swing of an op-amp. This swing for LM386N-1 op-amp is given in its datasheet (Figure 11). As can be seen from the graph, peak-to-peak output swing for load resistance RL = 8Ω (speaker resistance) and Vs = 5V (supply voltage, MBED pin “VU”) equals to approximately 2.55V. Figure 11. Maximum output voltage swing for LM386 op-amp National Semiconductor Corporation, 2000)
  • 37. 32 Therefore, maximum input voltage for the designed LM386 op-amp configuration can be calculated (Equations 6 and 7). 𝑉𝑠𝑤 = 𝑉𝑚𝑎𝑥 ∗ 𝑅6 𝑅5+𝑅6 ∗ 𝐺 (6) 𝑉𝑚𝑎𝑥 = 𝑅5+𝑅6 𝑅6 ∗ 1 𝐺 ∗ 𝑉𝑠𝑤 = 11Ω 1Ω ∗ 1 20 ∗ 2.55𝑉 = 1.4025𝑉 ≈ 1.4𝑉 (7) Where Vmax – maximum peak-to-peak voltage at MBED pin “p18”, R5 and R6 – voltage divider resistor values at op-amp input, G – op-amp gain, Vsw – maximum output voltage swing Therefore, audio signal output from MBED must be kept within 1.4V p-p range to avoid op-amp saturation which leads to distortion during playback. It is relatively hard to do, since the initial signal is mixed with its echoes during DSP processing, which makes signal levels to change unpredictably. The recommendation can be either increasing the value of R5 resistor to lower the input voltage or decreasing the output signal amplitude from the signal source (PC) until distortion disappears.
  • 38. 33 7. Conclusion Aims of this work have been achieved. The device incorporating ARM mbed LPC1768 Development Board has been built and is able to take audio signal, apply “echo” effect to it in real time and play it back through the speaker. Although sound from the speaker is subject to noise, it is still intelligible and applied effect can be clearly heard. Feedback gain value is correctly controlled by the range sensor measurements. Display is able to show range and feedback gain values in a correct way. Analysis and discussion of the results showed weak parts of the device which can be improved to increase sound quality. These improvements may include transferring the device from prototyping breadboard to Printed Circuit Board (PCB), applying additional shielding, improving decoupling and controlling the amplitude of input signal. Further modifications may embrace adding more DSP effects to the device (such as reverb or pitch correction), using more range sensors to control various parameters or using external DAC’s to improve sound quality and work with stereo sound. Microcontroller can be also upgraded to the one with ARM Cortex-M4 core, since it is more powerful and suitable for real time audio DSP applications.
  • 39. 8. References Bronckers, S. and Van der Plas, G., 2010. Substrate Noise Coupling in Analog/RF Circuits. [e-book] Norwood, MA, USA: Artech House. Available through: ebrary; ebrary <http://site.ebrary.com/lib/anglia/docDetail.action?docID=10393278&ppg=20> [Accessed 12/9/2015 2:25:23 AM]. Case, A.U., 2007. Sound FX : unlocking the creative potential of recording studio effects. [e- book] Amsterdam ; London: Amsterdam ; London : Focal. Available through: Primo; Primo [Accessed 12/10/2015 12:00:09 PM]. Cook, N., 2009. The Cambridge companion to recorded music. [e-book] Cambridge: Cambridge : Cambridge University Press. Available through: Primo; Primo [Accessed 12/10/2015 12:04:33 PM]. Crecraft, D.I. and Gergely, S., 2002. Analog Electronics : Circuits, Systems and Signal Processing. [e-book] Jordan Hill, GBR: Butterworth-Heinemann. Available through: ebrary; ebrary <http://site.ebrary.com/lib/anglia/docDetail.action?docID=10185890&ppg=318> [Accessed 12/9/2015 12:20:26 PM]. ENP Newswire, 2014. Power-hungry audio and video analytic applications have met their match with next-generation ultra-low-power DSP from TI. [e- ]. Available through: Primo; Primo, [Accessed: 12/10/2015 1:07:07 PM]. Horman, N., 2014. A derived version of the BSD licensed Adafrut GFX library for the SSD1306 controller for an OLED 128x32 or 128x64 display using SPI or I2C. [on-line] Available at: <https://developer.mbed.org/users/nkhorman/code/Adafruit_GFX/>. Jung, W.G., 2004. Op Amp Applications Handbook. [e-book] Saint Louis, MO, USA: Elsevier Science & Technology. Available through: ebrary; ebrary <http://site.ebrary.com/lib/anglia/docDetail.action?docID=10128146&ppg=768> [Accessed 12/9/2015 2:55:51 PM]. Kamenov, A., 2014. Digital signal processing for audio applications. [e-book] Second edition.. ed. United States? : Anton Kamenov?. Available through: Primo; Primo [Accessed 12/10/2015 12:43:19 PM]. Kirk, R., 1999. Digital sound processing for music and multimedia. [e-book] Oxford: Oxford Focal. Available through: Primo; Primo [Accessed 12/10/2015 11:44:43 AM]. Kuo, S.M., 2013. Real-Time Digital Signal Processing Fundamentals, Implementations and Applications. [e-book] 3rd ed.. ed. Hoboken: Hoboken : Wiley. Available through: Primo; Primo [Accessed 12/10/2015 2:05:14 PM]. Li, Q., 2003. Real-time concepts for embedded systems. [e-book] San Francisco, Calif.: San Francisco, Calif. : CMP. Available through: Primo; Primo [Accessed 12/10/2015 2:06:07 PM].
  • 40. vii Marven, C., 1993. A simple approach to digital signal processing. [e-book] Texas Instruments. Available through: Primo; Primo [Accessed 12/10/2015 12:53:43 PM]. Milner, G., 2010. Perfecting sound forever : the story of recorded music. [e-book] London: London : Granta. Available through: Primo; Primo [Accessed 12/10/2015 11:25:19 AM]. Miranda, E.R., 2006. New digital musical instruments : control and interaction beyond the keyboard. [e-book] Middleton, Wis.: Middleton, Wis. : A-R Editions. Available through: Primo; Primo [Accessed 12/10/2015 10:58:28 AM]. National Semiconductor Corporation, 2000. LM386 Low Voltage Audio Power Amplifier. [on-line] Available at: <http://www.ti.com/lit/ds/symlink/lm386.pdf>. Rao, B.Y.N. and Anand, K., 2010. Electronics. [e-book] Mumbai, IND: Himalaya Publishing House. Available through: ebrary; ebrary <http://site.ebrary.com/lib/anglia/docDetail.action?docID=10415084&ppg=6> [Accessed 12/9/2015 1:48:48 PM]. Rob Toulson, T.W., 2012. Fast and Effective Embedded Systems Design. [e-book] GB: Newnes. Available through: dawsonera Name; dawsonera Name [Accessed 12/6/2015 10:04:54 AM]. Rowe, R., 1993. Interactive music systems : machine listening and composing. [e-book] Cambridge, Mass.: Cambridge, Mass. : MIT Press. Available through: Primo; Primo [Accessed 12/10/2015 10:46:29 AM]. Solomon Systech Limited, 2008. 128 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller. [on-line] Available at: <https://www.adafruit.com/datasheets/SSD1306.pdf> [Accessed: 09/12/2015]. TruSens, n.d. TruSens SRF08 High Performance Ultrasonic Range Finder Datasheet. [on- line] Available at: <http://www.rapidonline.com/pdf/78-1086.pdf> [Accessed: 09/12/2015].
  • 42. ix Appendix II. Source Code #include "mbed.h" #include "Adafruit_SSD1306.h" //// Display SPI setup class SPI2 : public SPI { public: SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { format(8,3); frequency(2000000); }; }; SPI2 gSpi(p5,NC,p7); Adafruit_SSD1306 gOled(gSpi,p26,p25,p24); //// Range sensor initialization I2C rangefinder(p9, p10); //sda, sc1 const int addr = 0xE0; char config_r[2]; char range_read[2]; //// Analog Input and Output AnalogIn Ain(p15); // Analog In at pin 15 AnalogOut Aout(p18); // Analog Out at pin 18 //// DSP Echo Effect Declarations Ticker s20khz_tick; // Declare Ticker name #define MAX_BUFFER 14000 // Max data samples signed short data_in; // Signed input (positive and negative) unsigned short data_out; // Unsigned output (only positive) float delay = 0; float feedback =0; signed short buffer[MAX_BUFFER]= {0}; int i =0; //// Variables float range, rangeav; // Used by Ultrasonic Sensor float rng1, rng2, rng3, rng4, rng5; // Used to average data from the sensor float feedback_pot; // Feedback amount controlled by the sensor float delay_pot = 0.5; // Delay period. Constant. 0.5 //// Function - Range sensor control void acquire() { config_r[0] = 0x00; //set pointer reg to ‘cmd register' config_r[1] = 0x52; //config data byte1; result in us
  • 43. x rangefinder.write(addr, config_r, 2); wait(0.07); config_r[0] = 0x02; //set pointer reg to 'data register' rangefinder.write(addr, config_r, 1); //send to pointer 'read range' rangefinder.read(addr, range_read, 2); //read the two-byte range data range = ((range_read[0] << 8) + range_read[1]); //Concatenate 2 bytes of data wait(0.05); } /// Function - Average data acquired from the sensor void rangecalc() { float rangetot = 0; for (int ii= 0; ii<5; ii++) { acquire(); //Acquire data for averaging rng1 = rng2; rng2 = rng3; rng3 = rng4; //5-point moving average rng4 = rng5; rng5 = range; rangetot = rng1 + //Accumulate samples rng2 + rng3 + rng4 + rng5; } rangeav=rangetot/ 5; //Compute the average of 5 samples } /// Function - Echo Effect void echo_task() { data_in=Ain.read_u16()-0x7FFF; //Read data and normalize buffer[i]=data_in+(buffer[i]*feedback); //Combine current sample with //previous samples data_out=buffer[i]+0x7FFF; //Output data buffer Aout.write_u16(data_out); //Write to output if(i>(delay)) { i=0; //// Range mapping //// Form feedback pot depending on sensor readings if (rangeav < 3000) { //Scale feedback if range is less 3000 us feedback_pot = rangeav / 3000; } else { //Highest feedback gain if range > 3000 feedback_pot = 1; } //Reset counter
  • 44. xi delay=delay_pot*MAX_BUFFER; //Calculate new delay buffer size feedback=feedback_pot*0.9; //Calculate feedback gain value } else { i=i+1; } } //// Main int main() { gOled.clearDisplay(); //Clear LCD s20khz_tick.attach_us(&echo_task,50); //Attach 20khz ticker to the echo task //// Infinite loop while (1) { rangecalc(); //Calculate range gOled.setCursor(0, 0); //Set cursor for the display at initial position gOled.printf(" Range = %.0f us nr n Feedback = %.2fn ", rangeav, feedback_pot); //Data to display gOled.display(); //Command to display } }