0
votes

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

??????

2
Take a look at your signal: plot(1:length(signal),signal) Where is the noise?siliconwafer

2 Answers

1
votes

First you have to find out the power of your original signal and then you you have to calculate the power of noise using given snr information. Then you have to construct the noise signal using power information you calculated in last step. Then add the noise signal in actual signal and afterwards, use following lines of code.

I tried to implement the procedure which I have explain above:

Below code, I picked from your question:

n = 1:512;
signal = exp(-5*(n-250).^2/100000).*cos(pi*(n-250)/6);
Snr = 30:-5:-10 ;

Calculation of power from signal:

power_signal = (1/length (n))* sum ( signal.^2) ;

Calculation of different noise powers using the snr information:

P_noise = [] ;
for i = 1: length(Snr) 
    p_noise (i) = power_signal/(Snr(i) /10) ;
end

To keep things simple, I picked the signal and noise correspond to first snr level:

noise   = wgn (1, length(n), p_noise (1), 'linear') ;
ModifiedSignal = signal + noise  ;

MSE calculation:

 differ = abs(signal - ModifiedSignal).^2  ; 
 MSE = sum(differ(:) )/ numel(signal ) ;
0
votes
%MSE Original Signal
MSE_original_signal = (double(original_signal) - double(noise_signal)) .^ 2;
MSE_original_signal = sum(sum(MSE_original_signal)) / (length(n)); 
fprintf('\nMSE Original Signal.....= %3.4f', MSE_original_signal);

Mean Square Error (MSE) Calculating the mean square of each signal to enable comparison. the closest value compared to the mean square of the original signal is the most accurate one.

  1. Cast the number of samples to type floating point so as to ensure there are no negative differences.

  2. Subtract floating point integers on an elementwise basis.

  3. Square the elements of the resultant matrix from the subtraction

  4. Sum the Squared Signals

  5. Divide by the number of elements of the original matrix

  6. (optional for Root mean square) Square root the answer to get the Root Mean Squared Error