I am trying to make a basic VoIP implementation and I am stuck obtaining sound samples from the mic and playing the read data on a computer. I tried to sample the voice from the microphone and send it to the serial terminal using a very minimal code:

void setup() {

void loop() {
    int sensorValue = analogRead(A0);

The delayMicroseconds(122) causes the sample rate to be around 8192 Hz. I also tried with a sample rate of 1000 Hz. The data plot obtained looks good, however, when I try to play it with the MATLAB command

sound(csvread('samples.csv'), 8192);

I do not really hear what it should be (I just hear random noise). I am attaching a graph of the obtained data and my microphone circuit. (I also tried subtracting the average from the array so the values are centered around zero, but no use).

Data Obtained:

enter image description here

Microphone Circuit:

enter image description here


1 Answer 1



Your signal looks like it doesn't have much dynamic range. You may want to look into amplifying it before it reaches the arduino's ADC.

The AVR based Arduinos have a 10 bit ADC -- 0 to 1024. At 5 volts Vref that is

\$ \frac{5volts}{ 1024 counts} = 4.9 \frac{mVolt }{ count}\$

Your signal ranges from ~150 to ~225. This is 75 counts of range or 7% of the ADC's resolution. Your input signal varies by about 366mV peak to peak.

It should vary by about 2.5v peak to peak.


Matlab's documentation on audio files states the following:

The MATLAB sound and soundsc functions support only single- or double-precision values between -1 and 1.

Your arduino code is printing values from 0-1024. Integers. You will need to normalize them and remove the DC bias: make the signal have an average of 0, and a range of [-1 1].

input = double(csvread('samples.csv')); input = input - 512; % convert the [0 to 1024] range to [-512 to 512] input = input ./ 512; % convert the [-512 to 512] range to [-1 to 1] sound(input, 8192);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.