# EVAR - Noise variance estimation.

Assuming that the deterministic function Y has additive Gaussian noise, EVAR(Y) returns an estimated variance of this noise.

A thin-plate smoothing spline model is used to smooth Y. It is assumed that the model whose generalized cross-validation (GCV) score is minimal can provide the variance of the additive noise. EVAR theoretically works better if Y is differentiable. A few tests, however, showed that EVAR works very well even i some singularities are present.

Note: EVAR is only adapted to evenly-gridded 1-D to N-D data.

## Example #1: 1D signal

```n = 1e6; x = linspace(0,100,n);
y = cos(x/10)+(x/50); % differentiable function
var0 = 0.02; % actual noise variance
yn = y + sqrt(var0)*randn(size(y)); % noisy function
est_var = evar(yn); % estimated variance
plot(x,yn,x,y)
title(['Actual variance: ' num2str(var0) ' / Estimated: ' num2str(est_var)])
``` ## Example #2: 2D function

```[x,y] = meshgrid(0:.01:1);
f = exp(x+y) + sin((x-2*y)*3); % differentiable function
var0 = 0.04; % actual noise variance
fn = f + sqrt(var0)*randn(size(f)); % noisy function
est_var = evar(fn); % estimated variance
surf(x,y,fn), axis square
title(['Actual variance: ' num2str(var0) ' / Estimated: ' num2str(est_var)])
``` ## Example #3: 3D function

```[x,y,z] = meshgrid(-2:.05:2);
f = x.*exp(-x.^2-y.^2-z.^2); % differentiable function
var0 = 0.6; % noise variance
fn = f + sqrt(var0)*randn(size(f)); % noisy function
est_var = evar(fn); % estimated variance
disp(['Actual variance: ',num2str(var0),newline,'Estimated variance: ',num2str(est_var)])
```
```Actual variance: 0.6
Estimated variance: 0.59839
```

## Example #4: Actual versus estimated variance

A deterministic signal with 1000 data points is created. This signal is blurred by a Gaussian noise whose variance ranges between 0 and 0.5.

```n = 1e3;
x = linspace(0,25,n);
y = round(sin(x)); % differentiable function
sig2 = linspace(0,0.5,50);
```

Example with a variance of 0.2

```yn = y + sqrt(0.2)*randn(1,n);
plot(x,yn,'r',x,y,'k')
``` Estimate the variance of the additive noise by using EVAR

```est_sig2 = zeros(1,50);
for i = 1:50
yn = y + sqrt(sig2(i))*randn(1,n); % noisy function
est_sig2(i) = evar(yn);
end
```

Compare the estimated variance (est_sig2) with the actual variance (sig2)

```plot(est_sig2,sig2,'o',[0 0.5],[0 0.5],'k')
axis([-0.05 0.55 -0.05 0.55])
axis square
xlabel('Estimated variance')
ylabel('True variance')
``` ## References

Please refer to the two following papers:

1. Garcia D. Robust smoothing of gridded data in one and higher dimensions with missing values. Computational Statistics & Data Analysis, 2010;54:1167-1178.
2. Craven P, Wahba G. Smoothing noisy data with spline functions. Estimating the correct degree of smoothing by the method of generalized cross-validation. Numerische Mathematik 1979;31:377–403.

```Damien Garcia, Eng., Ph.D.