Arduino Forum

Using Arduino => Audio => Topic started by: tamadneko on Jun 29, 2020, 02:07 am

Title: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jun 29, 2020, 02:07 am
Hi guysss. I'm a noob and new here with lil knowledge on electronics and Arduino. I'm willing to search and learn if it's something I don't know and will help me. I'm working on a proposal project about digital stethoscope. And one of the problem is the ambient sound. There are 2 methods I found how to remove the ambient sound: 1) By using Band-Pass Filter and it's software algorithm (if working). 2) Is by using Adaptive Active Noise Cancelling (ANC) System. I decided to use ANC because it's much more effective in respiratory sound analysis than using Band-Pass Filter. I'll be not having an output sound, the sound recorded by the microphone will be analyzed by the microcontroller

The question is on how to implement an ANC System, what I know is it both involves hardware (error mic, source mic, ANC controller, etc) and software (code/algorithm). Though there might be possibility that I misunderstood concepts. I'm planning of implementing a Hybrid Active Noise Cancellation. Also, I will be using electret microphones with breakout board (MAX4466) which has op amp if I'm not mistaken. For the circuit board-microcontroller. I'm thinking of using maybe Arduino Due or Teensy 4.0. I don't know on how to do it and implement it. I don't also know where to start.

I've already search and found various forums in arduino which says it's not possible. But I've found codes for LMS and FXLMS Noise Cancellation Algorithm and that leads me in asking here.


Here's the link for the code I've found for LMS:
Arduino - https://github.com/wespo/LMS
Teensy - https://github.com/zftan0709/Feedback-ANC-Teensy-3.6
           - https://github.com/DD4WH/Teensy-ConvolutionSDR/blob/master/Teensy_Convolution_SDR.ino
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: DVDdoug on Jun 29, 2020, 08:18 pm
I'm not an expert in noise reduction but you will need something like the Teensy or Due.  The regular 8-bit Arduino isn't powerful enough for high-quality real-time audio.

Quote
. Also, I will be using electret microphones with breakout board (MAX4466) which has op amp if I'm not mistaken
Yes.   A board like that has "everything" you need - It supplies power to the electret mic element, it has a preamp, and it has a biased output (requried because the Arduino can't directly read the negative-half of the AC audio signal).

But, I'm not sure if you'll have enough gain.   You can try it with the Analog Read Serial Example to see what kind of readings you're getting.  (I'm assuming  Analog Read Serial works on the Teensy or Due.)  Take-out the delay, and note that readings will "look random" because you are sampling a waveform.    But, you should be able to get an idea of the peak readings.

Quote
I'm working on a proposal project about digital stethoscope
I'm not sure why noise reduction is necessary.  A regular acoustic stethoscope doesn't have noise reduction.

In general, open-ended noise reduction works best when you have a constant low-level background noise...  When you don't really  need it.  If the noise is bad you can get artifacts (side effects) and "the cure can be worse than the disease."  You wouldn't want to filter-out or mask any anomalies.

Regular high-pass, low-pass, or notch filtering can work if the noise has an identifiable frequency.   This can work especially well if the noise is outside of the signal-frequency range.   For example, a low-pass filter can remove 50/60 Hz power line noise from a voice recording without affecting the voice.  

Sometimes the human brain is the best "filter".  For example, if you are listening to a recorded conversation from a noisy envrionment, just listening carefully (multiple times) often works better than any kind of processing/filtering.  

...I'd recommend testing-out your filtering algorithms on a computer before building any custom hardware.

Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jun 30, 2020, 04:48 am
Thanks for replying.

Quote
I'm not sure why noise reduction is necessary.  A regular acoustic stethoscope doesn't have noise reduction.
I'm planning on analyzing the frequency and wave frequency of the lung sounds, ambient/background noise may affect the results. Also I'm planning on implementing an AI and give it lung sounds dataset.

Quote
Regular high-pass, low-pass, or notch filtering can work if the noise has an identifiable frequency.   This can work especially well if the noise is outside of the signal-frequency range.   For example, a low-pass filter can remove 50/60 Hz power line noise from a voice recording without affecting the voice. 
So with Band-Pass filter, can I remove the ambient sound and heart sounds?


Lastly, I don't know if I misunderstood concepts, but do I need to implement Noise Reduction so that the data can be analyzed by the AI?


Here's the link for:
Lung sound dataset: https://www.kaggle.com/vbookshelf/respiratory-sound-database
Smart Stethoscope: https://engineering.jhu.edu/ece/2019/02/01/a-smart-stethoscope-puts-ai-in-medics-ears/
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: Grumpy_Mike on Jun 30, 2020, 09:47 am
Quote
So with Band-Pass filter, can I remove the ambient sound and heart sounds?
The band pass filter attenuates (not removes) frequencies outside the filter's parameters, that is the band width of the filter. So you can improve the signal to noise ratio of the wanted frequencies. The amount by which frequencies outside the band width are reduced depends on how far they are away from the edge and what is known as the "order" of the filter. I would suggest you look for at least a 6th order filter here.

Note if the background noise is in the same frequency range as your wanted signal this will do no good at all.

Quote
but do I need to implement Noise Reduction so that the data can be analyzed by the AI?
No, but if you don't then that noise will become part of what the system is looking for which might be a problem. If you do implement noise reduction then again that becomes part of the data set for training and the same algorithm must be used in any subsequent measurements.

If you are not using your data to train an AI system but a standard data base then implementing a filter or noise canceling algorithm is going to produce better results than not doing anything.

I am assuming you have an oscilloscope, it would be fruitless to attempt a project of this nature without one.
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jun 30, 2020, 12:18 pm
Thank you for replyiing


Do I need to have my own circuit or can I just run a code to circuit board-microcontroller (Teensy/Arduino Due) ?

Quote
I would suggest you look for at least a 6th order filter here
Pertaining to my question, I found a band-pass filter arduino code. If it's possible do I have to implement a circuit or no? Also again, if it's possible, how do I set the code to 6th order filter?

Here's the link for the Band-Pass Filter Code:
https://www.norwegiancreations.com/2016/03/arduino-tutorial-simple-high-pass-band-pass-and-band-stop-filtering/

Quote
Note if the background noise is in the same frequency range as your wanted signal this will do no good at all.
I don't think that lung sound would be the in the same frequency range as the ambient sound, the heart sound might pose a problem when it comes to it.

Quote
If you are not using your data to train an AI system but a standard data base then implementing a filter or noise canceling algorithm is going to produce better results than not doing anything.
I have a link from the earlier reply, does it count as a standard database?

Quote
https://www.kaggle.com/vbookshelf/respiratory-sound-database
Quote
I am assuming you have an oscilloscope, it would be fruitless to attempt a project of this nature without one.
Why do I need an oscilloscope? Can I just run an FFT algorithm to see the frequency wave?

Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: pjrc on Jun 30, 2020, 01:43 pm
I am assuming you have an oscilloscope, it would be fruitless to attempt a project of this nature without one.
Why is an oscilloscope needed?

Many known-good shields and breakout boards exist for connecting microphones.  Most of them have all the analog circuitry on those boards, or even build into the microphone chip, with only digital I2S communication between those mic boards and the microcontroller.  If using such a breakboard board or shield which already has all the analog circuitry done and delivers digital data, I can't understand why a 'scope would be used at all.

Even for developing custom analog circuitry dealing with low voltage, often an oscilloscope isn't very useful.  Most oscilloscopes have a noise floor in the range of 1 to 10 mV.  They also have earth grounded probes.  Especially when working with analog circuits connected to USB-powered boards, where the USB connects to an earth grounded computer, connecting the probes tends to form analog ground loops.  These are tough problems even for experts.

Sure, you can see the signal after its been amplified by a gain of 100.  But if you're struggling to figure out why the amplifier or low-level signal part isn't working, a known-good audio amplifier with relatively high impedance input and good quality headphones are going to be much more useful.

But my general advice for this project would be to avoid messing with the microphone circuitry.  Or at least don't jump into the analog circuitry as your first part of the project.  Buy a shield or breakout board with a known-good microphone.  A board which delivers the audio as I2S digital data will allow you to avoid messing with sensitive analog signals.  This project already is a huge challenge in terms of data processing.  Don't make it even more work by messing with analog circuit design.

If you need to miniaturize the whole project into that stethoscope, make that the very *last* step.  Get as much as possible working the easiest way you can, with large known-good shields or breakout boards, before you dive into shrinking the size or designing sensitive analog circuitry.
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jun 30, 2020, 02:11 pm
Thanks for replying
Quote
Get as much as possible working the easiest way you can, with large known-good shields or breakout boards, before you dive into shrinking the size or designing sensitive analog circuitry.
Thanks for the advice. I'm planning on using Electret Microphone Amplifier MAX4466 with Adjustable Gain. It has a breakout board.

Quote
If using such a breakout board or shield which already has all the analog circuitry done and delivers digital data, I can't understand why a 'scope would be used at all.
So if I use an electret microphone with breakout board, I don't need to use an oscilloscope?

Here's the link for the electret microphone with breakout board:
https://circuit.rocks/electret-microphone-amplifier-max4466-with-adjustable-gain.html
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: pjrc on Jun 30, 2020, 03:57 pm
If your project does not work on the first try, which is very likely (even experts rarely have projects work on the very first try), nobody can say with 100% certainty exactly what tools & equipment you will need to diagnose and solve whatever unknown problems are preventing your project from working.

But using a breakout board with a known-good mic amplifier circuit greatly reduces the chances you will need to use an oscilloscope to view the signal.

If you use a board and library with I2S support, you might consider a microphone with all-digital I2S output.  Usually digital signals are more resilient to noise than analog signals.  But do pay attention to the library you use to receive the I2S data stream the mic transmits.
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jun 30, 2020, 05:17 pm
Quote
If you use a board and library with I2S support, you might consider a microphone with all-digital I2S output.
I was planning on using Adafruit MAX4466 Electret Mic Amplifier, however it doesn't support I2S. Should I switch to MEMS microphone which supports I2S?
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: MarkT on Jun 30, 2020, 10:56 pm
The ideal tool is a dynamic signal analyzer (aka FFT analyzer) or audio analyzer, thought most 'scopes of
modern type have a basic FFT facility (some very basic alas).  Expensive though, even second-hand.

Without these tools you only have your ears to rely on, but they are pretty good signal analyzers with
some very high end software running on them!  Not very accurate though, and don't hold calibration well :)
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: Grumpy_Mike on Jun 30, 2020, 11:52 pm
Quote
Why is an oscilloscope needed?
Because
Quote
Sure, you can see the signal
Quote
The ideal tool is a dynamic signal analyzer (aka FFT analyzer) or audio analyzer,
Yes that indeed is ideal but these things normally also have a scope mode.

The OP is proposing to do a complex project with little or no knowledge of the subject. He doesn't even know what a 6th order filter is. He is expecting to put together pre written libraries and get something to not only work but work well.

I used to tell my students that an oscilloscope was your eyes. Without one, or a better tool you are literally "pissing in the dark".

A typical example of a way too ambitious project for a beginner. And a blindfold beginner at that.   

Quote
Can I just run an FFT algorithm to see the frequency wave?
Many beginner here struggle to know what the numbers mean in an FFT dump of the bins, let alone when they go wrong and how good they are.
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: tamadneko on Jul 01, 2020, 01:59 am
Thank you guys for replyying.

It looks like this project is too complex for me.

If have any advice or any points of concern I should learn before I can do this project, do tell them. I want to make this project even if it'll take time.
Title: Re: Active Noise Cancellation System - LMS Algorithm
Post by: pjrc on Jul 02, 2020, 01:59 am
There are good libraries for I2S digital audio.  At least for getting a mic signal into a microcontroller as digital audio samples, an easy path does exist to just connect the mic I2S digital signals to the correct pins on a board which supports I2S audio input.  An oscilloscope isn't needed.  The mic outputs digital data on 3 pins.  You just connect 2 wires for power and 3 wires for data.  As long as you can connect 5 wires to the right pins, it's easy (if you choose a digital-only output mic and you choose a board with good library support for digital I2S audio).

Libraries do exist to detect specific tones, detect fundamental tone in a presence of strong harmonics, and to perform FFT.

But today, at least as far as I know, there aren't any really good and easy to use libraries for robust AI sound recognition.  I hope to change that within the next year.

With the incredibly powerful hardware that's available today, there's really no reason this stuff needs to be so hard for beginners.