0% found this document useful (0 votes)
13 views24 pages

BSP AA2 - Removed

The document outlines the implementation of the Pan-Tompkins algorithm for QRS complex detection in ECG signals, detailing the steps of bandpass filtering, differentiation, squaring, moving window integration, adaptive thresholding, and QRS detection. It also discusses the detection of alpha-wave rhythms in EEG signals using autocorrelation and power spectral density methods, concluding with the application of matched filtering for spike detection in EEG analysis. Additionally, it introduces respiration rate calculation from PPG signals, emphasizing the modulation of PPG by respiratory activity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views24 pages

BSP AA2 - Removed

The document outlines the implementation of the Pan-Tompkins algorithm for QRS complex detection in ECG signals, detailing the steps of bandpass filtering, differentiation, squaring, moving window integration, adaptive thresholding, and QRS detection. It also discusses the detection of alpha-wave rhythms in EEG signals using autocorrelation and power spectral density methods, concluding with the application of matched filtering for spike detection in EEG analysis. Additionally, it introduces respiration rate calculation from PPG signals, emphasizing the modulation of PPG by respiratory activity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Biomedical Signal Processing - EC4061D

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:

y(n) = x(n)2 (4)

5. Moving Window Integration (MWI)


A moving window integrator is applied to smooth the signal and further enhance
QRS complexes:
1 N−1
y(n) = Σ
N x(n − i) (5)
i=0

where N is the window size (typically 150 ms).

6. Adaptive Thresholding
The algorithm dynamically adjusts detection thresholds using signal peak (SPKI)
and noise peak (NPKI) indicators:

SPKI = 0.125 × Peak + 0.875 × SPKI (6)


NPKI = 0.125 × Noise + 0.875 × NPKI (7)

The detection thresholds are updated as:

Th1 = N PKI + 0.25 × (SPKI − NPKI) (8)


Th2 = 0.5 × Th1 (9)

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

33 = movmean squared ECG window Length


34 = max( %
35

36 %%
37

38

39

40
Chinthapanti Gowtham reddy
Roll No: B210662EC

41

42 [ ide nt ifie d Peaks , pe akLocatio ns ] = findpe ak s( mwiSignal ,


’ Min Peak Distance ’, 0.4 * Fs);
43

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

58 %% PLOT 1: Original & B an dpa sse d ECG ( Single Figure )


59 figure ;
60 subplot (2 ,1 ,1);

61 plot( timeAxis , ecgSignal , ’k’, ’ Line Widt h ’, 1.2); % Black

line
62 title (’ Raw ECG Signal ’);

63 xlabel( ’ Time ( s)’);

64 yla bel(’ Am pli tude ( mV)’);

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)’);

71 yla bel(’ Am pli tude ( mV)’);

72 grid on;

73

74 %% PLOT 2: Differentiatio n , Squaring & MWI


75 figure ;
76 subplot (3 ,1 ,1);
77 plot( time Axis (1: end -1), diff erentiat ed ECG , ’g’,
’ Line Width ’, 1.2); % Green line
78 title (’ Differentiated ECG Signal ’);
79 xlabel( ’ Time ( s)’);
80 ylabel(’ Am plitude ’);
81 grid on;
82
Chinthapanti Gowtham reddy
Roll No: B210662EC

83

84

% Magenta
85 Squared ECG
86

87

88

89

90

91

% Cyan
92

93

94

95

96

97 %% PLOT Peak &


98

99 end %

100

101

%
102

%
103

%
104

105

106

107

108 grid on;


109

110 %% Display QRS Complex Count


111 fprintf(’ Total QRS Com plexes Detected : % d\ n’,
length ( qrsPeaks));
Chinthapanti Gowtham reddy
Roll No: B210662EC

Results
Output:
Chinthapanti Gowtham reddy
Roll No: B210662EC

Total QRS Complexes Detected: 3


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).

Alpha Rhythms in EEG


Alpha waves are oscillatory patterns in EEG signals typically found in the
8-13 Hz frequency range. These rhythms are most prominent in the occipital
and parietal regions of the brain and are associated with a relaxed but wakeful
state.
Alpha activity increases when:

• A person is awake but in a relaxed state with their eyes closed.


• The brain is in an idle state with minimal sensory input.

Alpha rhythms are suppressed when:

• A person opens their eyes.


• They engage in mental activity or attention-demanding tasks.

Since alpha waves are periodic, they can be detected using autocorrela-
tion to analyze periodicity and power spectral density (PSD) to measure
frequency power.

Autocorrelation of EEG Signals


Autocorrelation is a statistical technique used to measure the similarity between
an EEG signal and a delayed version of itself. It helps in identifying repeating
patterns such as alpha rhythms.
The discrete-time autocorrelation function is given by:
N−1
Σ
Rx(τ ) = x[n]x[n + τ ] (10)
n=0

where:
• Rx(τ ) is the autocorrelation function,
Chinthapanti Gowtham reddy
Roll No: B210662EC

• x[n] is the EEG signal at discrete time index n,


• τ is the time lag.
By examining peaks in the autocorrelation function, periodic alpha rhythms
can be detected.

Power Spectral Density (PSD)


The Power Spectral Density (PSD) of an EEG signal provides information about
the distribution of power across different frequency components. It is calculated
using the Fourier Transform of the autocorrelation function:

Σ
Sx(f ) = F{Rx(τ )} = Rx(τ )e−j2πfτ (11)
τ =−∞

where:

• Sx(f ) represents the power spectral density,

• F denotes the Fourier Transform,


• f is the frequency.

Detecting Alpha Waves using PSD


To identify alpha rhythms, we analyze the PSD and check for significant peaks
in the 8-13 Hz range. The common methods used to estimate PSD are:

1. Periodogram Method:

N −1 2
1 Σ
Px(f ) = x[n]e−j2πfn (12)
N
n=0

2. Welch’s Method, which improves accuracy by averaging multiple win-


dowed segments.

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

50 %% Compute Power PSD


51 =

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 1: Original EEG Signal

Figure 2: Bandpassed EEG Signal


Chinthapanti Gowtham reddy
Roll No: B210662EC

Figure 3: Autocorrelation

Figure 4: Power Spectral Density


 Detected Alpha Peak Frequency: 8.79 Hz
Chinthapanti Gowtham reddy
Roll No: B210662EC

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:

r(t) = s(t) + n(t) (13)


where:

• s(t) is the transmitted signal,


• n(t) is additive noise, often modeled as Gaussian noise.
The matched filter h(t) is designed to maximize the output SNR. The optimal
impulse response of the matched filter is given by:

h(t) = s(T − t) (14)


where T is the duration of the signal.

Matched Filter Output


The output of the matched filter is obtained by convolving the received signal
r(t) with h(t):
∫ ∞
y(t) = r(τ )h(t − τ )dτ (15)
−∞
Chinthapanti Gowtham reddy
Roll No: B210662EC
Using the matched filter property, this maximizes the detection of the known
signal s(t) at a specific time instant.

Matched Filter in Discrete Time


For a discrete-time signal x[n], the matched filter is implemented as a discrete-
time convolution:
N−1
Σ
y[n] = x[k]h[n − k] (16)
k=0

where h[n] is the time-reversed and conjugated version of s[n].

h[n] = s[N − 1 − n] (17)

Application in EEG Spike Detection


In EEG analysis, matched filtering can be used for spike detection by correlat-
ing the EEG signal with a known template of an epileptic spike. This enhances
the identification of characteristic waveforms in noisy EEG recordings.

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:

Figure 5: Original EEG Signal


Chinthapanti Gowtham reddy
Roll No: B210662EC

Figure 6: Matched Filter Output

Figure 7: Detected Spikes in EEG signal

 Number of Spikes Detected: 11


Chinthapanti Gowtham reddy
Roll No: B210662EC

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:

• Amplitude Modulation (AM) - Periodic variations in PPG amplitude.


• Baseline Wander (BW) - Slow fluctuations in the baseline due to res-
piration.
• Frequency Modulation (FM) - Variations in pulse intervals caused by
breathing.

By extracting these variations, the respiration rate (RR) can be esti-


mated.

Preprocessing of PPG Signal


The raw PPG signal contains noise and artifacts that need to be removed before
extracting respiratory information. The preprocessing steps include:
1. Bandpass Filtering: The respiratory frequency range is typically be-
tween 0.1 Hz and 0.5 Hz (6-30 breaths per minute). A bandpass filter
isolates this range:
xfiltered(t) = HBP(x(t)) (18)
where HBP represents the bandpass filter.
2. Baseline Drift Removal: A high-pass filter removes slow variations
unrelated to respiration.

Extraction of Respiratory Components


Three main features can be used to estimate respiration rate from PPG:

1. Amplitude Modulation (AM) Method The amplitude envelope of the


PPG signal is extracted to obtain respiratory-induced variations:

xamp(t) = max(xfiltered(t)) − min(xfiltered(t)) (19)

2. Baseline Wander (BW) Method A low-pass filter extracts the slow


respiratory trend:

xbw(t) = HLP(x(t)) (20)

3. Frequency Modulation (FM) Method Respiration affects heart rate


variability. The instantaneous frequency of PPG peaks is computed using the
Hilbert Transform.
Chinthapanti Gowtham reddy
Roll No: B210662EC

Computation of Respiration Rate


To determine the dominant breathing frequency, the Power Spectral Density
(PSD) is computed:

Sx(f ) = |F {xresp(t)}|2 (21)


where F represents the Fourier Transform. The respiration rate (RR) is
then calculated as:

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:

Figure 8: Original PPG Signal

Figure 9: Estimated Respiratory components of PPG signal


Chinthapanti Gowtham reddy
Roll No: B210662EC

Figure 10: Detected Respiration Peaks

You might also like