One-dimensional Gaussian filter revolutions

Transfer: https: //blog.csdn.net/shanchuan2012/article/details/53071159 

 

1. Speaking from the normal distribution

 

 

We generate Gaussian template is from this formula come. For example, to generate a size of 3, the standard deviation of the template 1, need only substituting formula (where the mean μ \ muμ is 0, which is not translated to 0): f (-1) f (-1 ) f (-1), f (0) f (0) f (0), f (1) f (1) f (1) can be obtained of the value of the template.

2. Gaussian filter is how to achieve?
In fact, very simple idea, the characteristics of the Gaussian distribution is the mean μ \ probability of muμ both sides are large, the smaller the probability that the farther away, so the Gaussian function used in the filter idea is embodied: from a point nearer the the greater the impact point of their produce, so let the weight is greater, the farther the impact of smaller, less heavy weights allowed.

For example, following a sequence of operations in which the 6, the template is [1,2,1]:

1 2 3 5 6 3 1. 7 5 3. 8
|
1 2 1
1
2
3
the result is: (5 * 1 + 6 * 2 + 3 * 1) / (1 + 2 + 1) = 5 (5 * 1 + 6 * 2 * 3 + 1) / (1 + 2 + 1) = 5 (1 + 6 * 5 * 3 * 2 + 1) / (1 + 1 + 2) = 5, for each such data operation, known as a Gaussian filter.

There is a problem, and if so how do the start and end?

One approach is to make 0:

2. 5. 6. 3. 1 0. 3. 1. 5. 7. 8. 3
|
. 1 2. 1
. 1
2
. 3
Another approach is to keep out of range signal of the template, after an approach adopted here.

3.matlab codes
Gaussian filter function Gaussianfilter:

% Features: one-dimensional Gaussian filtering the signal, the signal head and tail r / 2 does not perform filtering
% R & lt: Gaussian template size is recommended odd
% Sigma: standard deviation
% Y: sequence required Gaussian filter
function y_filted = Gaussianfilter (r , sigma, y)

% To generate one-dimensional Gaussian filter template
GaussTemp = ones (. 1, 2-1 R & lt *);
for I =. 1: 2-1 * R & lt
GaussTemp (I) = exp (- (IR) ^ 2 / (2 * 2 ^ Sigma )) / (Sigma * sqrt (2 * PI));
End

% Gaussian
y_filted = Y;
for I = R & lt: length (Y) -R & lt +. 1
y_filted (I) = Y (I-R & lt +. 1: I-R & lt +. 1) * GaussTemp ';
End

test code:

% Test data
X = 1:50;
Y = X + RAND (1,50) * 10;

% Set the size and standard deviation of Gaussian template
R & lt =. 3;
Sigma =. 1;
y_filted = Gaussianfilter (R & lt, Sigma, Y);

Comparative mapping%
Plot (X, Y, X, y_filted);
title ( 'Gaussian filtering');
Legend ( 'pre filter', 'filtered', 'Location', 'northwest ')

How?

M 2 new file, a named Gaussianfilter, copied into the first code; the other named testgauss, copied into the second segment of code, save. In testgauss click the Run button, you can see the results.

result:


---------------------
Author: itsc
Source: CSDN
Original: https: //blog.csdn.net/shanchuan2012/article/details/53071159
Disclaimer: This article as a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/hjj-fighting/p/11269552.html