Tag Archives: audio

Sugarcube, a grid based music controller with accelerometer

via Arduino Blog

sugarcube

 

Once again Amanda Ghassaei sent a cool project she’s been working on lately as an extension of the work she’s been doing on the monome project. Sugarcube is an open source, grid-based, standalone MIDI instrument  self-contained and relatively cheap to make. It communicates via a MIDI output with other electronic MIDI instruments and software environments like Ableton and MaxMSP.

An Arduino Uno generates all of its MIDI data and drives LEDS, buttons, a 2 axis gyroscope, a 3 axis accelerometer,  two potentiometers, and the whole device is powered by a lithium-polymer battery making it pretty portable.

She published detailed  documentation on Instructables to make one yourself   and shared a bunch of videos to discover its main features:

Basically this project is:

A portable, Arduino-powered, grid-based MIDI controller that boots up into a variety of apps to do lots of things with sound. The controller has 16 backlit buttons, used as both inputs and outputs to give the controller some visual feedback. 2 potentiometers give analog control, depending on the app the pots are assigned to tempo, MIDI velocity, pitch, and scrolling (making the avaible grid space larger than 4×4). An x/y accelerometer and an x/y gyroscope add some playful, gestural control to the device; most of the apps implement a “shake to erase” control and several respond to tilt in various ways.

It boots up into 7 different apps, though it has the potential to boot up into 16 total. This device is primarily a MIDI controller, but I’ve also written an app that allows you to pull the button and analog data into MaxMSP and to control audio.

With this project, I was interested in making a device that was a little more self-contained and relatively cheap to make (lots of buttons = lots of $). In keeping more with the concept of the tenori-on, this controller does all its app processing itself, it does not rely on a computer to process button presses/analog controls into MIDI. This means you can plug it directly into a synth or any device that understands MIDI and you’re good to go, no computer required. It runs off a beefy LiPo battery that keeps it running for days on a charge, so it’s fairly portable as well. In keeping with the monome side of things, it’s totally open source and can be adapted to your particular audio setup/needs. All the Arduino code is up on github, along with a MaxMSP patch that decodes data from the controller into something usable in Max.

sugarcube  Arduino

Graphic equaliser

via Raspberry Pi

Our good friends at Adafruit put this project on their Learning System earlier this month. It’s a beaut: you’ll learn something making it, and it looks fantastic when set up. Before we get into the nitty gritty, here’s some video:

This graphic equaliser (a spectrum analys/zer if you’re from the USA) is made from a RGB led strip, with everything down to the audio processing run on the Pi. Everything you see in the video is happening in real time. The setup runs Python, and is based on LightShowPi (which was originally designed to orchestrate Christmas lights), so you’ll be able add LightShowPi features like SMS control from your phone if you’re an advanced user.

Some soldering is required – but soldering is easy, and this is a good project to earn your soldering wings on if you haven’t already. There’s the usual full and helpful tutorial over at Adafruit, along with tips, a parts list, code and all that good stuff. I wish I’d had one of these for my student bedroom. Imagine the parties!

Arduino Yún with sound the supereasy way

via Arduino Blog

Arduino Yún

 

 

During Codemotion Milano Stefano had a talk with Federico Vanzati from Officine Arduino on how to use a supercheap USB Audio card with Arduino Yún and test the full audio capabilities with zero effort, external libraries or mp3 shields.

After some days he came out with a quick tutorial that you can check out here (includes code!).

 

 

RaspyFi – a distro for music lovers

via Raspberry Pi

RaspyFi was brought to our attention a few days ago: it’s a distro designed especially for those with big media libraries who are using their Pis to listen to music. If you’re one of those people (I am, and I’m chuffed to bits to find RaspyFi), or an honest-to-god audiophile, you may have noticed that other media centre distros have been built to prioritise video rather than music, and don’t necessarily support all the formats your collection might be made up of; or give you the fine degree of control you want over volume and playback. And if you want to stream music wirelessly to other devices on your network, you’ll have to do a little more work with a traditional Raspberry Pi media centre (I can’t believe I’m saying “traditional” about a device that’s only been on the market for 18 months) to get everything working.

So RaspyFi has been engineered to address those issues. Apple AirPlay works out of the box, so you can stream to other devices without any extra work. The distro supports a large number of external USB DACs (there is a pleasingly lengthy list on the project website) and asynchronous playback, so you can use your other amplifiers and DACs instead of the one that’s onboard the Pi – which, let’s face it, wasn’t built for audiophiles.

The UI is really slick, and offers you a web interface you can use to control all your devices, so you can get to local or streamed content from your desktop, phone or tablet. I’ve been enjoying it so far: it’s intuitive, I can play music on any networked device with a web interface without having to install anything, and AirPlay just works - which is very pleasing.

Have a look for yourself. You can download RaspyFi (currently v1.0) from the project website. Documentation, help and tutorials are all available too – let us know what you think!

Building an audio box out of thrown away boards

via Hack a Day» hardware

The last time [Mark] was at the scrap yard, he managed to find the analogue input and output cards of an old Akai DR8 studio hard drive recorder. These cards offered great possibilities (8 ADC inputs, 12 DAC outputs) so he repaired them and made a whole audio system out of them.

The repair only involved changing a couple of low dropout regulators. Afterwards, [Mark] interfaced one of his CPLD development boards so he could produce some sine waves and digitize signals generated from a PC based audio test unit. He then made the frame shown in the picture above and switched to an Altera Cyclone IV FPGA. To complete his system, he designed a small board to attach a VGA screen,  and another to use the nRF24L01 wireless module.

Inside the FPGA, [Mark] used a NIOS II soft core processor to orchestrate the complete system and display a nice user interface. He even made another system with an USB host plug to connect MIDI enabled peripherals, allowing him to wirelessly control his creation.


Filed under: hardware

Giving toys an electronic voice

via Hack a Day» hardware

sound

Whether it’s a Furby or Buzz Lightyear’s button that plays, ‘To infinity and beyond’, most digital audio applications inside toys are actually simple affairs. There’s no Arduino and wave shield, and there’s certainly no Raspi streaming audio from the Internet. No, the audio inside most toys are one or two chip devices capable of storing about a minute or so of audio. [makapuf] built an electronic board game for his kids, and in the process decided to add some digital audio. The result is very similar to what you would find in an actual engineered product, and is simple enough to be replicated by just about anyone.

[makapuf]‘s game is based on Game of the Goose, only brought into the modern world with electronic talking dice. An ATtiny2313 was chosen for the microcontroller and an AT45D 4 Megabit Flash module provided the storage for 8 bit/8khz audio.

The electronic portion of the game has a few functions. The first is calling out numbers, which is done by playing recordings of [makapuf] reading, ‘one’, ‘two’, ‘three’, … ‘twelve’, ‘thir-’, ‘teen’ and so on. This data is pumped out over a pin on the ATtiny through a small amplifier and into a speaker. After that, the code is a simple matter of keeping track of where the players are on the board, keeping score, and generating randomish numbers.

It’s an exceptional exercise in engineering, making a quite complicated game with a bare minimum of parts. [makapuf] estimated he spent under $4 in parts, so if you’re looking to add digital audio to a project on the cheap, we can’t imagine doing better.

You can see a video of [makapuf]‘s project after the break.


Filed under: digital audio hacks, hardware, toy hacks

Raspberry Pi, for all your 50s diner needs

via Raspberry Pi

Have you ever been to a cafe or restaurant with 1950s jukebox wallboxes in each booth? Wallboxes were an extension for a jukebox, making it more convenient to select music right from your table. You’d drop a coin in, choose a song from the flipbook behind the glass, chrome and plastics, and the machine would send pulses down a wire to the restaurant’s jukebox, where a stepper would decode the pulses and queue up the song you’d picked. Refurbished wallboxes occasionally pop up in mock-50s diners; you’ll also see them for sale on eBay for anything up to a few hundred quid, and people buy them to add to their jukeboxes, or just as home decoration (I’ve seen one being used as a particularly cumbersome phonebook).

Wallbox in situ

Steve Devlin bought himself a couple of wallboxes a few years ago, meaning to hook them up to an MP3 player. He then switched over to a SONOS wireless media system in his house, and forgot about the wallboxes for a couple of years.

Enter the Pi.

On looking at a Raspberry Pi and a wallbox, Steve had an idea. Why not hook the two up together to make a controller for the SONOS system? The Pi decodes the pulses from the box, and sends the information to the SONOS system. (This approach will work with any UPnP protocol, so you’re not limited to using SONOS.)

Steve’s thinking about further customisation: a strip in the box with Radio 4 on it; some dynamic strips like “songs of the week”, which will play a selection of the week’s most-played tunes; some LEDs to show a binary index of common faults, like the wifi being down, or a song not being found.

There are full instructions and much more information on Steve’s website. We think there’s something really compelling about this mix of old and new; thanks for sharing, Steve!

TRUE ANALOG AUDIO VOLUME CONTROL (T.A.A.V.C.).

via coolarduino

More:   Video1   and   Video2

Now my Arduino can precisely measure audio input (VU meter),   and obviously, next thing that comes to mind right after measurements, is regulation or control. There are many different ways how to electronically adjust audio volume or level of AC signal.  I’ll name a few:

  • Specifically design IC, Digital potentiometers.
  • Mechanical potentiometers, driven by servo / motors.
  • Vacuum tubes amplifiers in “variable-mu” configuration.
  • Resistive opto-isolators.

First category (#1) fits nicely for arduino project. But it’s not interesting to me. My apologies to someone, who was searching an example of interface between arduino and digital pot. Other people don’t tolerate semiconductors in audio path ( tube sound lovers ). Third option would make them happy, only (#3) requires high voltage and difficult to accomplish on low hobbyist budget, so I left it out of the scope. Mechanical pot (#2) would be good solution to satisfy Hi-Fi perfectionists and arduino fans. The same time response time of mechanical parts is too slow, verdict – discarded.  (#4) have been in use since 1960s, but would you like your lovely music to be adjusted by highly toxic CdSe / CdS ?  I don’t think so. Wiki says opto-isolators have low THD distortion level, less than 0.1%. Probably true, but apart from technical aspect, there is always psychological, poisonous CdSe affects my perception.

How about variable resistor in it’s simplest form – tungsten wire? Where you can get one? In the electrical bulb. Perfect material for audiophiles – where distortion could get into ? – It’s pure metal ! And here is my design of the “basic cell” – True Analog Audio Volume Control (T.A.A.V.C.)

Analog_Volume_Control_(theory)

As you can see, cell consists of 5 bulbs plus 1 resistor. All elements form 2 attenuation stages, basically – voltage dividers with variable resistors. Resistive values of bulbs proportional to temperature, which is easy to control passing DC current through. To make it work with the biggest possible dynamic range, middle bulb is also heated up by current flow from two differential control lines / phases.

 Hardware prototype / Proof of Concept.

Analog_Volume_Control_double_diff_simple

Differential Power Amplifier (PA) IC LM4863  is used as DC current source for control lines. Circuitry powered from 5V regulated switching power supply (4A).  Bulbs – clear mini lights, 2.5V, approximately 200 mA. Cold state resistance about 1.2 – 1.5 Ohm, hot state resistance is rising up to 15 Ohm.  Volume regulator could be connected to any audio source with output impedance no more than 32 Ohm, for example, headphones output. For test I used second channel of the PA, that shown in “optional” box on the left side. Second channel is a “nice to have” feature  in stereo version of the project, when both channels would drive two separate TAAVC cells, so using it as a “buffer” amplifier may be not an option.

Results.

  Measured attenuation  range of the “basic cell” is  20 dB, or 10 x times.

266c260c 264c

 to be continue…

 Chart, PWM (Voltage) to Attenuation:

chart

 Quite interesting, isn’t it? I was not expecting it’s to be linear, but changing direction surprised me. There is one things, which could explain such abnormality, is that when voltage on the control lines 1 and 2 ( LM4863 outputs ) is approaching power rails, output impedance of the power amplifier is increasing, and consequently, attenuation characteristics of the basic cell deteriorate. It means, that in order to keep attenuation curve gradually declining, more powerful PA necessary. For now, I limited PWM to 0 – 200 range.

I’m thinking, STA540  powered from +12V, and 5 V bulbs would make sense to try next time.  Probably, replacing middle bulb for less current hungry, will increase max attenuation per cell up to 30-35 dB.

 O’K, after I get this data, how could I “straighten it up” for practical use ?  Volume control device, could be linear or logarithmic, but chart doesn’t resemble nether of this. And this is exactly what I need Arduino for.

Linearization.

 If you, by chance, have read this page, than you know how to do this part. Polynomial approximation. Unfortunately,  2-nd degree polynomial I used last time is not enough for VERY non-linear curve like I have. So, I “upgraded” my calibration subroutine (method: LEAST SQUARES) up to 3-rd degree:

void calibrate()
{
 //Least squares 3-rd degree polynomial coefficient calculation
 float arr[10][5] ={{0},{0}}, err[10] = {0}, coeff[10] = {0};

 err[0] = 10;
 for(uint8_t i = 1; i < 7; i++)
 {
  err[i] = 0;
  for(uint8_t j = 0; j < 10; j++)
  {
   err[i] += pow(level_table[j], i);
  }
 }

 for(uint8_t i = 0; i < 4; i++)
 {
  for(uint8_t j = 0; j < 4; j++)
  {
   arr[i][j] = err[i+j];
  }
 }

 for(uint8_t i = 0; i < 4; i++)
 {
  arr[i][4] = 0;
  for(uint8_t j = 0; j < 10; j++)
  {
   if (i==0) arr[i][4] += calibration[j];
   else arr[i][4] += calibration[j] * pow(level_table[j], i);
  }
 }

 for(uint8_t k = 0; k < 4; k++)
 {
  for(uint8_t i = 0; i < 4; i++)
  {
   if ( i != k )
   {
    for(uint8_t j = (k + 1); j < 5; j++)
    {
     arr[i][j] -= ((arr[i][k] * arr[k][j]) / arr[k][k]);
    }
   }
  }
 }

 union split_float {
 uint16_t tegri[2];
 float loatf;
 } sf; 

 for(uint8_t i = 0; i < 4; i++)
 {
  coeff[i] = ( arr[i][4] / arr[i][i]);
  sf.loatf = coeff[i];
  store_entry(( 2 * i ), sf.tegri[0] );
  store_entry(( 1 + (2 * i)), sf.tegri[1] );
 }
}

Procedure takes 10 data samples as input, calculates 4 coefficients and stores them in EEPROM memory.

VU meter based on Arduino UNO ( in minimum configuration Arduino and DC offsetting circuit ) should be connected right to T.A.A.V.C. output. Everything works in automatic mode, with results printed on serial monitor for review. Stable AC input is necessary, which easy to get from any PC sound card based signal generator, recorded media file or lab sine-wave generator. Arduino also provides PWM for T.A.A.V.C       via pin D3 (TIMER2 OCR2B).

TAAVC_Calibration

Link to download Arduino UNO sketch: T.A.A.V.C.

to be continue…audio compressor, .

Last part,

Dynamic Range Compressor.

There are two important parameters defined in the beginning of the sketch:

#define          CMP_THRE                     -10             // Compression Threshold 
#define          CMP_RATE                        4             // Compression Ratio 4 : 1

Threshold and Ratio. I’m not into explaining all bunch of the details about compressors or what for do you need one, rather forward you to this link.  I only want to say, that I didn’t find any evidence that someone ever used electrical bulbs as compressors “engine”. So, this is my idea, and my implementation.

Technical specification of this design is quite modest, having close to 20 dB maximum attenuation and setting ratio to 2:1, threshold couldn’t be set lower than -40 dB. Good news, that for practical use in home environment it’s  really unlikely, that you ‘d need more. It’s also should be enough to solve a problem with annoying TV or Radio commercial / advertisement.

Compare to VU Meter project, I’ve made a few “relaxing” changes to the code, as it appears there are no strict industry standard on Dynamic Range Regulation. I reduce sampling rate down to 10 kHz,  and  split Low Pass Filtering in two sections. One is the same, as in VU Meter, inside sampling interruption subroutine, only with lower time constants. First LPF section is responsible for “shaping” attack and decay timing. Using quite inertial electrical bulbs in the project, reduce importance of this timing. Here attack and release mostly defined  by thermal responsiveness of the bulbs, which isn’t very high. Decreasing software LPF time constants helps to improve sensitivity. Other LPF section included inside LCD drawing function, works to overcome display slowness, suppressing LCD flickering. Other changes from simple VU Meter, is that finally I “scaled” everything correctly,  and “0″ db corresponds exactly to 1.228 V RMS at the input. Threshold level -10 expressed in dB as well. You may see threshold “mark” above the log scale. Indicator “needle” just below it, small 5×2 pixels only, but you can make it bigger if you wish.

275a

I already described calibration procedure, to do it right, you need to connect arduino to output of the TAAVC cell.  Polynomial coefficients and minimum / maximum constants stored in EEPROM, so you don’t have to do this procedure each time after power cycling.  In normal mode arduino getting input measurements from the cell input:

Analog_Volume_Control_Compressor

Finished.  I’ll do a video “on demand” -);  If I had time…

Arduino UNO sketch:  Audio Dynamic Range Compressor. (TAAVC part 3).


MakerLab reviews the Arduino Starter Kit

via Arduino Blog

When we released the Arduino Kit, we knew that we are equiping the closet-wannabe-makers to start planning for world domination. Now it has the stamp of approval from MakerLab too!

Make Noise With The New Arduino Kit is a project by Alessandro Contini (@CNTLSN) and Alberto Massa (@nkint)

The above video explores the basic components of the kit and things that a new-maker would want to start with, including a light controlled theramin, and by theramin, I really mean exploring every possibe way to make impressive noises from one simple experiment.

Sounds fun? Do write to us, what you made out of your starter kit. We may feature you next ;)

Via:[MakerLab]

Media streaming without Air Play

via Raspberry Pi

Just before the New Year, we saw a lot of links in the tech press to a very neat hack using a Raspberry Pi as an Apple AirPlay receiver. The project had so many news stories written about it before I’d spotted it that I didn’t put it on this blog at the time because I thought most of you would have seen it – but do go and have a look if you’re a iTunes person (and have managed to get your head around the new layout of the library in iTunes 11 – my own failure to have got accustomed to it so far makes me worry about brain softening).

If you’re not an iTunes person, and you’re looking for an open alternative, you could do a lot worse than use Stephen Phillips’ UPnP/DLNA streaming method, which uses Android phones as remote controls. Your music lives on a server, and streams to your home speakers via the Pi. You can also play your music by streaming it to any of those phones, whether you’re at home or out gallivanting.

If you already have at least one Android device and some speakers, Stephen reckons that your outlay, including the Pi, should be about £45 – contrast this with the cost of a similar (closed) setup using Sonos hardware (today’s price on Amazon, with a sale on, was £230). Audio quality should be as good as – or even better than, depending on what your home hi-fi setup is like – an off-the-shelf solution using AirPlay, Sonos or Squeezebox, despite coming in at a fifth the price.

This is something I’ve been meaning to set a Pi up at home to do for ages (a little thing called work has got in the way). If you want to make your own streaming setup, Stephen has easy-to-follow instructions on his blog.

 

Radio-4-Matic

via Raspberry Pi

Update, Jan 12: Cargo Cult (whose name is actually Adam Foster) found that a lot of people were very interested in this project. Not least, Radio 4. Who interviewed him for the PM programme this afternoon about his hack. You can hear the programme at the PM website – listen now, because I can’t guarantee how long this will stay up! Adam’s bit starts at 27m00s.

I know several of you are making your own version of this project. Adam’s now blogged all the code you’ll need and very thorough instructions: so you’ve got no excuse for not getting started!

I’ve got a longstanding addiction to BBC Radio 4. It’s my alarm clock, keeps me company in the car, gives me something to shout at, and occasionally furnishes lovely surprises (like New Year’s morning last week, when the Raspberry Pi got a shout out on the Today program, and then Eben’s Dad was on ten minutes later talking about English dialect).

It can be a bit discombobulating trying to listen to Radio 4 online when you’re out of the country – Listen Again isn’t available for a day or so, and if you listen live, nothing is on at the right time. I must be woken by the soft keenings of James Naughtie, or else the day just doesn’t go right. PM must start at 5pm, and always coincides with a cup of tea. The Archers at 7 is a reminder that it’s time to turn off the radio, get out of the study and make dinner. Time-shifting any of these things just makes the day shapeless and wrong. Happily, our forum member Cargo Cult has experienced the same discombobulation. So he’s used a Raspberry Pi to build a time-travelling radio. He says:

Timezones. It’s live radio, but all the timing is wrong. Namely, the written-in-stone Radio 4 schedule must not, under any circumstances, be allowed to become misaligned from the rising and the setting of the sun. How could anything (or anyone) remotely British even think of operating normally if the Friday evening comedy gets broadcast on Friday morning, or if the Book at Bedtime arrives early in the evening? Or heaven forbid, if Woman’s Hour escapes from its usual 10am ghetto?

So, short of removing both the North American continent and the Atlantic Ocean in order to make Seattle a suburb of Plymouth, we’re going to have to take the existing internet radio streaming and add a timezone-busting delay. Oh, and then wrap the whole thing in a suitably middle-class casing complete with a Royal warrant of appointment.Luckily, we moved west of the Prime meridian, so we can get away without using actual time travel.

Cue the Radio-4-Matic.

From the outside, the Radio-4-Matic looks just like the old Roberts radio my Grandma had in her kitchen. It’s had a Pi inserted into its helpless torso. The LW, MW and SW buttons provide line-in audio from the Pi’s analogue audio-out – VHF still operates as a regular radio. And the audio that’s coming from the Pi is BBC Radio 4, time-shifted so that wherever you are, the shipping forecast is on at twelve minutes to one in the morning. Ford’s in his flivver, all’s well with the world.

Cargo Cult hasn’t written a how-to guide yet (he does plan to), but he has an excellent description of what he did with enough pointers in there to allow you to set one up yourself if you’re a relatively seasoned coder. You can read more (and ask questions) in this thread in our forums.

Hacking an old radar gun to interface with a laptop

via Hack a Day» hardware

[Gregory Charvat] decided to see what he could do with this old Police radar gun. It is an X-band device that broadcasts continuous waves and measures the Doppler shift as they echo back. He cracked it open to see if he could interface the output with a computer.

After a little poking around he’s able to get it connected to a 12V feed from his bench supply, and to monitor the output with an oscilloscope. He established that it draws about 0.5A in current he built a companion board which uses AA batteries for power, and provides an audio output which can be plugged into his laptop’s audio-in jack. This technique makes reading the device as easy as recording some audio. From there a bit of simple signal processing lets him graph the incoming measurement.

In the video after the break you’ll see his inspection of the hardware. After making his alterations he takes it into the field, measuring several cars, a few birds, and himself jogging.


Filed under: digital audio hacks, hardware

Pumpkin Pi

via Raspberry Pi

We’re on the hunt for guest posts for a couple of weeks in November. See this post for more details on how to contribute.

There seem to be a lot of Raspberry Pi + pumpkin projects around at the moment. Can’t think why.

Scary bucket

Gordon@Drogon’s Pumpkin Pi (as featured in the MagPi). Gordon had to photograph this in the summer, when pumpkins were not available, so he’s used a sort of Halloween bucket instead. Click the picture for instructions and more bucket photos.

There’s non-pumpkin spooky activity out there too. I love this: it’s a Raspberry Pi, an eight-switch relay, a garage door lifter rod, and a can opener, all hacked together to make a candy dispensing machine so you don’t actually have to interact with any children or open the front door on Halloween.

I love this even more: it’s a Raspberry Pi and a Makey Makey in a box, hooked together to make a Halloween sound box that uses the conductivity of your fingers to trigger events.

And Shawn Wallace at Make has made this, with an Arduino, a Pi, some switches and a recording of the Wilhelm Scream. Visit Make for complete instructions on making your own.

Do you have any Halloween Pi plans? Let us know in the comments.

Sound Localization.

via coolarduino

Updated on 16 Oct. 2012.

Well, it’s elementary simple in theory, how to do sound localization based on phase difference of signals, that received by two spatially distant microphones. The Devil, as always, in details. I’ve not seen any such project created for arduino, and get curious if it’s possible at all. Long story short, here I’d like to present my project, which answer this question  - YES!

Let me stress, project based on phase delay, not TDOA.  Measurements results show, that current version of software (both copy of the source code, linked  below, they differ only in filtering technics) has minimum detectable phase offset 1 degree!!!

This gives astonishing special resolution. For example, 10 kHz sound wave has length in the air about 34 millimeters, and if I divide it by 360 degree – full period, I’d get about  0.1 millimeters per 1 degree of phase shift..

Of course, as object getting away from the microphones, accuracy would proportionally deteriorate. What important is a ratio between distance to the object and distance between two mic’s (base). Having the base equals to 65 millimeters,  device you can see in the video, capable detect location along horizontal line with accuracy 1 meter at distance 650 meters. Theoretically.

Moreover, quantity  of electronics components not much differs from what I’ve used in my previous blog.  Compare two drawings, you will notice only 4 resistors and 4 electret microphones (mic’s) were added! All circuitry is just a few capacitors, 9 resistors, one IC and mic’s.  Frankly speaking, writing a remix of oscilloscope, I was testing  an arduino analog inputs, keeping in mind to use it in junction with electret microphones in other projects, like sound pressure measurements (dBA),  voice recognition or something funny in “Color Music / Tears of Rainbow” series. As they call it – “a pilot” project?.  There are some issue (simplest ever) oscilloscope has, when doing fast rate sampling with 4 channels (settings 7, 8 and 9 Time/Div ) I already described, so I slightly reduce sampling down to 40 kHz here.





Note: *All of the above true for Arduino Leonardo. Hardware and Software would be different for arduino boards based on different chips, and must include pre-amplifiers with AtMega328 uCPU. 

One more important things to mention in this short introductory, as I used FFT algorithm for phase calculation ( I like FFT very much, you probably, already notice it ),

Arduino is capable not only track a flying object in 3D space, it also could identify / distinguish this object based on spectral characteristic of the radiated sound, tell if it’s aircraft or helicopter, what type / model, and for living species like insects it could tell if its MALE of FEMALE !!!!!

                  SOFTWARE.

  As I say above, I choose 40 kHz for sampling rate, which is a good compromise between accuracy of the readings  and maximum audio frequency, that Localizator could hear. Getting signals from two mic’s simultaneously, upper limits for audio data is 10 kHz. No real-time, “conveyor belt” include 4 major separate stages:

  • sampling X dimension, two mic’s (interleaving);
  • FFT
  • phase calculation
  • delay time extracting
  • sampling Y dimension, two mic’s;
  • FFT
  • phase calculation
  • delay time extracting

4 mic’s split in 2 groups for X and Y coordinate consequently. Picking up 4 mic’s simultaneously is possible, but would reduce audio range down to 5 kHz, so I decided to process two dimension (horizontal and vertical planes)  separately, in series. Removing vertical tracking from the code, if it’s not necessary, would increase speed and accuracy in leftover plane. I’d refer you for description of the first and second stages to other blogs, FFT was brought w/o any modification at all. Essential and most important part of this project, stages 3 and 4.

Phase Calculation (3).

 Mathematical tutorial on a topic, I’m not any good as a teacher, so you better read somewhere else, to brush up a basic concept. Core of the process is arctangent function. This link says a number of cycles. In two words – too slow.  LUT ( Look Up Tables ) is the best solution for no-float uCPU to do complex math extremely fast, and reasonably (?) precise. Drawback of LUT is limited size, so it could be saved in FLASH memory, which in next tern  is also limited. This is what I did on “resource management” side: 1 kWords ( 16-bit integers, 2 kBytes) , 32 x 32 ( 5 x 5 bites) LUT, scaled up to 512 to get better “integer” resolution. There are a few values in top-right corner, that melted together as their differences are less than “1″ (not shown on the picture on right side). The “worst” resolution is in top-left corner, where “granularity” is reaching 256, or unacceptable 50% of the dynamic range. To stay as far away from this corner, I put a “Rainbow Noise Canceler” – single line with ” IF ” statement, which “disqualifies” any BIN with magnitude, calculated at the FFT stage, lower than 256.

IF (((sina * sina) + (cosina * cosina)) < 256) phase = -1;

 I called it “Rainbow” because of it’s shape, “red line” is an arc, going from 16 on top line to 16 on left side. Also, “Gain Reset” – 6 bit ( depends on the FFT size, has to be 6 bits for 128) was reduced to 5 bits, in order to get better sensitivity. This two parameters / settings, 5-bit and 3.5 bit magnitude (256) limit, create a “threshold” for weak spectral peaks. Basically, depends on application, both values can be adjusted in  different proportions.

 There are two category of tracking technics, with mic’s installed on moving platform, and stationary mic’s. First one is a little bit easier  to understand and build, calculates Relative direction to sound source. This what I’ve done. Stationary mic’s approach, when motors are moving laser pointer (or filming camera) alone, would require Absolute direction to sound source, and must include stage #5 – angle calculation via known delay time. Math is pretty simple, acrsine function, and at this point in program only one calculation per several frames would be necessary, so floating point math wouldn’t be an issue at all. No LUT, scaling, rounding/truncation. Elementary school geometry knowledge – thats all you need.

Delay Time Extraction (4).

 Subtraction phase value of one “qualified” mic’s data pull from another, produce phase difference. To turn phase difference in delay time, division by BIN number is performed. Lets call this operation “Denominator” process.  The denomination is necessary, because all data after this step going to be combine and process together, doesn’t matter of wave length, which is different for every bin. Frequency and wavelength related to each other via simple formula:  Wavelength = Velocity / Frequency, where velocity is a speed of sound wave in the air ( 340 m/sec at room temperature). As distance between two mic’s is a constant,  sound with different wavelength ( frequency ) produces different phase offset, and denomination make them proportional. (WikiPedia, I’m sure, would explain this much better, mind you, I’m a Magician, not mathematician).

First picture on right side shows  ”Nuisance 3: Incorrect arctan” correction. You will find two lines with “IF” statements in the code related to stage #3.

Second picture,  gives you an idea why one more correction at stage #4 is necessary As you can see, subtraction one arctan from another generates a rectangular “pulse” ( Diff. n. corr., violet line), whenever one function changes sign but other (delayed version) not yet. Light blue line (DIFF(B)) doesn’t have such abnormality. Math is simple, just two lines with “IF’s” in the same manner, only “double size” constants this time. 2048 on my scale corresponds to 2 x PI, 1024 – PI, and 512 – PI / 2.

Arduino has only 1 ADC, so there is always constant delay time equals to one sampling period ( T = 1/40 kHz = 25 usec), which also should be subtracted ( or added, depends how you associate input 1 and 2 – left / right side mic.)

Filtering.

 To fight reverberation and noise, I choose a Low Pass Filter, which I’d call here as a “Rolling Filter”. My research with regular LPF, shows that this class of filters is completely NOT appropriate for such type of data, due their high susceptibility to “spikes”, or sudden jump in magnitude level. For example, when system getting steady reading from 2-3 test frequencies with low values, let say -10, simple averaging ( should be -10 ) results will be corrupted with one accidental spike (magnitude +2000) during next 60 – 100 consecutive frames !!!  The Median Filter doing well eliminating sudden spikes, the same time is very hungry to CPU cycles, as it’s using “sort” algorithm each time new sample was arrived to the data pull. Having 64 frequencies, and setting filter kernel to 5 – 8 samples, arduino would be buried doing sorting at almost 40 ksps.  Even processing each frequencies data not individually,  and sorting only one 64 elements array still very time consuming job.  After thinking a while, I came up to conclusion, that “Rolling Filter” has almost the same efficiency as Median, but instead of “sorting” requires only 1 additive operation! On long run, the output value will “roll” and “stick” to the middle of the pull. ( Try to model it in LibreOffice. )  Adjusting “step” of the “Rolling Filter”, you can easy manipulate responsiveness,  which is almost impossible with Median Filters. (Things TO DO: Adaptive Filtering, real time adjustment depends on input data “quality”).

 To be continue…. 

Link to Arduino (Leonardo) sketch:  Localizator-beta-9.

 3 October 2012

Video clip posted. Arduino is running slightly modified version of software. Changes were made in the filtering algorithm, in order to eliminate motors interference. As you can see, one of the servo (Y dimension) is mounted at the back of moving platform, in close proximity to the mic’s. Filtering includes two stages this time,  “Rolling Filter” in every bin, plus averaging values  that are over noise canceling threshold. First stage is reducing phase noise at specific frequency. Second one, important in close environment with strong reverberation, when frequencies “appears” to come from different directions, even they all originated from the same source.

Link to Arduino (Leonardo) sketch:  Sound_Localization.

More Video:

Video-1

Video-2

 

 16 Oct. 2012

Version 3, and I think, it’s final release. I greatly re-worked sampling subroutine, with main goal to reduce a phase noise as much as possible. ADC is in auto triggering mode, via TIMER0, start conversion events strictly synchronize.  Please, read more details in this blog, at the end. Sampling rate pushed up to 50 ksps, providing 12.5 kHz audio range. That is much more, than small radio you can see in the video above could even reproduce!

Link to Arduino (Leonardo) sketch: Version 3 (Final)


Audio VU meter (AC microVoltmeter) with Extra wide Dynamic Range 69 dB.

via coolarduino

O’K, after having some fun with stereo version of the VU meter I described in my previous blog-post, now it’s time to do a serious stuff. Studio grade VU meter !!! 24 steps, equally spaced every 3 dB, covering Extra wide Dynamic Range from -63  up to  +6 dB.  Single (mono) channel this time, no messing around, absolute precision at the stake. Plus, it keeps absolutely Top-Flat linear frequency response from 40 Hz up to 20 kHz(*).

 

 

I’m not going into details of RGB LEDs Display, which has no modification since “Tears of Rainbow” project, only plates installed in one line, form a single GIGANTIC bar-graph. There are some minor changes in mixing colors data tables, but they intuitively understandable.  The most important feature in this project is autoscaling. As you, probably know, Arduino has 10 bits ADC. Only it can’t process negative half-wave, and for this reason it has only 9 bits available for AC measurements.  According to DSP theory, maximum dynamic range is:

DR = 1.77 + 6.02 x B = 1.77 + 6.02 x 9 = 55.95 dB.

 As input audio waveform represents anything but perfect peak-to-peak 5V sine-wave, real dynamic range would be lower. How much? In first, there is a hardware limits.  OPA (NE5532), which is:

  • very low noise !!!
  •  high output-drive capability;
  •  high unity-gain and maximum-output-swing bandwidths;
  •  low distortion;
  •  high slew rate;
  •  input-protection diodes, and output short-circuit protection

 but, unfortunately,  isn’t rail-to-rail type. Test results show, that compression  become noticeable (~1 dB) when not scaled magnitude approaches level about 50 dB. That is in good agreement with observed on oscilloscope not distorted deviation peak-to-peak 2.5 V. Or only half of full range of 5V. And as theory says, half is one bit less, and real DR = 1.77 + 6.02 x 8 = 49.93  (~50 dB). In second, audio data is processed on “block” structure basis. It means, having average of the block 50 dB, doesn’t mean that there was no spikes in the sampling pull, that obviously would be clipped and introduce error in the measurements results.  This phenomenon is defined as Crest Factor. Different sources estimate crest factor of musical content between 10 – 20 dB.  So, taking direct approach, Arduino with OPA mentioned above as front-end could accurately cover only:              50 – 20 = 30 dB.  To get wider dynamic range, I have to scale input amplifier gain, and this is exactly what I did, building amplifier in two stages and selecting one cascade (by-passing second one) or two cascades using internal ADC multiplexer. As there is no switching IC in analog signal path involved, gain is defined with high stability, could be one time precisely measured – calibrated via coefficient stored in EEPROM (nice feature to add).

On the right side there are electrical drawings of “slightly” modified kit,  where stereo amplifier was converted into 2 stage mono version. First stage, with gain about  G1 = 1 + 10 k / 1 k = 11  is necessary to “bump-up” line-level signal, to create DC bias required for correct operation of the ADC, and also served as buffer to lower signal source impedance, as it seen by ADC input.  I set a gain of the second stage amplifier at 40 dB:  20 x Log_10 ( G2 ),     where    G2 = 1 + 100 k / 1 k = 101.

IMHO, setting gain limit for only 30 db per stage as it follows from paragraph above, is overkill, and would be justified for “real-time” radio broadcasting or audio processing for storage media, when high fidelity of audio program must be preserved. For visual display “clipping” of bursts in signal is not noticeable at all due high refresh rate of display, 78 Hz. Human just can’t see, if LED lights-up with such speed.  For steady AC amplitude measurements (micro Voltmeter mode) this is not a problem at all, and headroom as small as 3 dB would be sufficient, leaving wide 47 dB per stage.

 Software

  There are two thresholds are defined in program, where switching between one or two stage amplification is happening:

      if ( magn_new <=  44 ) sensitv = 1;

      if ( magn_new >= 47 ) sensitv = 0;

  44 and 47, with hysteresis 3 dB. First line defines switching to high sensitive mode (overall gain 1100), and second line, does exactly opposite. Look at the chart, hope it would save me a million words -);

 Couple words on using this device as precise AC micro-voltmeter. Having 1100 overall amplification as add-up to already quite sensitive Arduino ADC, driving overall sensitivity to enormously  5 / ( 1024 x 1100 ) = 4.439 uV Special care should be taken on grounding, shielding of amplifier PCB, probably, EMI suppressor ferrite chokes wouldn’t be an excess in power line and signal path.   In my project, w/o any modification to original kit’s board (except couple jumper wires to cascade two stage amplifier) of course, I was not expecting to get to such high sensitivity level. Moreover, in project arduino is driving LED display, “ADC noise reduction mode” is off, plus ADC is working on double speed – preselector set to 250 kHz!!!  And this is why constant 14 was subtracted in software from magn_new, just before it goes for BarGraph “mapping” procedure:

      magn_new  -= 14;

Basically 14 is a noise flour of my analog front-end.  Approximately 51 micro volts AC is turning on first LED bar. Look at the table, which reflect my current hardware set-up.

* Other things to keep in mind, there is a “gap” 78 Hz wide in frequency range at 10 kHz,  It introduces a small error, about  78 / 20.000 = 0.39% in white noise measurements result. For musical content, which has really low power density level at 10 kHz, magnitude of error would be much lower, probably, less than 0.05 %.

 Running FFT in code creates great opportunity to reject any interference in the audio band. For example, if there is a noticeable hum from electrical grid lines in the content, issue easily could be fixed NOT including bin[1] in final sum of magnitude calculation. Though to make it works more efficient, some adjustment in sampling period would be necessary, setting bin[1] frequency precisely at 50/60 Hz.

 One more advantage of having FFT based  filtering     (primary mission is HPF, look in stereo VU meter, how long kernel of the FIR filter has to be otherwise), is great opportunity to create “weighting” A, B, C or D curve for audio noise measurements. (:TO DO).

 Link to Download Arduino sketch:  Audio_VU_Meter_Mono_69dB