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 ) ;