how can I write the MSE in matlab??
13 次查看(过去 30 天)
显示 更早的评论
Dear All, can anyone help me in implementing this formula on matlab? where aX(λ,k) is the true (clean) magnitude spectrum at frame λ and bin k; a^X(λ,k) is the estimated magnitude spectrum (following enhancement), M is the total number of frames in a sentence, and N is the number of frequency bins. The signal are complex column vectors and both size Mx1. Thanks you.
0 个评论
回答(1 个)
Image Analyst
2014-6-28
See my attached demo below. Here's a snippet from it:
%------ PSNR CALCULATION ----------------------------------------------------------
% Now we have our two images and we can calculate the PSNR.
% First, calculate the "square error" image.
% Make sure they're cast to floating point so that we can get negative differences.
% Otherwise two uint8's that should subtract to give a negative number
% would get clipped to zero and not be negative.
squaredErrorImage = (double(grayImage) - double(noisyImage)) .^ 2;
% Display the squared error image.
subplot(2, 2, 3);
imshow(squaredErrorImage, []);
title('Squared Error Image', 'FontSize', fontSize);
% Sum the Squared Image and divide by the number of elements
% to get the Mean Squared Error. It will be a scalar (a single number).
mse = sum(squaredErrorImage(:)) / (rows * columns);
% Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula.
PSNR = 10 * log10( 256^2 / mse);
% Alert user of the answer.
message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR);
msgbox(message);
2 个评论
Image Analyst
2014-6-28
Yes, it's the same, though you could simplify a bit by getting rid of the (:) since your signal is already a 1D signal
mse = sum(squaredErrorImage) / numel(squaredErrorImage);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!