0

I'm trying to calculate the MSE of some audio files in MATLAB. My code is shown below.

[y1,fs1]=audioread('one.mp3');
[y2,fs2]=audioread('two.mp3');
[c1x,c1y]=size(y1);
[c2x,c2y]=size(y1);

 R=c1x;
 C=c1y;
err = sum((y1-y2).^2)/(R*C);
MSE=sqrt(err);

The problem is, when the MSE is calculated, I get a 1 x 2 matrix, when instead I need a single value.

What am I doing wrong?

volvic
  • 1

1 Answers1

0

Your code is probably returning a value for each channel of audio. If you have two channels it will return two values, if you have three channels it will return three values, etc.

More importantly:

It looks like your normalising the summation by the number of channels by using (R*C). The square root (sqrt) is also unnecessary for MSE. (And you've found the size of y1 twice).

Perhaps use this for MSE instead:

MSE = mean( (y1 - y2).^2 );

Now it will find the mean based on the number of rows and divide by that size automagically. :)

Edit:

If you want the squared errors separately:

err_sq = (y1 - y2).^2;
MSE = mean( err_sq );
JacobD
  • 627
  • 6
  • 15