Main Content

필터로 인해 발생하는 지연과 왜곡 보정하기

신호를 필터링하면 지연이 발생합니다. 이는 출력 신호가 입력 신호에 비해 시간적으로 이동하는 것을 의미합니다.

이동 크기가 일정할 경우, 신호를 시간적으로 이동하여 지연을 해결할 수 있습니다.

때때로 필터는 특정 주파수 성분을 다른 주파수 성분보다 더 지연시킵니다. 이 현상을 위상 왜곡이라고 합니다. 이 영향을 보정하려면 filtfilt 함수를 사용하여 영위상 필터링을 수행할 수 있습니다.

1초 동안 500Hz로 샘플링된 심전도 측정값을 가져옵니다. 랜덤 잡음을 추가합니다. 재현 가능한 결과를 얻기 위해 난수 생성기를 재설정합니다.

Fs = 500;
N = 500;

rng default

xn = ecg(N)+0.1*randn([1 N]);
tn = (0:N-1)/Fs;

75Hz가 넘는 주파수를 저지하는 필터를 사용하여 일부 잡음을 제거합니다. designfilt를 사용하여 차수가 70인 FIR 필터를 설계합니다.

Nfir = 70;
Fst = 75;

firf = designfilt('lowpassfir','FilterOrder',Nfir, ...
    'CutoffFrequency',Fst,'SampleRate',Fs);

신호를 필터링한 다음 플로팅합니다. 결과로 생성된 신호는 원래 신호보다 매끄럽지만 뒤처져 있습니다.

xf = filter(firf,xn);

plot(tn,xn,tn,xf)
title 'Electrocardiogram'
xlabel 'Time (s)'
legend('Original','FIR Filtered')
grid

Figure contains an axes object. The axes object with title Electrocardiogram, xlabel Time (s) contains 2 objects of type line. These objects represent Original, FIR Filtered.

grpdelay를 사용하여, 필터로 인한 지연이 필터 차수의 절반과 같은지 확인합니다.

grpdelay(firf,N,Fs)

Figure contains an axes object. The axes object with title Group Delay, xlabel Frequency (Hz), ylabel Group delay (samples) contains an object of type line.

delay = mean(grpdelay(firf))
delay = 35

데이터를 정렬합니다. 필터링된 신호의 처음 delay개 샘플을 제거하여 필터링된 신호를 이동시킵니다. 원래 신호와 시간 벡터의 마지막 delay개 샘플을 제거합니다.

tt = tn(1:end-delay);
sn = xn(1:end-delay);

sf = xf;
sf(1:delay) = [];

신호를 플로팅하고 신호가 정렬되었는지 확인합니다.

plot(tt,sn,tt,sf)
title 'Electrocardiogram'
xlabel('Time (s)')
legend('Original Signal','Filtered Shifted Signal')
grid

Figure contains an axes object. The axes object with title Electrocardiogram, xlabel Time (s) contains 2 objects of type line. These objects represent Original Signal, Filtered Shifted Signal.

7차 IIR 필터를 사용하여 계산을 반복합니다.

Niir = 7;

iir = designfilt('lowpassiir','FilterOrder',Niir, ...
    'HalfPowerFrequency',Fst,'SampleRate',Fs);

신호에 필터를 적용합니다. 필터링된 신호가 원래 신호보다 깨끗하지만, 원래 신호에 비해 시간상 뒤처져 있습니다. 또한 필터링된 신호는 필터의 비선형 위상으로 인해 왜곡되었습니다.

xfilter = filter(iir,xn);

plot(tn,xn,tn,xfilter)

title 'Electrocardiogram'
xlabel 'Time (s)'
legend('Original','Filtered')
axis([0.25 0.55 -1 1.5])
grid

Figure contains an axes object. The axes object with title Electrocardiogram, xlabel Time (s) contains 2 objects of type line. These objects represent Original, Filtered.

필터로 인한 군지연을 살펴보면 지연이 주파수 종속적임을 알 수 있습니다.

grpdelay(iir,N,Fs)

Figure contains an axes object. The axes object with title Group Delay, xlabel Frequency (Hz), ylabel Group delay (samples) contains an object of type line.

filtfilt를 사용하여 신호를 필터링합니다. 지연과 왜곡이 효과적으로 제거되었습니다. 신호의 위상 정보를 반드시 그대로 유지해야 하는 경우 filtfilt를 사용하십시오.

xfiltfilt = filtfilt(iir,xn);

plot(tn,xn)
hold on
plot(tn,xfilter)
plot(tn,xfiltfilt)

title 'Electrocardiogram'
xlabel 'Time (s)'
legend('Original','''filter''','''filtfilt''')
axis([0.25 0.55 -1 1.5])
grid

Figure contains an axes object. The axes object with title Electrocardiogram, xlabel Time (s) contains 3 objects of type line. These objects represent Original, 'filter', 'filtfilt'.