[Finishing] The smoothing center Matlab

Moving average (moving average): in FIG geophysical anomaly, a window size is selected, all outliers Averages within the window, and the average value of the window as the center point exception. Press pitch line distance or moving window, the average method is repeated until the completion of the process the whole image, this process is called moving average.

Equivalent moving average low-pass filtering, this method is commonly used in the exploration and gravity of the log data processing and interpretation.

If the sliding window of length n, then, is to allow the moving average data through an n-point FIR filter, the filter tap coefficients are 1, and taking the moving average smoothing action sequence is played.

There are several Matlab moving average method, such as filter tsmovavg and methods can be implemented.

Ordinary Moving Average

Based on the weight of the moving average filter ordinary no right, there are about filter function, you can doc filterview detailed information, we are here because only a simple moving average, a simple moving average method in this record.

seqOriginal = rand(1,100);
windowSize  = x;
seqFilter   = filter( ones(1, windowSize) / windowSize, 1, seqOriginal );

The above command is actually calculated:

x表示seqOriginal, y表示seqFilter, a表示windowSize。
y(1) = (1 / a) * x(1);
y(2) = (1 / a) * x(2) + (1 / a) * x(1);
...
y(a) = (1 / a) * x(a) + (1 / a) * x(a - 1) + ... + (1 / a) * x(1);
...
y(i) = (1 / a) * x(i) + (1 / a) * x(i - 1) + ... + (1 / a) * x(i - a + 1);
...

NOTE: Since this method is that the point and the average calculated before windowSize point, so the output with respect to the original data trends there is a lag. If the data is less than, greater impact may be.

Center Moving Average

There is a method of moving average centered moving average, the data point in the center of the sliding window average value calculation. It becomes the above calculations (for convenience herein imaginary number, a set of an odd number):

y(1) = (1 / a) * x(1) + (1 / a) * x(2) + ... + (1 / a) * x((a+1) / 2);
y(2) = (1 / a) * x(1) + (1 / a) * x(2) + ... + (1 / a) * x((a+1) / 2 + 1);
...
y((a + 1) / 2) = (1 / a) * x(1) + (1 / a) * x(2) + ... + (1 / a) * x((a+1) / 2) + (1 / a) * x(a);
...
y(i) = (1 / a) * x(i - (a - 1) / 2) + (1 / a) * x(i - (a - 1) / 2 + 1) + ... + (1 / a) * x(i) + ... + (1 / a) * x(i + (a+1) / 2);
...

Converting the formula to Matlab statement:

seqOriginal = rand(1,100);
windowSize  = x;
seq1        = filter( ones(1, windowSize / 2 + 1) / windowSize, 1, seqOriginal );
seq2        = filter( ones(1, windowSize / 2 + 1) / windowSize, 1, fliplr(seqOriginal) );
seqFilter   = seq1 + fliplr(seq2) - 1 / windowSize * seqOriginal;

For ease of use, its function is to write a function call.

%fun_CenterAverageFilter
%--
%   seqFilter = fun_CenterAverageFilter(seqOriginal, windowSize)
%   中心滑动平均
%--
%   seqFilter   |Matrix|    滤波后输出序列  
%   seqOriginal |Matrix|    原始序列
%   windowSize  |Double|    滑动窗口
%--
%Author:    Liu Tong
%History:
%----
%Rev:  1.0
%Date: 2016/12/22
%   create.
%--
function seqFilter = fun_CenterAverageFilter(seqOriginal, windowSize)
seq1        = filter( ones(1, windowSize / 2 + 1) / windowSize, 1, seqOriginal );
seq2        = filter( ones(1, windowSize / 2 + 1) / windowSize, 1, fliplr(seqOriginal) );
seqFilter   = seq1 + fliplr(seq2) - 1 / windowSize * seqOriginal;
end

Guess you like

Origin www.cnblogs.com/airbird/p/11455223.html