MATLAB ::均方误差与SNR图

时间:2014-10-28 20:56:30

标签: matlab plot mean-square-error

我很难理解生成SNR(db)与MSE图的背后的逻辑。通过改变噪声功率来产生不同的信噪比(SNR)。 MSE的公式是T个独立运行的平均值。

对于每个SNR,我生成NEval = 10 time series。当SNR在[0:5:50]范围内时,如何正确绘制SNR与MSE的关系图?下面是伪代码。

 N = 100; %Number_data_points
NEval = 10; %Number_of_different_Signals
Snr = [0:5:50];
T = 1000; %Number of independent runs

MSE = [1];
for I = 1:T
 for snr = 1: length(Snr)
   for expt = 1:NEval
    %generate signal
      w0=0.001;  phi=rand(1);
    signal = sin(2*pi*[1:N]*w0+phi); 
    % add zero mean Gaussian noise
    noisy_signal = awgn(signal,Snr(snr),'measured');
    % Call Estimation algorithm
    %Calculate error
    end
  end
end

plot(Snr,MSE); %Where and how do I calculate this MSE

1 个答案:

答案 0 :(得分:0)

如此处所解释的(http://www.mathworks.nl/help/vision/ref/psnr.html)或其他类似的来源,MSE只是原始信号和损坏信号之间的均方误差。在你的符号中,

w0=0.001;
signal = sin(2*pi*[1:N]*w0);
MSE = zeros(T*Neval,length(Snr));
for snr = 1:length(Snr)
    for I = 1:T*Neval     %%note, T and Neval play the same role in your pseudo code
        noisy_signal = awgn(sin(2*pi*[1:N]*w0+rand(1)),Snr(snr),'measured');
        MSE(I,snr) = mean((noisy_signal - signal).^2);
    end
end
semilogy(Snr, mean(MSE))  %%to express MSE in the log (dB-like) units

对于不同长度信号的情况:

w0=0.001;
Npoints = [250,500,1000];    
MSE = zeros(T,length(Npoints),length(Snr));
for snr = 1:length(Snr)
  for ip = 1:length(Npoints) 
    signal = sin(2*pi*[1:Npoints(ip)]*w0);
    for I = 1:T
        noisy_signal = awgn(sin(2*pi*[1:Npoints(ip)]*w0+rand(1)),Snr(snr),'measured');
        MSE(I,ip,snr) = mean((noisy_signal - signal).^2);
    end
  end
end
semilogy(Snr, squeeze(mean(mean(MSE,1),2)) )