Report OFDM
Report OFDM
DESIGN PROBLEM-3
SUBMITTED TO:
Submitted By:
Here we are given with two ECG signal data in text file format from which we
are supposed to develop an algorithm ( in MATLAB environment ) to
estimate:-
The data given has 65000 samples with sampling rate 360 HZ.
fileID = fopen('ecg_1.txt','r');
formatSpec = '%f';
A = fscanf(fileID,formatSpec);
t=(0:1:(650000-1))/360;
figure(1)
plot(t(:),A(:))
xlabel('time(seconds)')
ylabel('Amplitude')
grid on
axis tight
title('ECG-1signal full plot')
Figure(a)
fileID = fopen('ecg_2.txt','r');
formatSpec = '%f';
B = fscanf(fileID,formatSpec);
t=(0:1:(650000-1))/360;
figure(1)
plot(t(:),B(:))
xlabel('time(seconds)')
ylabel('Amplitude')
grid on
axis tight
title('ECG-2 signal full plot')
Figure(b)
To better understand the signals see them in small interval of 1000 samples.
fileID = fopen('ecg_1.txt','r');
formatSpec = '%f';
A = fscanf(fileID,formatSpec);
t=(0:1:(650000-1))/360;
figure(1)
plot(t(1:1000),A(1:1000))
xlabel('time(seconds)')
ylabel('Amplitude')
grid on
axis tight
title('ECG-1 signal for 1000 samples')
Figure-1
fileID = fopen('ecg_2.txt','r');
formatSpec = '%f';
A = fscanf(fileID,formatSpec);
t=(0:1:(650000-1))/360;
figure(1)
plot(t(1:1000),A(1:1000))
xlabel('time(seconds)')
ylabel('Amplitude')
grid on
axis tight
title('ECG-2 signal for 1000 samples')
Figure-2
In order to understand data better, we need to know terms associated with different points in
individual ECG cycle, figure -3 shows all the points marked clearly namely the P, Q, R, S, T
and U points.
Peak point in the cycle is called R point, time difference between consecutive cycles can be
estimated by finding out time between two R points which is also called as R-R Interval.
Figure-3
Once R-R interval is determined we can calculate heart rate in beats per minute or BPM using
the formula mentioned below :-
Figure 4 shows first, difference and square of second difference for first
few samples of ecg1 and ecg2, we can see there are sharp peaks near R
peaks
Fig 4. Implementation of Algorithm in both the signals
We can clearly observe sharp peaks in squared double difference data, at R points, in order to
normalize the peaks, a novel method have been employed. We normalize first peak setting up
a suitable window and dividing it by max value, and then we assume a window of roughly
200 samples and divide by max value in that window, window is kept small so that, two ecg
cycles do not occur in a single window, to avoid false peaks being amplified, due to division
by max value, we keep a threshold, if max value in that window is less than that threshold, we
divide by a threshold value, so that false value is not amplified but rather suppressed, this way
we can normalize all correct squared double difference values to 1 or a value greater than one.
This threshold is chosen to be a value much greater than noise floor, but smaller than visually
observed squared double difference peak values. For ecg1 it was chosen to be 500 and 200 for
ecg2 upon observation. After this while looking for R index, in order to make exact detection,
upon finding a value greater than 0.98, max was searched in a window of 40 samples, to make
exact assumption. Fig. 5 shows implementation of this novel method for first 6500 samples of
both the ecg signals.
Fig 5. Normalized peaks of squared double difference
After determining R index corresponding to normalized value peaks, we have calculated R-R
interval and hence heart rates in beats per minute using formula stated before. We have
assumed that heart rates greater than 120 BPM and less than are 40BPM are false detection,
so have put a additional constraint to remove those.
Heart Rates
Using the methods stated above, we have determined the heart rates beat by beat for both ecg
files as shown in figure 6. We can see, ecg 1 has heart rates which vary slowly with some
abnormality at some points, which may be due to false detection or data itself, whereas we
observe heartrates are quite abnormal for ecg2 and vary quite abnormally beat by beat. We
have also shown change in heart rate beat by beat, which can be seen to be in a certain range
for most beats in ecg1, but not so in ecg2
Fig 6. Heart Rates and Heart Rate change for ecg1 and ecg2
Histograms, clustering heart rate into 50 bins for both signals have been shown in figure 7,
figure 8 shows histogram of heart rate change for both signals.
Fig 7. Histogram of Heart Rates for ecg1 and ecg2
We can observe that most common heart rate for ecg1 is between 74-75 BPS, and distribution
is even around it, with very few values of too high or too low heart rates, whereas in ecg2
most common heart-rate is as low as 50-51 BPS but significant mount of times its quite high
as well, and has a big distribution at different values suggesting very un-even heart beats.
Fig 8. Histogram of Heart Rates Changes for ecg1 and ecg2
We can observe that at the exact point of R-Peak, first difference is slightly negative or
slightly positive, and it remains negative till QRS envelope value is decreasing after R peak,
then again it becomes positive, after QRS interval ends, and similarly on the left side of peak,
value of first difference is positive for the duration of QRS envelope then it becomes
negative, so we have employed this observation to find QRS intervals.
After reaching index of the peak, we iterate after leaving two samples on either side till we
find negative values to right of the peak and, positive values to the left of the peak, then add
total no of samples, say total is m samples. So QRS interval will be given as
QRS = (1/Fs)*m
So using this method, QRS intervals are calculated and plotted in figure 11 for both the
signals.
QRS Intervals
Fig 11. QRS Estimated beat by beat for ecg1 and ecg2
we can observe that values, are quite uniform in ecg1, except for 2 discontinuities, which may
be due to wrong detection of index, i.e. algorithm is counting derivative of noise instead of
QRS. For ecg2 data we observe quite abnormality, and values fluctuating very frequently,
with many beats having too high or too low values.