Pages: [1] 2   Go Down
Author Topic: Using Arduino to Digitaly Filter Audio.  (Read 2929 times)
0 Members and 1 Guest are viewing this topic.
Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All.

Let me explane what I am trying to achive and what I problems I have hit.

I am trying to make a device that will allow me to plug a mic into, and a pot that will allow me to sweep through the ENTIRE audio frequency range at a bandwidth of 500hz.

Here is an ilistration of what I meen:



My first attempt was to do it all analog. Using a simple RC Filter set up as a bandpass and using pots. However the accuracy of the components meant that I couldnt have enough control over the values and I found the bandwidth would fluctuate.

So Im now attempting to do it digitaly. I have managed to input audio from a mic that passes through a preamp. I had to directly adjust regestry values to allow a fast enough frequency for the ADC and the PWM. The output is fitered to remove the fast PWM carrier frequency.

A lot of reading about FFT has helped understand it. Ive looked at demos of spectrum analysers and had the idea that: With spectrum analysers you have many bins of diferent groups of frequencys and you output the amplitude of each bin, well how about having 3 bins, 2 bins get discarded (the two bins below and above the accepted 500Hz bandwidth) and the 3rd bin is what we want and output the contents of that bin. Can I then just adjust the values of the bin's boundries.

Does this sound feasable?

Thanks, Phil.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you say output the contents of that bin, do you mean audio output? Because you would need an IFFT (Inverse FFT) to convert back from freq to time in this case.

Did you consider just regular digital filtering (http://en.wikipedia.org/wiki/Digital_filter) I have tried low-pass FIR on an Arduino and it seems to work ok. You have to adjust the coefficients of the band-pass filter based on where you want it to filter.
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the very quick reply, I assumed the fft bin would contain a value of the voltage at that instance, then outputing the value would be the same as what I am doing now?

Ive not looked into digital filters at all, is it possible to set the bandwidth and have it sweep through the range with digital filtes of the shelf?

Thanks.
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can filter digitally in software. The Goertzel algorithm might be a good application for what you are trying to do. It essentially computes the magnitude of only 1 FFT bin, and you control which bin with a single parameter.

http://en.wikipedia.org/wiki/Goertzel_algorithm

--
Need a custom shield? Let us design and build one for you.
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds more suited to my needs. Do you know of any good examples of using this algorithm? Or anymore information on it as the link you provided seems to mathimaticaly intense to digest atm.

Also is it possible to use that on an arduino as the device I intend to make must be stand alone.

Thanks, Phil.
« Last Edit: September 12, 2010, 11:20:46 am by philwalker » Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That sounds more suited to my needs. Do you know of any good examples of using this algorithm?

None that I can publish smiley  You will probably find some good code examples if you look for DTMF (touch-tone telephone) decoding as that's a common way to decode which buttons are pressed.

It is quite possible to use an Arduino, though you will need to do floating-point math (or be VERY good at implementing fixed-point algorithms). Basically, every time you read an A/D value from your audio you will run equations of the type:

Code:
y1 = inputvalue - 2*cos(theta)*y2 + y3;
y2 = y1;
y3 = y2;

So because of the floating point math and multiplication you cannot read new input values too quickly or the algorithm can't keep up, though 8 kHz should be doable (125us between samples).

The value theta is 2*pi*k/N where N is the number of samples you're going to read before making a decision as how to energetic the signal is, and k is an integer from 0 to N-1 indicating which "bin" of frequency you're interested in.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, light sensor, potentiometers, pushbuttons
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I fear this maths may be slightly to over my head and out performing my A level maths lol.

Do you, personaly, think it is best to use an arduino or can you buy specially designed digital variable filters?

Cheers, Phil.
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, you can buy devices like the MAX275:

http://www.maxim-ic.com/datasheet/index.mvp/id/1452

But these are "programmable" with resistors, so you'd have to fake it out with digital pots or such. And if your A-levels aren't up to understanding trig then reading the MAX275 datasheet won't be that easy either  smiley-wink

Perhaps someone can suggest an all-in-one solution.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anyone know any good informtaion about Switched Capacitor Filters? This seems the best choice, im just strugeling to find a good example. Cheers.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31355
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a choice of switched capacitive filters:-
http://uk.farnell.com/jsp/search/browse.jsp?N=500006+1004642&Ntk=gensearch_001&Ntt=switched+capacitave+filter&Ntx=mode+matchallpartial

In general an arduino is not the best machine for implementing digital filter algorithms because of lack of floating point support. You are better going for one of the TI DSP chips.
However, if your maths are only A level then you are going to struggle big time. I did teach DSP to an MSc class years ago and they struggled with the maths.
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rats. Im really keen to use a switched capacitor filter, but cant find any good examples, or guides to help me.

My maths is good A level, but that is all, Sadly.

Cheers, Phil.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31355
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but cant find any good examples,
Have you downloaded the data sheets attached to the chips in the last link?
These will have recommended schematics in them which will be enough to get you started.
As you haven't mentioned what your application is, it is hard to recommend anything more specific. For example in the graph you showed a brick wall response, in practice this is not going to happen and you will get a slope. You also showed an unfeasibly large attenuation of unwanted signals.
« Last Edit: September 12, 2010, 04:52:43 pm by Grumpy_Mike » Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ye I downloaded the datasheet, im currently reading over it.

Ok here is my situation:

I need to build a device that plugs into a cars knock sensor to be able to listen for knock whilst mapping cars.

The knock is in the audioable range and sounds like a pinging or static hissing noise.

The knock sensor is a pezio sensor and has a peak output of around 30mV.

I need to be able to filter out all of the background noise bar the frequency of the knock.

Thanks, Phil.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31355
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK that is a whole lot more complicated that the original question. You have two problems:-
1) Remove as much background noise as possible
2) Identify the noise when it comes.
but:-
Quote
and sounds like a pinging or static hissing noise.
Pinging and static hiss noises are wide bandwidth noises, therefore you need a wide bandwidth filter. That is bound to add in a lot of background noise.
Next you have the problem of the pattern recognition of your noise, this is not at all easy and will be computationally heavy. Coupled that with the filtering you want to do and I don't think the arduino is the processor for this project.

I would proceed by getting a recording of your noise on some form of digital media. Then look at the waveform on an oscilloscope or do some analysis / graphs on the numbers. Try and spot the difference between the background noise and the sound. Only when you can spot it in the waveform will you be able to detect it in a program. However, you will need at least a knowledge of Fourier Transforms which the last time I looked is way beyond A level.
Logged

Wales, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A appriciate your help.

Can I just clarify that I dont want to filter out everything but the pinging, I just want to be able to select that area of sound, even if it still contains noise (eg i might still hear alternator wine, but wouldnt here the injectors) etc.

I would just like to here to the region that contains the pinging, which can very from car to car, hence it having to be adjustable.

Cheers, Phil.
Logged

Pages: [1] 2   Go Up
Jump to: