Locating Where a Sound is Coming From

For my masters year, half the marks came from one module, the masters project. Being a team effort, we were in a group of three. Putting our heads together, and taking ideas from lecturers, we made a list of potential projects. We knew for one that I wanted to be making hardware, and the other two wanted to use/learn machine learning and maybe FPGA’s. After much deliberation we decided to make a project that listened for a sound, and using time difference of arrival worked out where the sound came from. This post is mostly about the hardware and circuitry designed for the project.

The final board for our masters project. Contains four amplifier sections for the microphones and a micro controller with USB interface.

With a world with a big focus on safety in public places, we thought it would be a good product for the security industry, potentially with links to smart cities. Imagine a shopping center, somewhere with lots of security already. They tend to have lots of security cameras, alarm systems and a dedicated guard. This isn’t uncommon in big public places/attractions, especially in the UK. Sports stadiums, train stations and museums are always looking for new ways to protect themselves and isolate problems. The example that inspired us was the horrendous shooting in Las Vegas at a concert in October 2017, just as we were picking projects. The main problem was that the security services did not know where the shooter was, meaning it took longer to get to him. If they had a system like we envisaged, the microphones would pick up the sound and triangulate it. The location could then be sent to relevant authorities to use.

The front page of the New York times just days after the Las Vegas shooting

To start with we needed microphones. We didn’t need to reinvent the wheel, and microphones can be easily bought off the shelf. For ease we used standard stage microphones, that had 3-pin XLR outputs. Although we had been warned that they would not work they had a good omnidirectional pattern, and had lots of good documentation. One issue with them is the output is balanced, which means it needs to go through a pre-amp. To get an idea of what a balanced signal is, imagine a ground connection and two signals. The two signals are the same, but one is inverted. This means when it travels down the cable it is much less susceptible to interference. This is part of the reason we liked using stage rated equipment, as sound engineers have already worked out issues with transporting sound signals long distances through noisy situations. We concluded from research that the signals could reach over 100m, which was the number we were aiming for.

One of the pre-amplifier sections used on the board, using four operational amplifiers.

Once the signal got to the box it needed to be converted to a signal that could be read by an ADC. To do this we used an INA217, a pre-amp designed for basically this purpose. An instrument amplifier, it measures the difference between the signals and amplifies them, outputting a voltage with reference to ground. The signal from the microphone is tiny, in the tens of milivolts range, so it needed some dramatic amplification to get it near the 5V ADC. The INA217 did a good job but we put a second stage amplifier to give it the extra push, as very large gains can sometimes be bad for a number of reasons. We used an OP07D but if we were to do it again we would get a rail-to-rail to get better results. This amp had a pot as one of the gain resistors so that we could easily trim the gain depending on test. Finally, the signal at this point sat between -2.5V and +2.5V so we needed to shift it up so it was between 0 and 5V. This was done with a simple shift circuit and an amplifier. We used another OP07D to make buying easier.

Me manufacturing the PCB, at this point I was inspecting to see how well it had been soldered.

From here the signal gets read by the 12 bit ADC in an STM32 microcontroller. It then streams the data via the USB to a PC where MATLAB picks it up. This is where my knowledge is a bit lacking as I did not make it. In essence MATLAB uses a machine learning algorithm that had listened to over 1000 gunshots, screams and explosions. It has categorized them, and used a number of features to notice the difference. Then when playing a new sound of one of these things (not heard by it before) it categorizes it and outputs it to the user. It also used a selection of sounds from the background to know when there is not one of these events happening, else there will false negatives.

One of our set ups to get a useful output and test the amplifiers were working properly.

All in all the project did actually work. It detected gunshots and screams being played into the microphone, and the triangulation algorithm worked, just not in real time. We managed to win the best masters project, mainly because we had good quality hardware, a partially working system and a good business case behind it. There is a lot of scope of where this project could go, and many things that could be improved, but we were happy with how it came out. I may be able to use some of the circuitry on other projects, who knows. If you are interested in more of the project, maybe some more detail about the hardware or manufacture, comment or message on Twitter. Thanks for reading.

A good example of how much difference there is between the microphones when a big sound was made. Minute distances made a big time difference.

Getting Ugly, Dead Bugs, and Manhattan Style

If you are anything like me, you love to build small circuits. I like to try and get my head around how things work by making it in front of me. This is usually in the form of breadboarding, but sometimes that doesn’t cut it, and soldering is needed. Veroboard tends to be my go to for building a simple circuit as something a bit more permanent, but it doesn’t always lend itself to certain designs. Take a design with lots of grounding points in the design, like an RF circuit, it can be difficult to have lots of ground strips everywhere, and the extra capacitance can mess with those high frequency signals. Also, designs with lots of different separate signal traces going round the board can make for a real pain. lots of slicing the traces, which tend to lead to mistakes. With my constant desire for order and straight lines, and pretty layouts this can get annoying quickly. Recently I have found a few new and simpler ways to throw together simple circuitry. For any budding electronic engineer, they are good skills to add to an arsenal.

A veroboard design of a hybrid microphone amplifier and level shifter I made for a recent project, prototyped on veroboard, many mistakes were made.

Ugly Circuits

As the name suggests, ugly circuits are not always the prettiest of designs. There are a few different definitions of what makes an ugly circuit, but my favourite is any circuit where the components are not completely mechanically connected to the substrate. The substrate usually being a copper clad board, but not always. This method can be a tricky one to master, as it is literally a balancing act. The prefered method that I see this being used is having a single copper clad board as a giant unobstructed ground plane. Two wire passives are usually the easiest to start with (standard resistors/capacitors), soldering one side to ground, then soldering the other side to another component in the air. This means any point that is not grounded is usually floating physically in the air (but depending on how good you are it could have floating voltage too). This can be a big benefit to RF circuitry or circuits that need good solid grounding. The unobstructed copper clad board means anything connected to it has a great connection to ground. It is fairly easy to build simple passive filters, but gets very fiddly and fragile if you aren’t careful.

A very “haywire” circuit constructed in the ugly style by Rick Anderson – KE3IJ in 2006. An experimental stage of his AGC-80 Regan receiver.
Not sure on the origin of this one, but it is more chaotic rather than ugly. It is definitely in the ugly style.

Technically ugly circuits don’t have to have a substrate at all, although it makes life easier. There are plenty of examples out there of ugly circuitry that just connects pins to pins via small wires. As said before, it can be very fiddly to make a circuit like this, but it is much cheaper to make singles as there is no need for expensive copper clad board. Plus after plenty of practice one can get very good at doing it. The wires connecting the parts together can be part of the structure of the unit, and if designed correctly could be very strong. The construction method can be useful in certain circumstances, and as long as you have the components, it can be build easily with just a soldering iron and solder. Although there are some amazing looking circuits made from this method, the majority do earn the name of an ugly circuit. If you can make a pretty one I would love to see.

Nathanxl at the Electro music forums creates some amazing almost artistic music project using the ugly style, but they look incredibly hard to make.
An Arduino Uno made without any substrate, just wires and components. Made by Kimo Kosaka, it is not an ugly, but it uses an ugly style of construction.

Dead Bugs

No, this method does not actually use dead insects as a manufacturing material, but it may look like it. The idea is to take an IC, traditionally in a DIP package, and place it upside down on the substrate. Usually glueing, but not always, with the pins facing upwards, so it has the look of a dead bug. The pins can be bent to attach to the substrate if required, but they tend to be facing up. Taking many methods from ugly, the pins are usually directly connected to passives or wires to other chips. This means the mechanical connections are usually in the air. The benefit to this method is that you don’t have to waste time drilling holes in in the substrate, and can integrate IC’s into an ugly design fairly easily. If trying to use this method, just be weary that all the pins on the chip will be the wrong way round as it gets flipped when placed upside down. I recommend making your own diagram to go from to make life easier.

As you can see in this use of dead bug mixed with ugly construction made by JCHaywire is the chip flipped over and the pins moved about with all the connections floating in the air

Although not really dead bugs, the concept can be seen in many modifications of PCB’s. It is easy to order the wrong package or get sections of pins wrong when designing and ordering PCB’s, especially if you have manually made the part. So it is not uncommon to find upside down IC’s on prototype PCBs or even sometimes on short runs. That being said, anything smaller than a DIP or SOIC package can get very fiddly, and is difficult to hand solder, and will need some extra magnification. Don’t be deterred though, there are many examples of even QFN and even BGA devices being hand soldered in the dead bug form, with very thin gauge jumper wires. With plenty of practice and spares, it can be a useful method of saving money without having a new run of PCB’s.

A bodge on a PCB before the real chip arrives, a 6650 is being used in dead bug style to get the circuit working by Dave Curran.

Manhattan Style

This one is my favourite styles of circuit design on the cheap and quick, and if done right can be very pretty and efficient. The big issue with the ugly method is that it is difficult to create, and often difficult to follow, and horrible to document. Manhattan is an upgrade, using cut out sections of copper board as small islands, much like manhattan. This method means there are no connections floating in the air, as all points on a component are mechanically connected to copper clad in some way, even if it is only a small bit. This leads to generally a much nicer laid out board, that can easily be followed and replicated. It also allows for use of SMD components, which is possible with ugly, but very difficult. The small pads don’t have to be separate, they can simply be cut outlines on the same backplane, making the process cheaper, but get it wrong and it can get messy. I much prefer manhattan as a quick construction method, due to its neat look and ease of use. Another reason for the name Manhattan is the fact the capacitors and resistors tend to line up and are perpendicular to the substrate, looking a bit like tower blocks and skyscrapers like Manhattan itself.

A great example of Manhattan style soldering by Dave Richards. Solid copper substrate with QRPme pads to attach components together. 
Another impressive circuit in the Manhattan style by Dave Richards, this one is a high performance regen receiver, with a full write up on his blog.
An example by VE7SL – Steve of making his own pads for his amateur radio transmitters and receivers, using an Ebay punch to make the pads.

One step on from Manhattan style, and the final step before fully fledged PCB’s is a little known style called Pittsburg, much like the steak. I have also seen it be called muppet style, and I am sure there are many other names for it. It is very similar to an actual PCB, usually etched, a layout is carved into the board, with traces and pads. The difference from a PCB is the fact there are no holes anywhere to be seen. Meaning you get the benefit of being able to etch a nice looking layout at home, and the benefit of not needing expensive routers/drills that quickly break. To allow for the pads to be soldered to as the main mechanical connection they are much bigger to allow for more solder on a bigger surface area. These pads would be overkill for a thru hole project, but also allows for easy use of SMD components. You can sometimes see specialist pads like Pittsburg to use SMD chips on a Manhattan style board. It is a matter of taste and confidence. These methods are obviously not suitable for all prototypes, but could come in useful for your next project. 

A Pittsburgh style PCB at one point sold by Joe Porter, unsure if they are still sold.

A good source of the small pads used in Manhattan can be found here. Reasonable price, and if you are doing lots of prototyping you can even buy the tools to make it yourself!

Thank you for reading, take a look at my other posts if you are interested in space, electronics, or military history. If you are interested, follow me on Twitter to get updates on projects I am currently working on.


How a Voltage Regulator Works: LM7805

Voltage regulators are one of the first electronic components you get introduced to as a hobbyist. Really useful when starting out, it simply takes a voltage that is too high, and reduces it down to a set voltage that you want, usually defined by the component. Solves the problem of having batteries or power supplies being a different voltage to the thing you are powering (such as your Arduino), and at as little as 50p from ebay they are easily acquired. Sounds like a great solution, but there is an issue, they are terribly inefficient. They are known to get very hot when used at high currents, and often need hefty heatsinks to stop the magic smoke from being released. To demonstrate why they get so hot we need to think about what happens during use. Remembering Kirchoff, the current going into a system is the same as the current going out of the system. If we use a simplified version of the regulator, the only thing this device changes is the voltage of the output. Due to the minimal current lost powering the circuit we assume the vast majority of power lost is in heat. Using the basic equation of:

Power (W) = Voltage (V) x Current (I)

So if we use an example of the LM7805 made by On Semiconductor (previously Fairchild) that can regulate 5V at 1A. It’s a pretty standard component, and is very typical of a voltage regulator.

If we use a 9V input the power going in is 9V x 1A = 9W.

The output power is 5V x 1A = 5W.

This means that there is 4W of power being dissipated from the regulator as wasted heat. This is a large amount when considering the size of the packages available. When thinking about problems excessive heat can cause in a circuit, it can quite easily damage itself and other components around it when not designed properly. It is why there are often big chunks of aluminium attached to the back of the components to act as a heat sink.

7805
7805 chip in a TO-220 package. Notice the heat sink on the rear with a screw mount.

This post isnt meant to dissuade you from using regulators, they have their place in electronic circuits, and are a great starting point. All electronic engineers need to have a broad understanding of the advantages and disadvantages of linear voltage regulators to be able to handle them properly.

How it Works

LM78xx schematic 2 coloured
Schematic of the silicon inside an LM78xx device, coloured relating to the function of each area.

The above schematic can be found on the datasheet, but it’s been coloured in to show the different sections of the circuit.

The most important component in the above schematic is Q16 (Red), it controls the current between the input and output, therefore the voltage. It is placed in a darlington pair configuration with Q15 (Orange). In this configuration Q16 is amplifying the current amplified by Q15. This means that Q15 can be used to introduce error feedback. The Blue section contains a voltage divider that scales the output voltage so that it can be used by the bandgap circuit. This bandgap circuit is found in the yellow section (Q1 and Q6). This bandgap reference produces an error signal that is fed into Q7 (orange). A bandgap is used because it can provide a stable output even when the temperature of the device changes.

The orange section takes this error and amplifies it through Q15 and the darlington configuration described earlier. The purple section has overheating protection (Q13) and excessive output current protection (Q14). Occasionally on these schematics you also find excessive input voltage protection marked as Q19 in this section. These shutdown the regulator in fault conditions like overcurrent or getting too hot. The Green section is known as the “start up” circuit, because it provides the initial current needed to power the bandgap circuitry. This gives a jumpstart to the circuit when it needs it.

I chose the LM7805 because 5V is a common value to be used, but the LM78xx series has many different preset voltage versions. The bandgap circuit is trying to get its input to 1.25V, this is from the voltage divider found in the blue section. As R20 is a variable resistor, the voltage divider can be calibrated during manufacture to output exactly 1.25V at any chosen output voltage. This is great for a manufacturer because they make lots of the same chip, and it can be made to suit any voltage output they want. This is also similar to the way some adjustable voltage regulators work, such as the LM317. In adjustable chips, the voltage divider is made by the designer externally, meaning it can be applied to any situation with a simple change of resistors.

Basic Configuration

Looking at the datasheet, there are many applications for the device. but the simplest one is just an input and an output. All that’s needed is a couple of decoupling capacitors to smooth out AC signals and random noise. Voltage regulators work best with clean, smooth power. There is also the need, due to the voltage drop across the transistors, for the input voltage to be at least 2V above the required output. This is always a good rule of thumb to go by when it comes to regulators.

LM78xx basic configuration
LM78xx basic configuration

I would recommend people read the datasheet and have a play with different voltage inputs and current outputs, see how easy it is for it to get hot. In that datasheet there are some other good applications using the device, you can turn it into an adjustable voltage output, constant current supply and high current supply. These are also good projects for learning more about transistors and op amps. Equally, there are other types and brands of regulator out there, some cheap, and some quite expensive, it is worth shopping around for  the ones that suit you.