# Audio Quality Measurement

### Theoretical Overview

We can generate a 500Hz signal by following formula:

`sin(x * 2 * 500)`

Result:

We can also generate a noise in interval `<-1, -1>`

:

`rand(-0.1, 0.1)`

which produces curve:

To calculate RMS of such signals we use the formula:

`Xrms = sqrt((1 / n) * (X1 ^ 2 + X2 ^ 2 + ... + Xn ^ 2))`

The ratio of both signals is by following formula:

`20 * log10(SignalRms / NoiseRms) [dB]`

### Measurement

Your oscilloscope can measure such signal with a noise present:

This has been simulated by formula:

`sin(x * 2 * 500) + rand(-0.1, 0.1)`

But real measured signal looks like this (with red ideal wave):

*HiFiBerry DAC+ frequency response*

Where a zoom looks like this:

*HiFiBerry DAC+ frequency response zoomed*

- Blue - measured signal
- Red - ideal sine wave

### Calculation

For theoretical wave `sin(x * 2 * 500) + rand(-0.1, 0.1)`

we could subtract the exact part `sin(x * 2 * 500)`

and will get `rand(-0.1, 0.1)`

.

With formulas will get:

```
SignalRms = 0.70681
SignalNoise = 0.05773
20 * log10(SignalRms / NoiseRms) = 20 * log10(0.70681 / 0.05773) = 21.75779 dB
```

#### Real World Calculation

For real measured wave we must find the exact ideal wave. Since we know the frequency (set on signal generator or played exact wav with given frequency) we only must correct the phase shift and amplitude. See above the red curve which is such ideal curve going through the measured one. After subtraction we get the noise curve.

For HIFIBerry Dac+ above it is:

```
RMS[B] = 0.13295
RMS[A] = 0.13283
σ[A,B] = sqrt((1 / N) * Σ(A-B)^2) = 0.00122
SNR[A / B] = 20*log(RMS[B] / σ) = 40.74621 dB
```

*Note: the value doesn't correspond with rated value but this is a topic for another article*