RMS RAW values from audioshield - I just don't understand it

Status
Not open for further replies.

DIYLAB

Well-known member
Teensy 4.0, AudioShield, Teensyduino 1.53

Hi all,
a simple, basic question about RMS from the Audioshield:

Shouldn't this program actually give a value of 1.0 at 1V sine Vrms (1KHz)?

Code:
#include <Wire.h>
#include <Audio.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=372,361
AudioAnalyzePeak         peak1;          //xy=717,293
AudioAnalyzeRMS          rms1;           //xy=717,337
AudioAnalyzeRMS          rms2;           //xy=719,383
AudioAnalyzePeak         peak2;          //xy=720,426
AudioConnection          patchCord1(i2s1, 0, peak1, 0);
AudioConnection          patchCord2(i2s1, 0, rms1, 0);
AudioConnection          patchCord3(i2s1, 1, rms2, 0);
AudioConnection          patchCord4(i2s1, 1, peak2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=322,466
// GUItool: end automatically generated code

elapsedMillis fps = 0;

void setup() {
    // Audio
    AudioMemory(6);
    sgtl5000_1.enable();
    sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
}

void loop() {
    if (rms1.available()) {
        if (fps > 24) {
            fps = 0;

            float raw = rms1.read();
            Serial.println(raw, 2);
        }
    }
}

Displayed is only 0.89.
The value 1.0 is never reached, not even at 3V Vrms, then it is 0.95
Since I do not understand this, I ask you for enlightenment - thank you very much!
 
You realize the gain of the ADC and DAC in the SGTL are indivually settable via lineInLevel() and lineOutLevel() calls?

The defaults are 1.33V p2p on line input and 1.29V p2p on line output: https://www.pjrc.com/teensy/gui/index.html?info=AudioControlSGTL5000

1.33V p2p = 470mV rms, a reasonable line level (400mV is a commonly used value for domestic equipment) - thus
your 1Vrms was overloading the front end.

When you were putting 3V rms in you were exceeding the absolute maximum specs for the SGTL5000, note, which is about
1.2Vrms. This means the signal was basically looking like a square wave, hence the reported rms approaching 1.0

The AudioAnalyzeRMS class returns 1.0 as its maximum output, such as for a full-scale square wave, I believe.
Thus a full scale sine wave should show as 0.7071.

Try using lineInLevel (0) (3.12V p2p), feeding in 1V rms, you should see about 0.64 from AudioAnalyzeRMS
as the signal will be a sine wave at about 90% of full scale amplitude.
 
Thank you for your answer!

You realize the gain of the ADC and DAC in the SGTL are indivually settable via lineInLevel() and lineOutLevel() calls?

Yup :cool:

When you were putting 3V rms in you were exceeding the absolute maximum specs for the SGTL5000, note, which is about
1.2Vrms.

The data sheet says: 2.83 Vpp at 3.3V VDDA and 1.6 Vpp at 1.8 VDDA.
Now one would have to know, with which voltage the chip is operated - I hope very much, with 3.3V ?
At least the 1.6 Vpp would be sufficient to display up to +6dB with a 0dB reference of 775mV.

Try using lineInLevel (0) (3.12V p2p), feeding in 1V rms, you should see about 0.64 from AudioAnalyzeRMS ...

Almost. 0.66 are displayed :)

Code:
void setup() {
    // Audio
    AudioMemory(6);
    sgtl5000_1.enable();
    sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
    sgtl5000_1.lineOutLevel(13); // 3.16 Volts p-p
    sgtl5000_1.lineInLevel(0); // 3.12 Volts p-p
}

void loop() {
    if (rms1.available()) {
        if (fps > 24) {
            fps = 0;

            float raw = rms1.read();
            
            // ????????
            // float dB = 20 * log10f(raw / .775);
            
            Serial.println(raw, 2);
        }
    }
}

Ok, so let's assume that I want to feed in max. 1.6 Vpp and display a range up to +6dB.
0dB reference in this case is 775mV.

How would the dB formula (which I have commented out) have to look correct then?
 
Remember these values are approximate, audio sigma delta ADCs ad DACs are typically not accurately calibrated, the entire scaling
depends on the size of some VLSI capacitors and charge sources deep in the chip I think.

Just measure the result with a known input, calculate the dB error, and add that at the relevant place in the code?
Code:
  float dB = 20 * log10f(raw) - calibration_value ;

The audioshield schematics are not a secret(!) pin 5 of the SGTL5000 (analog supply) is connected to 3.3V via an LC noise filter.
 
Just measure the result with a known input, calculate the dB error, and add that at the relevant place in the code?

Ah, so a correction factor after all, well then it shall be so, thank you.

The audioshield schematics are not a secret(!) pin 5 of the SGTL5000 (analog supply) is connected to 3.3V via an LC noise filter.

Oops, I had only seen pin 30 across the fixed voltage regulator in the schematic, but the 3.3V makes me happy - perfect.
 
Status
Not open for further replies.
Back
Top