Using Arduino to Digitaly Filter Audio.

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.

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 (Digital filter - Wikipedia) 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.

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.

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.

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

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.

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

None that I can publish :slight_smile: 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:

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 2pik/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

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.

Well, you can buy devices like the MAX275:

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 :wink:

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

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

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

Here is a choice of switched capacitive filters:-

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.

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.

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.

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.

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:-

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.

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.

Yes understood. The problem is that the human brain is so good at doing those sorts of things you think it will be easy getting a computer to do it but it is not.
If you do a google search for "pattern recognition sound" you will see all the work and complexity that it involves.

Ok, so I may have bitten off more than I can chew :frowning:

Is there no filter chip that can be controlled digitally, eg by clock frequency or voltage? any sort of commercialy available chip?

I spent the last few days spending all day serching the net. I thaught Switched Capacitor filters were my answer?

Cheers Mike.

You need an 32bit DSP to do it, if you only want to pass a band of frequencies, you can use a band-pass filter made with op-amps or switched caps filters.

I understnad that. And actualy planned to use op amps originaly instead of RC filters, along with pots to adjust the cuttoff frequeuncys but wasnt sure if that was possible.

Cheers, Phil.

Is there no filter chip that can be controlled digitally,

Your on the right track with switched capacitive filters but it is the rest of the project that is a killer.