Hello, I'm currently working on a project involving using an analog pin as an audio input, and I've been having some problems with harmonic distortion. The pin is being used to measure the voltage output of a microphone preamp at a sample rate of ~10.3kHz, and the distortion issue is apparent when looking at a plot of the signal being read by the Arduino: when playing a pure 233Hz sinewave into the input of the preamp, the signal that's received is heavily distorted. Looking at the spectrum of the signal, it's clear that this is harmonic distortion, because there are sharp frequency bands that form at integer multiples of 233Hz.
[this is where a couple images of the distorted signal & its spectrum would be, but I'm not currently allowed to upload more than one image]
I've been testing the system by playing signals directly into the input of the preamp using an external DAC, and the distortion issues have been present for every signal I've tried.
I am using an SSM2166 preamp, and I have it set up pretty close to how the datasheet suggests; the only notable difference is that I'm using a really small (2.2 microfarad) averaging capacitor for the level detector because, according to the datasheet, using a smaller capacitor is necessary for good low-frequency operation. Here's a schematic showing how the preamp is wired and connected to everything else:
I don't that the distortion is the result of a minor wiring mistake, as I've built two of these already and they both have the exact same problem. There probably isn't an easy solution to this, but if anyone at least has an idea of what the source of the problem might be, I'd appreciate some advice!
Can you please share your code using code tags; easiest is to use edit -> copy for forum in the IDE and paste it in a reply.
Which Arduino are you using?
Transfering a byte / character from the Arduino to the PC at 115200 baud takes approx 0.09 ms; if you uses Serial.print, you will send between 1 and 4 bytes just for the data; Serial.println will add 2 more bytes. Do the calculation and you will never get the 10 kSamples/second.
The Arduino supports far higher baudrates; my first attempt would be to increase the baudrate to 1,000,000 or 2,000,000 and see if that improves the situation. But as said, far outside my area of expertise expertise so I might be totally wrong.
The waveform is typical of signal clipping; the input voltage waveform is asymmetrical. Ideally the waveform should be balanced around the mid value reading. So if its a 10 bit ADC the mid value should be around 512 and it looks more like 900.
We are lacking a LOT of information.
Can you measure the voltage output from the preamp with no signal? It should be 2.5V.
Which would lead me to suspect the ADC is measuring 0 - 3.x volts.
What is the range and resolution of the ADC? ie WHICH Feather are you using?
After checking with no signal/silence, try a lower-level signal.
Do you have a spectrum analyzer? If you have a spectrum analyzer, I assume you have an oscilloscope? And, you're looking at the preamp output so you know it's the preamp that's defective, right?
Have you checked the output from the DAC? Have you tried the DAC directly into the Arduino? (You'll have to bias the Arduino input.)
I took a quick look at the preamp datasheet and it has compression and expansion If you're using those effects they can cause distortion.
It looks like your input signal is not biased properly to 1/2 the analog reference voltage. It looks like the top end is getting clipped, which will cause harmonic distortion.