0
$\begingroup$

I have written some audio decoding code. I decoded an mp3 file and save as wav file.

In order to validate the code is working correctly, I compare the signal between the mp3 file and the decoded audio in wav file by using PSNR matlab (coding shown below). The results obtained are shown in the table.

Signal1 = audio.mp3;
Signal2= audio.wav;
[R C]=size(Signal1);
err = sum((Signal1 -Signal2).^2)/(R*C); 
MSE=sqrt(err);
MAXVAL=255;
PSNR = 20*log10(MAXVAL/MSE); 

PSNR Result

How can I comment on the result?

According to the post here, it says ‘If the reconstructed audio signal is exactly same as original signal then MSE =0. And if Max pixel value is 255 (8-bit representation), then the value of PSNR = 20*log(255) = 48dB.’

Since the PSNR of the songs are more than 48, can I conclude that the decoded audio signal in the wav file is valid?

$\endgroup$
8
  • $\begingroup$ um, where does you MAXVAL come from? I doubt it's right. $\endgroup$ Apr 28 '20 at 8:51
  • $\begingroup$ @MarcusMüller, if Max pixel value is 255 (8-bit representation), then the value of PSNR = 20*log(255) = 48dB. This is the maximum value of PSNR when signal is represented in 8-bits. $\endgroup$
    – Cyan
    Apr 28 '20 at 9:16
  • 1
    $\begingroup$ ... that is just repeating what's in your question. What I meant to ask is "how do you know your maximum value is 255? That sounds wrong!". $\endgroup$ Apr 28 '20 at 9:22
  • $\begingroup$ Audio doesn't have pixels and typically doesn't work with 8-bit (unless it's really bad audio) $\endgroup$
    – Hilmar
    Apr 28 '20 at 11:15
  • 1
    $\begingroup$ If the MSE is zero, then the PSRN would be infinite $\endgroup$ Apr 28 '20 at 11:22
1
$\begingroup$

If the reconstructed audio signal is exactly same as original signal then MSE =0. And if Max pixel value is 255 (8-bit representation), then the value of PSNR = 20*log(255) = 48dB

That statement is plain wrong. If the two signals are identical, then MSE = 0, then division by zero is undefinied and you don't get a PSNR at all, but "infinity".

Since the PSNR of the songs are more than 48, can I conclude that the decoded audio signal in the wav file is valid?

PSNR is really not a very useful metric; you can get these values with a codec that simply broken, or one that sounds great.

Let's throw a bit of math in here: let's say we map our 8 bit to - to +1. Our original audio signal $S$ is well-scaled and its amplitude is pretty normally distributed¹, centered around 0, and has a variance $\sigma^2=\frac14$, so that clipping very rarely happens, i.e. $S\sim\mathcal N(0;\frac14)$.

Then, what's the PSNR of a codec that simply always produces "0"?

\begin{align} \text{PSNR} &= 20\log_{10}\left(\frac{\text{Maxval}}{\sqrt{\text{MSE}}}\right)\\ &=20\log_{10}\left(\frac{\text{1}}{\sqrt{\text{MSE}}}\right)\\ &=10\log_{10}\left(\frac{\text{1}}{\sqrt{\text{MSE}}}\right)^2\\ &=10\log_{10}\left(\frac{\text{1}}{\text{MSE}}\right)\\ \end{align}

So, what's our MSE? It is

\begin{align} \mathbb E\left((0-S)^2\right)&= \mathbb E\left( S^2\right)\\ &S \text{ is zero-mean}\\ &=\text{Var}\{S\}=\sigma^2\\ &=\frac14 \end{align}

Therefore,

\begin{align} \text{PSNR} &= 10\log_{10}(4) \\ &\approx 6 \end{align}

So, what this would prove is that your codec is better than just producing the mean value of the information-theoretically worst possible continuous audio source – but that's about it.


¹ that assumption about the amplitude distribution is slightly wrong, but wrong in favor of your codec.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.