code for calculating root mean square error of two quantities having different dimensions?

I am doing floating to fixed point conversion. output of Fixed point conversion has different dimensions than the same of floating point engine. How to calculate root mean square error in such a case?
er = M - x; er = sqrt((er(:)'*er(:))/length(er(:))); Using the above formulas, matlab's giving error that matrix dimensions must agree

1 Comment

Fix the output to have the same number or truncate the longer of the two to the shorter. It makes no sense to talk of a error if there's nothing to compare to.

Sign in to comment.

 Accepted Answer

I assume it is the line
er = M - x;
that is giving the error. Do M and x have different dimensions, but the same number of elements? If so, then try transposing one of the vectors like this:
er = M' - x;
If they have different number of elements, then I am completely befuddled as to how you expect to calculate the error from these two variables. There must be a one-to-one comparison for the error to make sense (most of the time).

2 Comments

Hi,
thanks for the reply. M & x have different number of elements. I am trying to truncate the larger of the two to the smaller one & then trying to find the error.
But, this is so confusing. Do M(1) and x(1) really correspond to each other, such that that is a valid measure of error? What about M(7234) and x(7234)?
Or is it more complicated, with M and x being sampled at different rates or times, such that there is not a one-to-one correspondence?

Sign in to comment.

More Answers (1)

Agree w/ cycler that it's confusing why this should be so, but the answer to the question ...trying to truncate the larger of the two to the smaller one & then trying to find the error is pretty simple.
N=min(length(M), length(x));
er=M(1:N)-x(1:N);
Now, whether that really makes any sense or not is beyond the amount of information we have to judge but it should solve your immediate problem programmatically, anyway.

2 Comments

thanks for the answer. I am doing 32 bit floating to 24 bit fixed point conversion of an audio signal. Number of elements in one dimension of sampled data of both cases are slightly different from each other. That's the reason why I am finding the rms error in this way.
Would seem like in that case you'd be better off resampling to a constant time base.

Sign in to comment.

Asked:

on 27 May 2014

Commented:

dpb
on 27 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!