Powerline noise elimination MATLAB tutorial series (Part 2.2) - - PowerPoint PPT Presentation

powerline noise elimination
SMART_READER_LITE
LIVE PREVIEW

Powerline noise elimination MATLAB tutorial series (Part 2.2) - - PowerPoint PPT Presentation

Powerline noise elimination MATLAB tutorial series (Part 2.2) Pouyan Ebrahimbabaie Laboratory for Signal and Image Exploitation (INTELSIG) Dept. of Electrical Engineering and Computer Science University of Lige Lige, Belgium Applied


slide-1
SLIDE 1

Powerline noise elimination

Pouyan Ebrahimbabaie Laboratory for Signal and Image Exploitation (INTELSIG)

  • Dept. of Electrical Engineering and Computer Science

University of Liège Liège, Belgium Applied digital signal processing (ELEN0071-1) 1 April 2020

MATLAB tutorial series (Part 2.2)

slide-2
SLIDE 2

Motivation

Signal measured in an ideal environment G x signal (V) Time (s)

slide-3
SLIDE 3

Motivation

Signal measured in a real environment G x (signal + Noise) (V) Time (s)

slide-4
SLIDE 4

Human body as an antenna 50Hz noise exists !

slide-5
SLIDE 5

Electrocardiogram (ECG)

Clean ECG ECG Time (s)

slide-6
SLIDE 6

Electrocardiogram (ECG)

ECG measured in a noisy environment ECG + Noise Time (s)

slide-7
SLIDE 7

Powerline noise elimination

  • Step 1: plot the signal
  • find the sampling period (Ts)
  • find the ending time (Tmax)
  • find the length of the signal (N)
  • Step 2: plot one-sided magnitude spectrum
  • use fft to plot magnitude spectrum
  • Step 3: identify the noise frequencies
  • Step 4: filter all undesired frequency components
  • here we used Notch filter (i.e. Notching)
  • Step 5: plot the results
  • Plot the original and filtered signals together
slide-8
SLIDE 8

Powerline noise elimination

  • Step 1: plot the signal
  • find the sampling period (Ts)
  • find the ending time (Tmax)
  • find the length of the signal (N)
  • Step 2: plot one-sided magnitude spectrum
  • use fft to plot magnitude spectrum
  • Step 3: identify the noise frequencies
  • Step 4: filter all undesired frequency components
  • here we used Notch filter (i.e. Notching)
  • Step 5: plot the results
  • Plot the original and filtered signals together
slide-9
SLIDE 9

Powerline noise elimination

  • Step 1: plot the signal
  • find the sampling period (Ts)
  • find the ending time (Tmax)
  • find the length of the signal (N)
  • Step 2: plot one-sided magnitude spectrum
  • use fft to plot magnitude spectrum
  • Step 3: identify the noise frequencies
  • Step 4: filter all undesired frequency components
  • here we used Notch filter (i.e. Notching)
  • Step 5: plot the results
  • Plot the original and filtered signals together
slide-10
SLIDE 10

Powerline noise elimination

  • Step 1: plot the signal
  • find the sampling period (Ts)
  • find the ending time (Tmax)
  • find the length of the signal (N)
  • Step 2: plot one-sided magnitude spectrum
  • use fft to plot magnitude spectrum
  • Step 3: identify the noise frequencies
  • Step 4: filter out undesired frequency components
  • here we used Notch filter (i.e. Notching)
  • Step 5: plot the results
  • Plot the original and filtered signals together
slide-11
SLIDE 11

Powerline noise elimination

  • Step 1: plot the signal
  • find the sampling period (Ts)
  • find the ending time (Tmax)
  • find the length of the signal (N)
  • Step 2: plot one-sided magnitude spectrum
  • use fft to plot magnitude spectrum
  • Step 3: identify the noise frequencies
  • Step 4: filter out undesired frequency components
  • here we used Notch filter (i.e. Notching)
  • Step 5: plot the results
  • Plot the original and filtered signals together
slide-12
SLIDE 12

Step 1: plot the signal % Load ecg signal from .mat file load('TNS_2_1_2018_example1.mat','ecg') % Fs is given Fs=250; % Ts sampling period Ts=1/Fs; % Length of the signal N=length(ecg); % Ending time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-13
SLIDE 13

Step 1: plot the signal % Load ecg signal from .mat file load('TNS_2_1_2018_example1.mat','ecg') % Fs is given Fs=250; % Ts sampling period Ts=1/Fs; % Length of the signal N=length(ecg); % Ending time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-14
SLIDE 14

Step 1: plot the signal % Load ecg signal from .mat file load('TNS_2_1_2018_example1.mat','ecg') % Fs is given Fs=250; % Ts sampling period Ts=1/Fs; % Length of the signal N=length(ecg); % Ending time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-15
SLIDE 15

Step 1: plot the signal % Load ecg signal from .mat file load('TNS_2_1_2018_example1.mat','ecg') % Fs is given Fs=250; % Ts sampling period Ts=1/Fs; % Length of the signal N=length(ecg); % Ending time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-16
SLIDE 16

Step 1: plot the signal % Plot the original signal figure(1) plot(t,ecg) xlabel('Time (s)') title('ECG + noise')

slide-17
SLIDE 17

Step 2: plot one-sided magnitude spectrum % Compute fft ECG=fft(ecg); % Take abs and scale it ECG2=abs(ECG/N); % Pick the first half ECG1=ECG2(1:N/2+1); % Multiply by 2 (except the DC part), to compenseate % the removed side from the spectrum. ECG1(2:end-1) = 2*ECG1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-18
SLIDE 18

Step 2: plot one-sided magnitude spectrum % Compute fft ECG=fft(ecg); % Take abs and scale it ECG2=abs(ECG/N); % Pick the first half ECG1=ECG2(1:N/2+1); % Multiply by 2 (except the DC part), to compenseate % the removed side from the spectrum. ECG1(2:end-1) = 2*ECG1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-19
SLIDE 19

Step 2: plot one-sided magnitude spectrum % Compute fft ECG=fft(ecg); % Take abs and scale it ECG2=abs(ECG/N); % Pick the first half ECG1=ECG2(1:N/2+1); % Multiply by 2 (except the DC part), to compenseate % the removed side from the spectrum. ECG1(2:end-1) = 2*ECG1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-20
SLIDE 20

Step 2: plot one-sided magnitude spectrum % Compute fft ECG=fft(ecg); % Take abs and scale it ECG2=abs(ECG/N); % Pick the first half ECG1=ECG2(1:N/2+1); % Multiply by 2 (except the DC part), to compenseate % the removed side from the spectrum. ECG1(2:end-1) = 2*ECG1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-21
SLIDE 21

Step 2: plot one-sided magnitude spectrum % Compute fft ECG=fft(ecg); % Take abs and scale it ECG2=abs(ECG/N); % Pick the first half ECG1=ECG2(1:N/2+1); % Multiply by 2 (except the DC part), to compenseate % the removed side from the spectrum. ECG1(2:end-1) = 2*ECG1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-22
SLIDE 22

Step 2: plot one-sided magnitude spectrum % Plot single-sided spectrum figure(2) plot(F,ECG1,'LineWidth',2.5) title('Single-Sided Amplitude Spectrum') xlabel('f (Hz)');

slide-23
SLIDE 23

Step 3: identify the noise frequencies

Just take a look to the single-sided magnitude spectrum and you will see …

slide-24
SLIDE 24

Notch filter for dummies Apps

slide-25
SLIDE 25

Notch filter for dummies Filter designer

slide-26
SLIDE 26

Notch filter for dummies Close

slide-27
SLIDE 27

Notch filter for dummies

slide-28
SLIDE 28

Notch filter for dummies Notching

slide-29
SLIDE 29

Notch filter for dummies Single notch

slide-30
SLIDE 30

Notch filter for dummies Hz

slide-31
SLIDE 31

Notch filter for dummies Sampling frequency

slide-32
SLIDE 32

Notch filter for dummies Notch frequency

slide-33
SLIDE 33

Notch filter for dummies sharpness

slide-34
SLIDE 34

Notch filter for dummies Lets go !

slide-35
SLIDE 35

Notch filter for dummies Single-sided magnitude spectrum

slide-36
SLIDE 36

Notch filter for dummies Pole and zeros

slide-37
SLIDE 37

Notch filter for dummies Export …

slide-38
SLIDE 38

Notch filter for dummies Export to workspace

slide-39
SLIDE 39

Notch filter for dummies Export as objects

slide-40
SLIDE 40

Notch filter for dummies Choose a name for your filter

slide-41
SLIDE 41

Notch filter for dummies Export

slide-42
SLIDE 42

Notch filter for dummies Filter object

slide-43
SLIDE 43

Notch filter for dummies %You can save your filter to your current folder >> save Notch50 Notch50

slide-44
SLIDE 44

Notch filter for dummies % You can save your filter to your current folder >> save Notch50 Notch50 % Now you can load it whenever you want >> load Notch50

slide-45
SLIDE 45

Notch filter for dummies % You can save your filter to your current folder >> save Notch50 Notch50 % Now you can load it whenever you want >> load Notch50 % You can use filter object directly >> y=filter(Notch50,x)

slide-46
SLIDE 46

Step 4: filter out undesired frequency components % load the filter object load Notch50; % removing the noise pure_ecg=filter(Notch50,ecg);

slide-47
SLIDE 47

Step 5: plot the results figure(3) plot(t,pure_ecg,'LineWidth',2); title('without noise') xlabel('time (s)') ylabel('amplitude') % Zoom in figure(4) plot(t(500:length(t)/6),ecg(500:length(t)/6),… 'LineWidth',2.5); title('Noisy and without noise') xlabel('time') ylabel('amplitude') hold on plot(t(500:length(t)/6),pure_ecg(500:length(t)/6),… 'LineWidth',2.5)

slide-48
SLIDE 48

Open filter visualization tool

MATLAB: fvtool(b,a)

  • r

fvetool(object)

  • r

slide-49
SLIDE 49

Useful links

  • https://www.youtube.com/watch?v=utrb6DN-Pqc
  • https://www.youtube.com/watch?v=aZ9fnLzPIWo
  • https://nl.mathworks.com/help/signal/ug/getting-

started-with-filter-designer.html