BSP AA2 - Removed
BSP AA2 - Removed
Assignment-II
Chinthapanti Gowtham reddy
B210662EC
Question 1
Detect QRS complex using Pan Tompkins Algorithm and display all
the intermediate steps.
Introduction
The Pan-Tompkins algorithm is a widely used technique for detecting QRS
complexes in an electrocardiogram (ECG) signal. It is based on a series of pre-
processing steps that enhance QRS complexes while suppressing noise, baseline
drift, and other artifacts.
1. Bandpass Filtering
Low-pass Filter Transfer Function:
1 − 2z−6 + z−12
HLP (z) = (1)
1 − 2z−1 + z−2
This filter attenuates components with frequencies higher than the cutoff, smooth-
ing the ECG signal while retaining essential features.
High-pass Filter Transfer Function:
−1 + 32z16 − 32z−16 + z−31
HHP (z) = (2)
32(1 − z−1)
This filter removes baseline wander and low-frequency noise, retaining higher-
frequency components crucial for detecting rapid changes like QRS complexes.
2. Differentiation
The ECG signal is differentiated to highlight rapid changes, making the QRS
complex more prominent:
1
y(n) = [−x(n − 2) − 2x(n − 1) + 2x(n + 1) + x(n + 2)] (3)
8
1
Chinthapanti Gowtham reddy
Roll No: B210662EC
4. Squaring
The output is squared to amplify large variations and suppress small changes:
6. Adaptive Thresholding
The algorithm dynamically adjusts detection thresholds using signal peak (SPKI)
and noise peak (NPKI) indicators:
7. QRS Detection
A peak is classified as a QRS complex if it exceeds the adaptive threshold
Th1. The algorithm ensures robustness by enforcing a minimum peak separation
(typically 200–600 ms).
Conclusion
The Pan-Tompkins algorithm effectively detects QRS complexes in real-time
using signal processing techniques. Its adaptive thresholding mechanism ensures
reliable performance across different ECG datasets.
Chinthapanti Gowtham reddy
Roll No: B210662EC
MATLAB Code
1
5 %% ECG
6 One BSP
%
7 %
8
9 %
10
11
12
13
14
15
16 end
17
18 = %
19
20 %% Low &
21 %
22 PassDenom %
23 PassDenom
24
25 = 1 32 32 %
26
27 ECG PassDenom
ECG_Low % ECG
28
29 %% and Window
30
31
32
36 %%
37
38
39
40
Chinthapanti Gowtham reddy
Roll No: B210662EC
41
44 qrsPeaks = [];
45 for idx = 1: length ( ident ified Peaks )
46 peakV alue = identif ied Peak s ( idx);
47 peak Position = peak Lo c atio ns ( idx);
48 if peakV alue > thr esho ld_ 1
49 signalPe ak Index = 0.125 * pe akValue + 0.875 *
signalPe ak Index ;
50 qrsPeaks = [ qrsPeaks; peakPosition ]; %# ok <AGROW >
51 else
52 noise PeakI ndex = 0.125 * peakValue + 0.875 *
noise PeakIndex ;
53 end
54 thre sho ld_ 1 = noise P eakIndex + 0.25 * ( signalPeakIndex
- noise P eakI nd ex );
55 thre sho ld_ 2 = 0.5 * th re sho ld_ 1 ;
56 end
57
line
62 title (’ Raw ECG Signal ’);
65 grid on;
66
67 subplot (2 ,1 ,2);
68 plot( timeAxis , filtered ECG , ’b’, ’ Line Width ’, 1.2); % Blue
line
69 title (’ Band pa ssed ECG Signal ( After Low & High Pass
Filtering )’);
70 xlabel( ’ Time ( s)’);
72 grid on;
73
83
84
% Magenta
85 Squared ECG
86
87
88
89
90
91
% Cyan
92
93
94
95
96
99 end %
100
101
%
102
%
103
%
104
105
106
107
Results
Output:
Chinthapanti Gowtham reddy
Roll No: B210662EC
QUESTION 2a:
Detect alpha-wave rhythms present in EEG waveform
Introduction
Electroencephalography (EEG) is a technique used to record electrical activity
in the brain. It captures signals generated by neuronal oscillations, which can
be analyzed in both the time and frequency domains. One of the important
components of EEG analysis is the detection of alpha rhythms, which are
associated with wakeful relaxation.
This document discusses alpha rhythms and two fundamental signal process-
ing techniques used for EEG analysis: autocorrelation and power spectral
density (PSD).
Since alpha waves are periodic, they can be detected using autocorrela-
tion to analyze periodicity and power spectral density (PSD) to measure
frequency power.
where:
• Rx(τ ) is the autocorrelation function,
Chinthapanti Gowtham reddy
Roll No: B210662EC
where:
1. Periodogram Method:
N −1 2
1 Σ
Px(f ) = x[n]e−j2πfn (12)
N
n=0
Conclusion
Alpha rhythms are a key component of EEG signals, observed during relaxed
wakefulness. They can be analyzed using autocorrelation to study periodic-
ity and Power Spectral Density (PSD) to determine their frequency content.
These methods help in understanding brain states and diagnosing neurological
conditions.
Chinthapanti Gowtham reddy
Roll No: B210662EC
MATLAB Code
1
5 %% Load EEG
6 %
7 %
8 %
9
10
11 % EEG
12
13 %
14
15
16
17
18
19 %%
20
21
22
23
24
25 % EEG waves
26
27 %
EEG
28
29 %
30
31
32
33
34
35
36
37 %% Compute Autocorrelation
38
39
40
41
42
Chinthapanti Gowtham reddy
Roll No: B210662EC
43
44
45
46
47
48 2 % Focus on
49
52
53 % PSD
54
55
56
57
58
59
60 % Show
61
62 %%
63 & %
64
%
65 %
66 %
67
68 %
69
70
71
72
73
Chinthapanti Gowtham reddy
Roll No: B210662EC
Output:
Figure 3: Autocorrelation
Question 2b:
Introduction
A matched filter is an optimal linear filter designed to maximize the signal-
to-noise ratio (SNR) of a signal in the presence of noise. It is widely used in
signal processing applications, including EEG signal analysis, radar, sonar,
and communications. The fundamental principle of a matched filter is that it
correlates a received signal with a known template (or reference signal), thereby
enhancing the detection of specific signal patterns.
Mathematical Formulation
The matched filter is derived based on the assumption that the received signal
consists of a transmitted signal corrupted by additive white Gaussian noise
(AWGN). Given a transmitted signal s(t), the received signal r(t) is:
Conclusion
Matched filtering is a powerful technique for detecting signals embedded in
noise. By maximizing the SNR, it enhances the detection of specific waveform
patterns, making it a widely used tool in signal processing applications such as
EEG analysis and radar signal detection.
Chinthapanti Gowtham reddy
Roll No: B210662EC
MATLAB Code
1
5 %% Load EEG
6
%
7 %
8
10 %
11
12 %
13 Raw EEG
14
15
16
17
18 %%
19 %
20 %
21 %
22
%
23
24 %%
25
26
27 %
28
29
30
31
32
33
34
35 %%
36 %
37
38
Chinthapanti Gowtham reddy
Roll No: B210662EC
39 %
40
41 % EEG
42
43
44
45
46
47
48
49
50
51 %% Number
52 Number %
Output:
Question 3:
Respiration Rate calculation from PPG signal
Introduction
Photoplethysmography (PPG) is a non-invasive technique that measures blood
volume changes in microvascular tissue using an optical sensor. While primarily
used for heart rate monitoring, PPG also contains valuable information about
respiratory activity.
Respiration modulates the PPG signal through:
RR = fresp × 60 (22)
where fresp is the peak frequency in the 0.1-0.5 Hz range.
Conclusion
By applying bandpass filtering, feature extraction, and spectral analysis, we
can accurately estimate respiration rate from the PPG signal. This method is
valuable for non-invasive respiratory monitoring in wearable health devices,
clinical monitoring, and fitness tracking.
Chinthapanti Gowtham reddy
Roll No: B210662EC
MATLAB Code
1
5 %% PPG
6
%
7
8 %
9
10
11 % PPG
12 Names =
13
14
15 %
16 %
17
18 %
19
20 %
21
22
23
24
25
26 %%
Component
27 %
28 %
min
29
30 %
31
32
Chinthapanti Gowtham reddy
Roll No: B210662EC
33 %
34
35
36 % Component
37
38
39
40
41
42
43
44 %%
45 %
46
47
48 %
49
50
51 end
52
53 %
54
55
56
57
58
59
60
61
62
63
64 %%
65 %
66
67
68 %
69
Chinthapanti Gowtham reddy
Roll No: B210662EC
Output: