Autoswitch between three dynamic microphones for instrument

Hi all,
I am working on this interesting project which is probably not new, the idea is to monitor and autoswitch between three identical dynamic vocal microphones "Shure BETA 58A" which are mounted on or near the musical instrument. Arduino would monitor each microphone volume trought analog inputs and the mic which has the highest volume will be transmitting signal via UHF band transmitter to amplifier with speakers. The mic would be selected by transistor operating as a switch.

For now I am monitoring amplified signal from microphone with Arduino Nano analog input and the sound coming from pc speaker, it seems to be working but not as I was expected. The higher the volume the more "disorted" like signal it gets and when silence there is almost flat line, which is normal I think, but from that signal it is hard for me to filter out which mic has the highest volume. The best solution would be like a linear analog input, high volume, high voltage. For any helpful advice or tips I would be much appreciated.

Everything is connected as in attached image drawing and with two 100k resistors as voltage divider for analog input to arduino. I will draw new schematic and upload later. The code for now is only example analog input. Many thanks

20190827_194328.jpg

BETA58A.png

The higher the volume the more "disorted" like signal it gets

It shouldn't be distorted, but you are sampling a waveform (probably at an unknown sample rate). It's an audio waveform that's positive half the time and negative half the time, and it crosses-through zero twice per cycle.

That's before you add the bias. Typically, you'd subtract-out the bias in software but that depends on what you want to do.

The "raw data" will "look random", even with a pure tone. But, if you sample fast-enough and "connect the dots" with a DAC you get-back the original-continuous analog waveform.

The Audacity website has a [u]little tutorial[/u] about how digital audio works.

and when silence there is almost flat line, which is normal I think

Correct. Silence will read the flat-line bias (about 512). Except you will pick-up some acoustic noise and some electrical noise from the amplifier.

"Quiet sounds" should jump around "randomly" near 512 and "loud sounds" should jump around "randomly" between about zero and 1023, depending on the loudness of the sound, the sensitivity of the mic, distance from the mic, and the gain of the amplifier, etc. Of course, its not truly-random but the readings are uncorrelated to the sample rate so they "look random" unless you reconstruct the analog waveform.

**There a few ways to get "loudness".**The easiest way is to read in a "fast loop" for about 25 milliseconds, finding and saving the peak. (That's enough time to read a low-frequency half-cycle.)

Or again reading in a fast-loop, you can find the average (or moving average) of the positive half-cycles, or the average of the absolute values, or you can calculate RMS. (The true-average is zero, since it's positive half the time and negative half the time.)

BTW - The LM386 is intended to a power amplifier (for driving a speaker). It's not intended to be a microphone preamp. It may work, but it may not have enough gain (depending on the loudness of the sound) and it may be excessively noisy (especially if you are trying to detect quiet sounds).

Also, if you are running the LM386 from 5V the output from the chip should be biased at 2.5V (check with a multimeter). That means you can leave out the blocking DC-blocking capacitor (C4) and get rid of the 100k bias resistors.

Hi doug, I read the tutorial and I understand better about digital audio. I tried your tips and so far so good. I have measured the output from amp and it is already bias as you said, so C4 and bias resistor removed.

I used LM386N beacuse it seems to be popular on such circuits, also read there are also LM358 or TL072 in common use. I tried with LM386N-3 which has 500mW of power, but it seems little improvement of signal. Which one should be preferable for dynamic microphones as this one?

About detecting volume or loudness I have a code for sampling analog input and get the average or peak to peak. The average seems to be better working since it is a value between 480-880, and with peak to peak calculation and if I use 512 as zero offset all is good until value goes slightly below 512, then result is negative and since I used unsigned long, final result is 10 digit. Below are current results. Thanks

const int analogInPin0 = A0;  // Analog input pin that the mic amp out is attached to
int sensorValue0 = 0;        // value read from mic amp out
const int sampleWindow = 300; // Sample window width in mS (50 mS = 20Hz) 
unsigned int sample;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  Serial.println(F("Ver: MIC_v11d_PEAK"));  /* For debug use */

}

void loop() {
  unsigned long startMillis = millis(); // Start of sample window
  unsigned long samplesTaken = 0;
  unsigned long addValue = 0;
  unsigned long maxValue = 0;
  unsigned long avgValue = 0;
  unsigned long ppValue = 0;

  // collect data for 25 mS
  // lower sample time, more accurate signal
  // higher sample time, more flat line signal
  while (millis() - startMillis < sampleWindow)
  {
    // read analog input
    sensorValue0 = analogRead(analogInPin0);
    
    // calculate samples taken and all analog readings for average
    samplesTaken++;
    addValue = addValue + sensorValue0;

    // saving the highest peak value
    if (maxValue < sensorValue0)
    {
      maxValue = sensorValue0;
    }


  } // END MILIS
  avgValue = addValue / samplesTaken;
  ppValue = 2 * (avgValue - 512);

  Serial.println(maxValue); // print max value

} // END LOOP

Testing with online sound generator:

440Hz sample 300ms

5400Hz sample 300ms

If you feed the biased audio through a filter (different caps between signal and ground) you should get an approximate "level" out.

Smoke, yes you are right, but there seems to be little improvement, I will test with lower value capacitor. I only have 0.1 and 10nF and it gets worse when one of them is connected, does not filter well.

So first step seems to be promising, but I am curious about next step which is toggle on/off or passing amplified signal to the UHF transmitter between three microphones. Will transistor as a switch work or do I need some special chip? I will post full circuit diagram when I finish it.

Edit: The transistor as switch seems to be working, on scope the vaweform is identical after and before transistor. Is this circuit reliable?

Can you tell any difference with loud and quiet sounds? If not, there could be something wrong in your setup/wiring or maybe you need more gain.

About detecting volume or loudness I have a code for sampling analog input and get the average or peak to peak. The average seems to be better working since it is a value between 480-880,

Are you getting anything "useful" for maxValue? That's your "peak" and it should change with loudness.

The long-term true-average should be 512 (or whatever your bias actually reads) so that's pretty useless.

It's easier to use signed values and subtract 512 (or whatever your bias actually reads) from every reading before you do anything else.

Then, you can throw-away/ignore all of the negative values and take an average of the positive values. Or, take the average of the [u]absolute values[/u] (make everything positive before averaging).

I don't understand what you're trying to do with peak-to-peak. The peak-to-peak includes the negative & positive peaks. Or if you don't remove the bias, the "negative" becomes a minimum, but you're not saving either value. With "normal audio" peak-to-to peak should be double the peak so you shouldn't need it.

If you feed the biased audio through a filter (different caps between signal and ground) you should get an approximate "level" out.[/quote]No... We don't want to filter-out the audio signal! Plus, that's a lousy way to make an audio filter and it could damage the amplifier!

Yes the difference is seen clearly, when I volume up music or even clap hands. The maxValue goes from 511 to 880 at max volume.

True average is around 511-514 but that also changes sometimes from 507-512.
With peak to peak "ppValue" i wanted to calculate peak to peak from average readings but first divide by 512 then multiply by 2, but the problem was if when silence the average was below 512, then long int was at max value. I will experiment more with signed integers and absolute values.

Isn't C5 and R3 acting like filter?

Isn't C5 and R3 acting like filter?

Yes, but it doesn't filter the audio. With an [u]RC filter[/u] the "output" is connected in-between the resistor & capacitor.

I think it's to prevent oscillation of the amplifier (at radio-frequencies) but scanning the datasheet I didn't see an explanation.

The resistor keeps it "safe". Without the resistor you could get excess current depending on the frequency and capacitor value.

Yes the difference is seen clearly, when I volume up music or even clap hands. The maxValue goes from 511 to 880 at max volume.

I think you're on your way to success!

Hand claps are tricky because they are short duration. The basic loop runs rather slow (for audio) so you might not "catch" the loudest part of the clap. It will be even slower if you read 3 microphones. That shouldn't be a problem with "normal sound".

Also, a short-duration clap won't "contribute" much to the average. You may have to experiment to see if the peaks or the (modified) average works better for your application.

turbozob:
True average is around 511-514 but that also changes sometimes from 507-512.

A 2.5V bias should make no sound = 511. Maybe you have less?

With peak to peak "ppValue" i wanted to calculate peak to peak from average readings but first divide by 512 then multiply by 2, but the problem was if when silence the average was below 512, then long int was at max value. I will experiment more with signed integers and absolute values.

With integers you don't want to divide then multiply as that greatens roundoff error. Anyway /512 then *2... better to /256.

Analog read gives 1023 max while an int can be -32768 to +32767, you don't need 32 bit variables to do the math unless you want to work to extra places before the divide like value * 1000 / 256 gives 3 extra places where

511 millivolts * 1000 / 256 = 1996 microvolts
511 millivolts / 256 = 1 millivolt with .996 rounded off

1996 uV + 500 uV round-up = 2496 uV
2496 uV / 1000 = 2 mV rather than the 1 mV that 511/256 gets.

Integers can give more accurate results but you gotta work with them, use units 2 or 3 magnitudes smaller than your results need to be and you won't end up being off in significant digits at all. I had to learn this back in the 80's doing billing and payroll code that HAD to be right to the penny or people would freak badly. Yes it can be done, with floats as well only with messier and slower code.

Isn't C5 and R3 acting like filter?

Different frequencies need different filters. A low-pass filter followed by a high pass filter that overlap might do but I am sure that a EE will tell that is just too simple. I go off old transformer/linear power supply lessons from way back.

Just thinking, with a full wave rectifier made of Schottky diodes you don't need to bias at all.

Why don't you just use a simple Vu Meter circuit of one diode and one capacitor? This would give you an analog voltage directly related to the loudness of the audio. If you want a slower response to minimize hand clapping interference, just increase the size of the capacitor.

Vu Meter.jpg

Vu Meter.jpg

Years ago I was looking at the slow response of LDRs as a way to average much faster PWM. It might work for audio.

I have used your advice and changed the code to use signed and abs values, then subtract the values with bias "512" to get the true value and the results are more accurate. I don't mind subtracting bias because I would like to have circuit board as small as possible.
I have also tested the output control with transistor of the signal and it works, tested with the scope. Handclaps and similar can be only detected by increased sample window "300ms"

Stevemann, that is good idea, but I need to monitor pre amplified signal from microphone which is on instrument, not from speaker.

GoForSmoke, I dont understand your last post about LDRs, but will search about it.

LDR has a slow response to change, can never make a steep wave output. A led blinking at high frequency should get flattened out to a low ripple.

It seems that transisotr as a analog switch does not work as expected. When turned on the output voltage increases like it is also acting as a amplifier. I read about analog switched like MAX313 and ADG511 but am not sure what which one to use.

The project has made a good progress, but the last problem I have is with DG412DJ analog switch.

There is a little pop-click noise heared on speakers when is switching and is also seen on scope. I tried everything to suppress it with capacitors and resistors, also used another analog switch to close-loop of amplifier before changing source of input, but again without success. Whenever the amp signal is released over analog switch the noise is there.

I read somewhere that optoisolator with MOSFET is a good choice for analog switching as Fairchild H11F1M
If anyone has more experiance and feedback what is the best for audio switching I would be much appreciated.

Does anyone know why there is audible click pop noise to amplifier whenever I turn on LED or opto element? I tought that switching analog signal was making this noise, but now I see that whenever output is high or turning LED on the pop sound is there, it is also seen on the scope at amplifier output

First and foremost a Beta 58 is a dynamic supercardioid microphone it does not need or tolerate any external power. I will admit it is one of the best vocal mic you can purchase. Any DC applied to it will cause distortion and possibly burn it out. Your Beta58A drawing shows that it is transformer coupled. You will need a Differential front end to amplify the microphones output, not single ended as in your drawing. You will need about 24 bit analog converter to pick up the quality of the microphone and convert it to digital where you will have to do processing. Multiply the A/D bits times the conversion rate required times 3. For 44Khz 24 Bits 3 channels you need to process 3,168,000 bits per second or 395000 bytes a second. A sigma delta converter may work better for you. Try this link: https://www.ti.com/europe/downloads/Choose%20the%20right%20data%20converter%20for%20your%20application.pdf

Take a look at this link: https://www.rane.com/note137.html it will give you some background information. The simplest solution I can see at this point is to get a mixer that you can gate the outputs. These will have the ability to direct each channel to an effects processor (FX). Connect that to a AC/DC conversion circuit via a 600 Ohm isolation transformer. You can then read the output of the conversion circuit with the arduino A/D inputs. Then do some software to determine which is to be turned on and control the gates accordingly. You can use a inexpensive condenser microphones placed close to the Shure and use them for level measurement only,
Good Luck & Have Fun!
Gil

Thanks for the info, the op amp circuit does is updated and does not have power to microphone and also uses TL074 op amp, but still my question was why when turning on/off led or opto I can hear click pop noise on op amp output? This happens even in op amp circuit with power led only.