Matlab: Mean Square Error
이전 댓글 표시
Hi I am new to Matlab and I am having difficulties understanding the logic behind Mean Square Error. I have been given a signal and I am able to generate it and calculate SNR of the signal, is there a way to find mean square error between original signal and SNR signal?
% Number of Samples.
n = 1:512;
% Given Signal
signal = exp(-5*(n-250).^2/100000).cos(pi(n-250)/6);
% Range of SNR
Snr = 30:-5:-10
% Calculate and display MSE between the original signal and noisy signal
??????
댓글 수: 3
Adam
2015년 5월 1일
Which part of it do you not understand?
- Calculate the error (subtraction)
- Square it
- Apply a mean filter to the result with a filter size you feel appropriate
would be the usual process I imagine.
Ali Arslan
2015년 5월 1일
Adam
2015년 5월 2일
I'm still not sure exactly what aspect you are struggling on.
signal - noisy_signal;
is a subtraction.
a.^2
is a squaring of the an array a.
The Mathlab documentation includes plenty of help on applying a simple mean filter to the result of that.
답변 (1개)
Image Analyst
2015년 5월 1일
1 개 추천
If you have the Image Processing Toolbox, use immse() or psnr().
댓글 수: 4
Ali Arslan
2015년 5월 1일
Image Analyst
2015년 5월 1일
I suggest you make an n with linspace(), and plug it in
n = linspace(0, 50000, 512);
sn = exp(-5*(n-250)* 2/100000) .* cos(pi *(n - 250) / 6);
plot(n, sn, 'b*-');
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
Note: this is a badly aliased signal as you can see by increasing the number of samples from 512 to 1000 to 5000 to 10000 or more. The period of the cosine wave is 12 so you should have at least one sample every 3 units to not have bad aliasing.
Ali Arslan
2015년 5월 2일
편집: Ali Arslan
2015년 5월 2일
Image Analyst
2015년 5월 2일
Like Adam, I'm confused why this is so complicated and confusing to you. The name tells you how to do it. Let me do it in multiple steps.
Get the error
theError = signal - noisySignal;
Square it
squaredError = theError .^ 2;
Get the mean
% Use the mean() function.
I can't do every single step for you because it sounds like homework but the last step is unbelievably trivial.
One thing to get clarification on from your instructor is if the SNR is calculated based on the maximum signal, or is is supposed to apply on a element by element basis, which means the noise on the right will be less than on the left because the signal decays.
카테고리
도움말 센터 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!