Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
관리 메뉴

OnlyOne

MAF(Moving Average Filter) 본문

Control Engineering/Linear System and Signal

MAF(Moving Average Filter)

Taesan Kim 2024. 8. 24. 17:02

MAF(Moving Average Filter)

MAF(Moving Average Filter)

 

Intro

이동평균필터는 노이즈를 누그러뜨리는 효과가 있다. 저주파 영역만 통과시키는 효과가 있으므로, Low-pass filter이라고 할 수 있다. 오늘은 주어진 데이타를 가져와 Matlab에서 MAF를 구현하는 작업을 할 것이다.

 

MAF

MAF는 버퍼에 들어가는 숫자들의 평균을 업로드하는 필터이다. 수학적 정의는 다음과 같다.

 

MAF

 

Matlab Simulation

다음과 같은 데이터 시트가 주어진다.

clc;clear all;close all;
Ts = 0.01;
time = 0:Ts:2*pi;
Niter = length(time);
s = sin(2*pi*time);
v = 0.1*randn(size(time));
u = s + v;
save sim_data.mat; clear all;

 

MAF를 구현하기 위한 Matlab코드는 다음과 같다.

%================================================
%Handong Global University
%------------------------------------------------
%Name:      Taesan Kim
%ID:        22300203
%Create:    2024.08.19
%Modifire:  2024.08.19
%------------------------------------------------
% MAF simulation 001
%================================================

close all; clear all; clc;
load sim_data.mat;
N = 3;
%N개의 비어있는 버퍼 생성
buffer_n = zeros(N, 1);


function [y, buffer_n] = MAFilter(N, u, buffer_n, n)
    x = 0;
    for i = 1:N
        if n-i+1 <= 0
            x = x+ sin(2*pi*0.01*(n-i+1)) + 0.1*randn(size(0.01*(n-i+1)));
        else
            x = x + u(n - i+1);
        end
    end
    y = x/N;
    %버퍼의 마지막 값만 버리고 앞에 u(N)값을 넣는다.
    %u(N)은 u의 가장 최근값
    %buffer_n = [u(end); buffer_n(2:end)];
    buffer_n = [u(N); buffer_n(1:end-1)];
end

for n=1:Niter
    [y(n), buffer_n] = MAFilter(N, u, buffer_n, n);
end

plot(time, u, 'b', 'LineWidth', 1);hold on;
plot(time, y, 'r', 'LineWidth', 1);
xlabel('Time');
ylabel('Amplitude');
title('Original Signal vs. Filtered Output');
legend('Original', 'Filtered');
grid on;

 

N = 5
N = 10
N = 20

 

시뮬레이션 1 결론 : N값이 커질수록, 초기 버퍼에서 과거 메모리 부재로 인한 필터 지연 효과가 커진다. 반면에 N 값이 커질수록 신호가 더 많이 누그러진다는 것을 알 수 있다.