Help with oscilloscope and multimeter readings for guitar signal

MrChips

Joined Oct 2, 2009
35,307
Shucks, I did that already a long time ago. I had a display in a showcase. Visitors could come up to the display, talk, hum, whistle, sing a song, etc, and it showed the frequency and note detected. I was written in MATLAB.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
You need a rail-to-rail op-amp, like @MrChips says, and you need to run it from the same power supply as the micro. That way it can get to the maximum input voltage possible for the A/D without exceeding the inputs. My favourite op-amps for that situation are Microchip's MCP6061, MCP6071, MCP6021 etc.
Bias the input with two equal value resistors to keep it as near the centre as possible
I'll have to look into those chips.
ESP32 can be powered either 3.3 or 5v. But ADC limit is 3.1v.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
Shucks, I did that already a long time ago. I had a display in a showcase. Visitors could come up to the display, talk, hum, whistle, sing a song, etc, and it showed the frequency and note detected. I was written in MATLAB.
Interesting. Got any videos? What algorithm did you use and how accurate was it?
 

MrChips

Joined Oct 2, 2009
35,307
I just did an FFT (Fast Fourier Transform).
Sampling theory says that the resolution is the inverse of the sampling period.
Hence, if you want 1 Hz resolution, you need to sample for 1 second. To get 0.5 Hz resolution, you need to sample for 2 seconds.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
ESP32's ADC is famously rubbish.
yeah. Most if not all of the hobbyist microcontrollers (Arduino, ESP32, Seeed, Teensy, Lilygo, etc) have less than stellar ADC's. But for our application, we don't need accurate voltage readings. Just accurate time.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
I just did an FFT (Fast Fourier Transform).
Sampling theory says that the resolution is the inverse of the sampling period.
Hence, if you want 1 Hz resolution, you need to sample for 1 second. To get 0.5 Hz resolution, you need to sample for 2 seconds.
That is for FFT, yes. 1 Hz resolution is pretty poor at lower frequencies. And FFT is notoriously processor intensive - no one uses FFT for this type of application. Autocorrelation and zero crossing algorithms are much better, and faster. But, back in the day, FFT was IT.

As a reference. 1 cent on a low E for guitar is 0.024 Hz (1/2 that for bass). All commercially available guitar tuners can do +/-1 cent, and many do +/1 0.1 cents.
 
Last edited:
The LM358 is hopeless for audio and nowhere near rail to rail, especially at 5V supply voltage. Why are R1 and R2 different values? Surely you want the peak to peak to swing equally between the 2.5V midpoint? Maybe power with 12V and attenuate the output with a resistive potential divider?
Further to my post #14 (with suggestions subsequently repeated by others), given your application is just to determine frequency, the LM358 is probably okay but I would certainly make R1 and R2 the same value and use the available 9V to power the circuit followed by a resistive potential divider on the output to drop the possible 9V to 3V. Not being rail to rail, you don't need to drop quite so much. By making the gain higher you will cap the maximum and minimum voltage output to near the rails to look more like a square wave. Maybe use a potentiometer to vary the gain to accomodate different input values.

Personally, I doubt that the poor linearity of the ESP32 A/D really matters. I'm actually wondering if you could simply use digitalRead(); instead of analogRead(); as it's much faster - I believe less than 0.8V is guaranteed low and above 2.5V is guaranteed high. Maybe adjust either R1 or R2, or the resitive voltage divider so that LOW and HIGH values occur equally often. I believe this would be a good starting point from which to try alternative algorithms. As already mentioned, FFT will take too long to provide a good frequency resolution and you'd need a lot of memory!
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
Further to my post #14 (with suggestions subsequently repeated by others), given your application is just to determine frequency, the LM358 is probably okay but I would certainly make R1 and R2 the same value and use the available 9V to power the circuit followed by a resistive potential divider on the output to drop the possible 9V to 3V. Not being rail to rail, you don't need to drop quite so much. By making the gain higher you will cap the maximum and minimum voltage output to near the rails to look more like a square wave. Maybe use a potentiometer to vary the gain to accomodate different input values.

Personally, I doubt that the poor linearity of the ESP32 A/D really matters. I'm actually wondering if you could simply use digitalRead(); instead of analogRead(); as it's much faster - I believe less than 0.8V is guaranteed low and above 2.5V is guaranteed high. Maybe adjust either R1 or R2, or the resitive voltage divider so that LOW and HIGH values occur equally often. I believe this would be a good starting point from which to try alternative algorithms. As already mentioned, FFT will take too long to provide a good frequency resolution and you'd need a lot of memory!
So by 9v, I mean off the shelf 9v (Boss style center negative) power supplies used by musicians. But they aren't actually 9v, they are anywhere from 9.2 - 9.6v. So I really need to use a voltage regulator to accurately put the signal in the middle of the ADC 0-3.1v range. That's why I chose the 7805 so I could start with 5.0v.

I guess I don't understand. You want R1 and R2 to be the same, but then use a "resistive potential divider" on the output... that's what I'm doing to get the signal into the ADC range I thought. The 100k and 220k voltage divider put the signal right in the middle of the ADC at 1.55v. Maybe you want the LM358 to be powered straight off of 9v instead of 5v?

There's something else at play here. Various guitars have a wide range of pickup output. Here's a chart I made of all the guitars I have access to using a Tek 2213 Oscope:
1724420855779.png

That's a big range. But assuming the weakest pickup is 100mv, then 30x gain gives me the max input for the ADC. I was taking advantage of the LM358 common mode voltage drop of 2v below Vcc as a natural voltage protection for the ADC. If the LM358 is at 5v then the max output is 3v, which is the max input of the ADC. If I power the LM358 with 9v, it could output up to 7v and then I'd have to protect the ADC some other way, like maybe a 3v zener? But I'm here to learn so I'm open to better ways of doing this.
1724421042499.png

As it is, here's a video I made of the LM358 clipping on the Breedlove after sending it through 50x gain. It never gets above 3v, which is good for the ADC. But maybe using a clipping diode is better?
https://www.youtube.com/shorts/kTe-ALyEs5c?feature=share

Your suggestion of using digitalRead(); instead of analogRead() is SUPER interesting. I will look into this!
 

MrChips

Joined Oct 2, 2009
35,307
I think you're splitting hairs here.

If all you want to do is analyse zero crossings, then use a narrow band-pass filter and AC couple the signal to an analog comparator (or digital GPIO pin). You don't need an ADC for this.
 

Ian0

Joined Aug 7, 2020
13,317
One thing that is worth trying is to use a 74HCU04 as and amplifier. (Also available as a 74HC1GU04).
See this application note.
Its maximum gain is about 50, and its linearity is rather horrible as the output signal approaches supply rails, but it never really clips, rather it compresses, making the output signal vary rather less in amplitude than the input signal.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
One thing that is worth trying is to use a 74HCU04 as and amplifier. (Also available as a 74HC1GU04).
Its maximum gain is about 50, and its linearity is rather horrible as the output signal approaches supply rails, but it never really clips, rather it compresses, making the output signal vary rather less in amplitude than the input signal.
Huh, a logic hex inverter. I've known about those for about 15 minutes. So it would do the digital conversion, kinda. As I understand it, if I use Vcc = 3v, then the LOW input < 0.5v and HIGH input is >2.46v. And the output LOW = 0.32v and the HIGH output would be 2.68v. Sending those into the digital GPIO would allow the use of digitalRead(); and keep the voltage under the 3.3v GPIO limit.

I don't quite understand the gain, is it FIXED with respect to a specific Vcc? At 3v, the gain is about 53 db? in Figure 5 of that link. I'm not sure what that means.

1724430096052.png
 

Ian0

Joined Aug 7, 2020
13,317
Huh, a logic hex inverter.
You can treat it as an op-amp, with only inverting input and output pinned out, and non-inverting input internally connected to half supply. Compared to a real op-amp the open loop gain is hopeless (about 50)
But make sure it's the "U" version (74HCU04) not 74HC04.
It might not be very linear, but it is monotonic (if the input increase the output always increases).
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
Would this be how to design this circuit around the 74HCU04? It creates a 1.5V dc offset for the MCU. And the 3v supply effectively protects the MCU from overvoltage.

Schematic.png
 

Ian0

Joined Aug 7, 2020
13,317
Would this be how to design this circuit around the 74HCU04? It creates a 1.5V dc offset for the MCU. And the 3v supply effectively protects the MCU from overvoltage.

View attachment 329933
That will almost work. Connect the 74HCU04 VCC to the microcontroller Vcc.
(It will probably work without R2,R1 and C1)
The DC offset at he 74HCU04 output is a bit unpredictable. It will be somewhere near half the supply voltage, but you may have to use software to eliminate it. (But if you are looking for zero-crossings, your software will do that anyway)
One thing to note is that the normal really low power consumption of the CMOS gate is no longer true when it is biassed as a linear amplifier, and it consumes at least 1mA.
 

Thread Starter

rpschultz

Joined Nov 23, 2022
851
Huh ok. Like this? So the 74HC04 will create the DC offset roughly in the middle of Vcc?
The dev board suggests it wants 3v3, but when you look up esp32 specs it says it can run on 2.8v. I could push that up towards 3.1 or 3.2. A 56k and 33k for R6, R7 would give 3.15v. I'm not sure what the goal should be. Max GPIO voltage is 3.3v. If I give the 74HC04 Vcc=3v3 then that should limit the output to less than 3v3? 100k and 200k for R6, R7 would give 3v3.

Schematic2.png
 
Top