Beruflich Dokumente
Kultur Dokumente
CONTENTS
Abstract
Chapter 1
introduction
introduction of anc
filter implementation
adaptive filters
adaptive filters in the filter design toolbox
noise cancellation
adaptive signal identification
general properties
system identification
noise cancellation
Chapter 5 matlab
Matlab Introduction
features of MATLAB
MATLAB System
Development Environment.
Graphics.
Starting MATLAB
MATLAB Desktop
Implementations
Arithmetic operations
Generating Matrices
M-Files
Graph Components
Plotting Tools
Editor/Debugger
Chapter 6 SIMULATION
CODE
RESULTS
APPPENDIX – BIBILOGRAPHY
CONCLUSION
Abstract:
Introduction:
The aim of the ECG simulator is to produce the typical ECG waveforms of
different leads and as many arrhythmias as possible. My ECG simulator is a
matlab based simulator and is able to produce normal lead II ECG
waveform.
Principle:
Fourier series
Any periodic functions which satisfy dirichlet’s condition can be expressed
as a series of scaled magnitudes of sin and cos terms of frequencies which
occur as a multiple of fundamental frequency.
∞ ∞
f (x) = (ao/2) + Σ an cos (nπx / l) + Σ bn sin (nπx / l),
n=1 n=1
ao = (1/ l ) ∫ f (x) dx , T = 2l --
(1)
T
Calculations:
If we observe figure1, we may notice that a single period of a ECG signal is
a mixture of triangular and sinusoidal wave forms. Each significant feature
of ECG signal can be represented by shifted and scaled versions one of these
waveforms as shown below.
• QRS, Q and S portions of ECG signal can be represented by triangular
waveforms
• P, T and U portions can be represented by triangular waveforms
Once we generate each of these portions, they can be added finally to get the
ECG signal.
Lets take QRS waveform as the centre one and all shiftings takes place with
respect to this part of the signal.
ao = (1/ l ) ∫ f (x) dx
T
= (a/b) * (2 – b )
∞
f (x) = (ao/2) + Σ an cos (nπx / l)
n=1
∞
f (x) = (ao/2) + Σ an cos (nπx / l)
n=1
CHAPTER 2
INTRODUCTION
In a general sense, adaptive filters are systems that vary through time
because the characteristics of its inputs may be varying. That is what separates it from
classical digital signal processing - the digital system itself changes through time. In a
sense, its convolution properties are evolving.
FILTER IMPLEMENTATION
When we began the project, nobody in the group had ever seen a DSP board
like the ones in the lab before, let alone used one. Our first hurdle to overcome was to
familiarize ourselves with the boards functionality.
Using the Elec434 web page as a basis for learning, we set out to master the
structure of the DSP boards use. Our first steps of understanding the boards involved
doing several of Dr. Choi's lab assignments for 434. Upon completing the third lab, we
understood how to implement a low pass FIR filter. MATLAB is used to generate the
desired coefficients. These coefficients are then saved to a file as the two's complement
representation in Q15 (16 bit fixed point) format.
When the board is run, the main function is used to initialize all variables,
and an infinite loop with no operations is run to keep the board running. However, the
board has several interrupts built in that will cause the board to perform various tasks.
One of these interrupts is used for inputing data from the CODEC. Our implementations
of filters involved using this interrupt (IRQ 11) to carry out our desired task.
Every time the interrupt is used, it means that there is an input sample ready
to be dealt with. In our code, we wrote our algorithms into this section of the board. For
most (non-adaptive) filters, this just meant shifting our array, taking a dot product, and
giving an output. Having carried out the first three labs, we were fully capable of creating
low-pass, high-pass, and band-pass filters in real-time.
Previous to this stage, we were working on the DSK boards in the lab, but
due to limitations on the board, we had to switch over to the EVM boards. The big
advantage of doing this was that the DSK boards only have one input on the CODECs,
while the EVM boards have two. We needed the second input if we were to have some
reference to our noise signal. Though it was only a small task, we had to make sure our
FIR filters worked on the EVM board. The EVM boards did offer one extra challenge
though - the gains on the two inputs is different, and therefore it was increasingly difficult
to match the decibel level between the two. This didn't affect our algorithm on the board
very much, but dealing with different sized gains on the inputs made it difficult to not
overflow the registers on the EVM. The overflow of registers made it difficult to tell
when our code had actually started working. In the end, we learned that extremely small
input signals are needed to keep the board from having overflow problems.
Another key factor in the math was number representation. Since the
board uses a two's complement number to represent the signal sample, some of the
constants needed to be changed. Specifically, the value for mu now needed to be greater
than one (not less than), but still close to one. From our experiments, we found that a
value between 1 and 10 worked best, and we choose to use 2 for our demonstrations
because it kept the output voice signal the most clear. The tradeoff was that the
background noise now had a bit of a more vibrant pinging to it.
Here the is the contaminated signal containing both noise nk and the desired signal
is a measure of .
The digital filter of the system is used to process the by producing, an estimation of
. An FIR digital filter is the single input single output system. The FIR Filter is used
here instead of IIR because of its simplicity and stability
The main objective in noise cancellation is to produce an optimum estimate of the noise
in the contaminated signal & hence an optimum estimates of the desired signal.The or
is feedback to Adaptive algorithm & performs two tasks:
1. Desired signal estimation
2. Adjustment of filter coefficients
6.1.3 Adaptive Algorithm
The Adaptive filter algorithm is used to adjust the digital filter coefficients to minimize
the error signal, according to some criterion e.g., in the Least Square sense. Thus taking
square & mean of error signal is
Last term in eq. (3) becomes zero because of un correlation of desired signal with noise &
noise estimate.
The first term in the above equation is estimated of signal power; the second one is the
total signal power while the last one is the noise power. If then is the exact replica of
, the output power contain only the signal power i.e., by adjusting Adaptive filter towards
the optimum position, the remnant noise power & hence the total output power are
minimized. The desired signal power remains unaffected by this adjustment since is
uncorrelated with . Thus:
This shows that minimizing the total power at the output of the canceller maximizes the
signal to noise ration of the output. Having exact estimate of the noise the last term
becomes zero & estimate of desired signal becomes equal to the desired signal. i.e., the
Out put of the canceller becomes noise free:
At this stage adaptive filter turns off (ideally) by setting its weights to zero. A number of
adaptive algorithms are being used like:
LMS
RLS
Kalman
We used LMS here in this system because of the following advantages:
More efficient because of easy computation & better storage capabilities
Numerically stable
6.1.3.1 Lms Adaptive Algorithm
Instead of computing noise weights in one go, like above the LMS coefficients are
adjusted from sample to sample in such a way as to minimize the MSE (mean square
error).
The LMS adaptive algorithm is based on the Steepest Descent algorithm, which updates
weight vectors sample to sample:
The gradient vector, the cross-correlation between the primary & the secondary inputs P
and the autocorrelation of the primary input, R, are related as
For instantaneous estimates of gradient vector, we can write as
Chapter4
ADAPTIVE SYSTEM
General Properties
From the above a second property for the adaptive system is that it must be non-linear.
By this we mean that the principle of superposition doesnot hold good. Certain forms fo
adaptive systems become linear systems when their adjustments are held constant after
adaptation. They may be called linear adaptive systems. They are useful in one way
because they are easier tho design than other forms of adaptive systems.
Pictured here is the general structure of an adaptive filter. The main points to be noted
here are
The functions are determined by you, the programmer. Examples commonly used are
LMS (Least Mean Squared), NLMS (Normed LMS), RMS (Root Mean Squared), and
ABC (just kidding). We will use LMS for this project.
The user will want an output. Depending on what the system is for, the output will be
either y(n), e(n), or the filter itself.
SYSTEM IDENTIFICATION
Fig A) This is a plot of the coefficients of our adaptive filter vs. time. You can see the
values converge to the unknown values. So now we know b(1)=1.65, b(2)=0.72,
b(3)=0.38. We have our system identified.
Fig B
Fig B) The first example had mu, the step size of our error correction, equal to 0.1. If we
make it a little larger, say 0.3, we get faster convergence as seen here. But it we have mu
too large, say 0.5, the system diverges.
Fig C
Fig C) If we have the noise turned up, the adaptive filter will oscillate more, but we can
still make out that it converges to an estimate of the B coefficients.
Fig D
D) We can also figure out any n-order FIR filter. Here's a 10th order filter.
ADAPTIVE INTERFERENCE CANCELLING
I have selected my problem for the project as follows. In a car we have the
audio system. There will be some noise coming from the engine when we try to play a
song. We can use an adaptive filter in order to reduce the noise. The system configuration
is shown in the figure 1.
In the figure S(k) is the speech signal, n(k) is the noise signal which
is coming from the engine vibrations, n'(k) is the reference signal that is being used to
reduce the noise, Sys(k), is the primary input to the filter that is the corrupt signal, H(z) is
the transfer function of the adaptive filter, Y(k), is the output of the adaptive filter and
c(k) is the output signal i.e., is the difference of the corrupt signal and the output of the
adaptive filter. The refernce input i.e., n'(k) is in someway correlated with the noise and is
uncorrelated with the original signal. If these conditions are violated, the adaptive filter
may cancel the signal, s(k) in place of (or in additon to) the noise or could fail to cancel
the noise. It can be proved that n(k) and n'(k) are correlated but n'(k) and s(k) are
uncorrelated from the derivation given in appendix [1].
NOISE CANCELLATION
We begin with two signals, the primary signal and the reference signal. The primary
signal contains both our desired voice signal and the noise signal from the car engine.
Primary: Noise + Voice
The reference signal is a tapped version of the noise in the primary signal, i.e.
it must be correlated to the noise that we are trying to eliminate. In the case that we are
trying to model, the primary signal may come from a microphone at the speaker's mouth
which picks up both the speech signal and a noise signal from the car engine. The
reference signal may come from another microphone that is placed away from the
speaker and closer to the car engine, so the reference noise will be similar to the noise in
primary but perhaps with a different phase and with some additional white noise added to
it.
Reference: Estimation of Noise
The LMS algotrithm updates the filter coefficients to minimize the error between
the primary signal and the filtered noise. In the process of pouring through some class
notes from ELEC 431, we found that it can be proven through some hard math that the
voice component of the primary signal is orthogonal to the reference noise. Thus the
minimum this error can be is just our desired voice signal.
Output: Voice
We then experimented with varying different parameters. It turns out that the output we
get is very, very sensitive to mu. Apparently there is a very precise method for finding the
most optimal mu, something to do with the eigenfuction of the correlation matrix between
the primary and reference signals, but we used an educated trial and error technique.
Basically we found that mu affects how fast a response we were able to get; a larger mu
gives a faster response, but with a mu that is too large, the result will blow up.
Result with Big mu
One question that is often asked is why we cannot simply subtract the reference noise
from the primary signal to obtain our desired voice signal. This method would work well
if the reference noise was exactly the same as the actual noise in primary.
Reference Noise = Actual Noise
However, if the reference noise is exactly 180 degrees out of phase the
with noise in primary, the noise will be doubled in the output. As can be seen in the
figures below, the output from the adaptive filter is still able to sucessfully cancel out the
noise.
Reference Noise 180 deg Out-of-Phase from Actual Noise
Matlab Introduction
Mat lab stands for matrix laboratory. It was written originally to provide easy access to
matrix software developed by LINPACK (linear system package) and EISPACK (Eigen
2. Algorithm development
3. Data acquisition
applications.
MATLAB
MATLAB
Programming language
Computation
Graphics External interface
Linear algebra
2-D graphics Interface with C
Signal processing
3-D graphics and
Quadrature
Color and lighting FORTRAN
Etc
Animation Programs
Tool boxes
Signal processing
Image processing
Control systems
Neural Networks
Communications
Robust control
Statistics
Development Environment.
This is the set of tools and facilities that help you use MATLAB functions and files.
Many of these tools are graphical user interfaces. It includes the MATLAB desktop and
Command Window, a command history, an editor and debugger, and browsers for
like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like
matrix inverse, matrix Eigen values, Bessel functions, and fast Fourier transforms.
This is a high-level matrix/array language with control flow statements, functions, data
"programming in the small" to rapidly create quick and dirty throw-away programs, and
Graphics.
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well
as annotating and printing these graphs. It includes high-level functions for two-
dimensional and three-dimensional data visualization, image processing, animation, and
presentation graphics. It also includes low-level functions that allow you to fully
This is a library that allows you to write C and Fortran programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking),
calling MATLAB as a computational engine, and for reading and writing MAT-files.
Starting MATLAB
on your Windows desktop. On UNIX platforms, start MATLAB by typing mat lab at the
operating system prompt. You can customize MATLAB startup. For example, you can
MATLAB Desktop
When you start MATLAB, the MATLAB desktop appears, containing tools (graphical
user interfaces) for managing files, variables, and applications associated with MATLAB.
The following illustration shows the default desktop. You can customize the arrangement
of tools and documents to suit your needs. For more information about the desktop tools .
Implementations
1. Arithmetic operations
Entering Matrices
The best way for you to get started with MATLAB is to learn how to handle
Start by entering Dürer’s matrix as a list of its elements. You only have to
A=
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
This matrix matches the numbers in the engraving. Once you have entered
You are probably already aware that the special properties of a magic square
have to do with the various ways of summing its elements. If you take the
sum along any row or column, or along either of the two main diagonals,
you will always get the same number. Let us verify that using MATLAB.
sum(A)
MATLAB replies with
ans =
34 34 34 34
When you do not specify an output variable, MATLAB uses the variable ans,
short for answer, to store the results of a calculation. You have computed a
row vector containing the sums of the columns of A. Sure enough, each of the
How about the row sums? MATLAB has a preference for working with the
columns of a matrix, so one way to get the row sums is to transpose the
matrix, compute the column sums of the transpose, and then transpose the
result. For an additional way that avoids the double transpose use the
MATLAB has two transpose operators. The apostrophe operator (e.g., A')
diagonal, and also changes the sign of the imaginary component of any
containing all real elements, the two operators return the same result.
So
A'
produces
ans =
16 5 9 4
3 10 6 15
2 11 7 14
13 8 12 1
and
sum(A')'
ans =
34
34
34
34
The sum of the elements on the main diagonal is obtained with the sum and
diag(A)
produces
ans =
16
10
and
sum(diag(A))
produces
ans =
34
The other diagonal, the so-called anti diagonal, is not so important
But a function originally intended for use in graphics, fliplr, flips a matrix
Sum (diag(fliplr(A)))
ans =
34
You have verified that the matrix in Dürer’s engraving is indeed a magic
Square and, in the process, have sampled a few MATLAB matrix operations.
Operators
+ Addition
- Subtraction
* Multiplication
/ Division
MATLAB documentation)
. ^ Power
Generating Matrices
Z = zeros(2,4)
Z=
0000
0000
F = 5*ones(3,3)
F=
555
555
555
N = fix(10*rand(1,10))
N=
9264874084
R = randn(4,4)
R=
M-Files
You can create your own matrices using M-files, which are text files containing
MATLAB code. Use the MATLAB Editor or another text editor to create a file
Containing the same statements you would type at the MATLAB command
A = [...
Store the file under the name magik.m. Then the statement
magik
reads the file and creates a variable, A, containing our example matrix.
Graph Components
The actual visual representation of the data is achieved with graphics objects
like lines and surfaces. These objects are drawn within the coordinate system
accommodate the range of the data. The actual data is stored as properties of
Plotting tools are attached to figures and create an environment for creating
Display the plotting tools from the View menu or by clicking the plotting tools
Use the Editor/Debugger to create and debug M-files, which are programs you
user interface for text editing, as well as for M-file debugging. To create or
edit an M-file use File > New or File > Open, or use the edit function.
program
************************************************************************
% removal of 50 hz noise (power line interference) from ecg signal using
% adaptive filtering
%creation of 50h noise signal
clear all
Fs = 1000;
N = 6000;
l=[0:999]';
i = [0 : N-1]';
p=ecg(500).';
p1=[p;p;p;p;p;p;p;p;p;p];
figure
plot(p1)
title('original ecg signal')
figure
plot(125*sin(2*pi*50*l/Fs))
title('noise signal')
%create the initial signal
k=1.2*sin(2*pi*50* i/Fs)
c=p1+k;
figure
plot(c)
title('signal after adding noise')
h = adaptfilt.lms(15,0.02);
y = filter(h,c,p1);
fvtool(h)
figure
plot(y)
title('signal after removal of noise')
simulation results:
% removal of 50 hz noise (power line interference) from ecg signal using
% iirnotch filter
clear all
Fs = 1000;
N = 6000;
%l=[0:999]';
i = [0 : N-1]';
p=ecg(500).';
p1=[p;p;p;p;p;p;p;p;p;p;p];
figure
plot(p1)
title('original ecg signal')
figure
%plot(3.25*sin(2*pi*50*l/Fs))
%title('noise signal')
k=1.2*sin(2*pi*50* i/Fs)
plot(k)
title('noise signal')
c=p1+k;
figure
plot(c)
title('ecg signal after addition of noise')
wo = 50/(1000/2); bw = wo/35;
[b,a] = iirnotch(wo,bw);
y = filter(b,a,c);
fvtool(b)
figure
plot(y)
title('signal after filtering');
Simulation results:
% removal of 50 hz noise (power line interference) from ecg signal using
% adaptive filtering algorithm
clear all
Fs = 1000;
N = 1000;
i = [0 : N-1]';
p=ecg(500).';
p1=[p;p];
figure
plot(p1)
title('original signal')
figure
plot(sin(pi*50*i/FS))
%create the initial signal
x =p1+ sin(2*pi*50* i/Fs)
figure
plot(x)
%create the reference signal of the adaptive filter
u =sin(2*pi*50* i/Fs);% sin(2*pi*60* i/Fs);
%compute the spectrum of the initial signal and the filtered signal
f = [0 : Fs/N : Fs - Fs/N]';
F = abs(fft(x));
E = abs(fft(e));
%plot
figure;
subplot(411) ;plot(x); title('initial signal');
subplot(412) ;plot(e); title('initial signal after filtering');
subplot(413) ;plot(f,F( 1:length( f)));title( 'spectrum of
initialsignal');
subplot(414) ;plot(f,E( 1:length( f)));title( 'spectrum of initialsignal
after filtering');
simulation results:
% removal of 50 hz noise (power line interference) and 0.5hz noise
(base line wandering from ecg signal using
% adaptive filtering algorithm
clear all
Fs = 1000;
N = 1000;
i = [0 : N-1]';
p=ecg(500).';
p1=[p;p];
figure
plot(p1)
%create the initial signal
x =p1+ sin(2*pi*0.5* i/Fs)+sin(2*pi*50* i/Fs) %+ 0.66*sin(2*pi*
280*i/Fs) + 0.59*sin(2*pi*60*i/Fs) + 0.5^0.5*randn( N,1);
figure
plot(x)
%create the reference signal of the adaptive filter
u =sin(2*pi*0.5* i/Fs)+sin(2*pi*50* i/Fs);% sin(2*pi*60* i/Fs);
%plot
figure;
subplot(411) ;plot(x); title('initial signal');
subplot(412) ;plot(e); title('initial signal after filtering');
***********************************************************
.
conclusion
BIBLIOGRSPHY
REFERENCES
Byron JP, He J, Hu S (2005). “ First International Conference on Neural
Interface and Control Proceedings, Wuhan, China. A Conceptual
Brain Machine Interface System, pp 112-116.
Cuiwei L, Chongxun Z, Changfen T (1995). Detection of ECG
Characteristic Points Using Wavelet Transform,” IEEE Trans on
Biomed Eng, 42(1): 21-28.
Gotman J (2002). “Automatic recognition of epileptic seizures in the
EEG” Electro encephalography and clinical neu. physiology 54, PP
530– 540.
Haykin S (1991). Adaptive Filter Theory' Prentice Hall,” London
Haykin S (1996). Neural Networks SP's Horizons' IEEE Signal
Processing Magazine,13(2): 24-29.
Latka M, Ziemowit (2002). Wavelet analysis of epileptic Spikes”.
Wroclaw university of Technology, Poland, Dec. 22, 2002.pp. 1-6.
Robert C (2002). "Electroencephalogram Processing using Neural
networks", Clinical Neurophysiology 113, pp. 694-701.
Selvan S, Srinivasan R (2001). Neural Networks-based Effecient
Adaptive Filtering Technique volume 82.