This example shows how to apply adaptive filters to noise removal using adaptive noise canceling.
Author(s): Scott C. Douglas
In adaptive noise canceling, a measured signal d(n) contains two signals: - an unknown signal of interest v(n) - an interference signal u(n) The goal is to remove the interference signal from the measured signal by using a reference signal x(n) that is highly correlated with the interference signal. The example considered here is an application of adaptive filters to fetal electrocardiography, in which a maternal heartbeat signal is adaptively removed from a fetal heartbeat sensor signal. This example is adapted from Widrow, et al, "Adaptive noise canceling: Principles and applications," Proc. IEEE, vol. 63, no. 12, pp. 1692-1716, December 1975.
In this example, we shall simulate the shapes of the electrocardiogram for both the mother and fetus. The following commands create an electrocardiogram signal that a mother's heart might produce assuming a 4000 Hz sampling rate. The heart rate for this signal is approximately 89 beats per minute, and the peak voltage of the signal is 3.5 millivolts.
x1 = 3.5*ecg(2700).'; y1 = sgolayfilt(repmat(x1,69,1),0,21); Hmhb = dsp.SignalSource(y1,'SamplesPerFrame',100,... 'SignalEndAction','Cyclic repetition');
The heart of a fetus beats noticeably faster than that of its mother, with rates ranging from 120 to 160 beats per minute. The amplitude of the fetal electrocardiogram is also much weaker than that of the maternal electrocardiogram. The following series of commands creates an electrocardiogram signal corresponding to a heart rate of 139 beats per minute and a peak voltage of 0.25 millivolts.
x2 = 0.25*ecg(1725).'; y2 = sgolayfilt(repmat(x2,108,1),0,17); Hfhb = dsp.SignalSource(y2,'SamplesPerFrame',100,... 'SignalEndAction','Cyclic repetition');
The maternal electrocardiogram signal is obtained from the chest of the mother. The goal of the adaptive noise canceller in this task is to adaptively remove the maternal heartbeat signal from the fetal electrocardiogram signal. The canceller needs a reference signal generated from a maternal electrocardiogram to perform this task. Just like the fetal electrocardiogram signal, the maternal electrocardiogram signal will contain some additive broadband noise.
mnoise = 0.02*randn(size(y1)); Hmn = dsp.SignalSource(mnoise,'SamplesPerFrame',100); Hts = dsp.TimeScope('SampleRate',4000,'YLimits',[-4,4],'TimeSpan',2.5); for k = 1:length(y1)/Hmhb.SamplesPerFrame x = step(Hmhb) + step(Hmn); step(Hts,x); end
The measured fetal electrocardiogram signal from the abdomen of the mother is usually dominated by the maternal heartbeat signal that propagates from the chest cavity to the abdomen. We shall describe this propagation path as a linear FIR filter with 10 randomized coefficients. In addition, we shall add a small amount of uncorrelated Gaussian noise to simulate any broadband noise sources within the measurement. Can you determine the fetal heartbeat rate by looking at this measured signal?
Wopt = [0 1.0 -0.5 -0.8 1.0 -0.1 0.2 -0.3 0.6 0.1]; Hd = dsp.FIRFilter('Numerator',Wopt); fnoise = 0.02*randn(size(y2)); Hfn = dsp.SignalSource(fnoise,'SamplesPerFrame',100); release(Hts); for k = 1:length(y2)/Hfhb.SamplesPerFrame d = step(Hd,step(Hmhb)) + step(Hfhb) + step(Hfn); step(Hts,d); end
The adaptive noise canceller can use most any adaptive procedure to perform its task. For simplicity, we shall use the least-mean-square (LMS) adaptive filter with 15 coefficients and a step size of 0.00007. With these settings, the adaptive noise canceller converges reasonably well after a few seconds of adaptation--certainly a reasonable period to wait given this particular diagnostic application.
Hlms = dsp.LMSFilter('Length',15,'StepSize',0.00007);
The output signal y(n) of the adaptive filter contains the estimated maternal heartbeat signal, which is not the ultimate signal of interest. What remains in the error signal e(n) after the system has converged is an estimate of the fetal heartbeat signal along with residual measurement noise. Using the error signal, can you estimate the heart rate of the fetus?
release(Hts); release(Hmn); release(Hfn); reset(Hd); Hts.YLimits = [-0.5,0.5]; for k = 1:length(y2)/Hfhb.SamplesPerFrame mhb = step(Hmhb); d = step(Hd,mhb) + step(Hfhb) + step(Hfn); x = mhb + step(Hmn); [~,e] = step(Hlms,x,d); step(Hts,e); end