0
votes

To smooth my data, I use gaussian function to convolve with my data in MATLAB. But there's a detail which can't be ignored. For instance, my original data is "DATA",the smoothed data is "SM_DATA", a simple matlab code will be:

gauss=gausswin(100);
gauss_normalize=gauss/sum(gauss);
SM_DATA=conv(DATA,gauss,'same');

The image will be like this:

 blue curve:original data; red curve: smoothed data

However, if I delete the 2nd line "gauss_normalize=gauss/sum(gauss);" the image will have very strong DC, see

blue curve:original data; red curve: smoothed data

Can anybody help to explain why I should use gauss_normalize to do convolution using plain but professional language? Also, it isn't a typical normalization, right? because a typical normalization would divide by the maximum value rather than the sum of the series so that the data is from 0 to 1.

1
This is due to discretization of kernels. Ultimately, if your data is all 1 and you apply the kernel, you expect to be all 1. To make sure that happens, you need to make sure that the kernel, when applied to data of all 1, returns 1. The straightforward way of doing it is normalizing the kernel. - Ander Biguri

1 Answers

1
votes

Let's look at a convolution with a simpler filter: [1,1,1].

For each output point, the convolution will multiply the filter values with the function values around this point, and sum the result:

out(i) = in(i-1) * 1 + in(i) * 1 + in(i+1) * 1;

Obviously, out(i) will have a value that is approximately three times as large as in(i), since we're simply adding up three input values.

The average of the three input values would be:

out(i) = ( in(i-1) + in(i) + in(i+1) ) / 3;

which is the same as

out(i) = in(i-1) * 1/3 + in(i) * 1/3 + in(i+1) * 1/3;

That is, the averaging filer should be [1,1,1]/3, not [1,1,1]. We've normalized the filter kernel to sum up to 1 to compute the average. When we didn't normalize, the mean of the signal went up.

Now let's take this lesson to a weighted average. The weighted average of values v with weights w is computed as

sumi ( v(i) w(i) ) / sumi ( w(i) )

or, written in MATLAB:

out(i) = ( in(i-1) * w(1) + in(i) * w(2) + in(i+1) * w(3) ) / sum(w);

As you can see, this looks identical to the convolution above, but with different kernel weights. And we're again normalizing the kernel weights.

So, given that you want to compute a weighted average using Gaussian weights, you need to normalize those weights to add up to 1. If you don't, you are not computing an average, and therefore you won't preserve the DC component (the mean across the whole signal).