-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdgeEffect.m
More file actions
51 lines (33 loc) · 1.43 KB
/
EdgeEffect.m
File metadata and controls
51 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
39
40
41
42
43
44
45
46
47
48
49
50
51
%% Edge effect using resample
% This script shows the edge effect due to resampling operation in signals.
% In addition, it presents two alternatives to fix it.
% Author: MSc. David Castro Piñol
clear; close all; clc;
load ecgSignal;
Fs = 250;
newFs = 360;
n = 0:length(ecgSignal)-1;
t1 = n*1/Fs;
%% Problem Edge Effects
signalResampled = resample(ecgSignal,newFs,Fs);
n2 = 0:length(signalResampled)-1;
t2 = n2*1/newFs;
figure; plot(t1,ecgSignal,'b',t2,signalResampled,'r'); ylim([-4.7 -2.5]);
xlabel('Time (s)'); ylabel('Signal'); legend('Original','Resampled', ...
'Location','NorthWest');
%% First Alternative: mean normalization
ecgSignalMeanOff = ecgSignal - mean(ecgSignal);
signalResampled = resample(ecgSignalMeanOff,newFs,Fs);
n2 = 0:length(signalResampled)-1;
t2 = n2*1/newFs;
figure; plot(t1,ecgSignalMeanOff,'bo-',t2,signalResampled,'r*-');
xlabel('Time (s)'); ylabel('Signal'); legend('Zero Mean','Resampled', ...
'Location','NorthWest');
%% Second Alternative: Flip and shift
L = ceil(length(ecgSignal)*newFs/Fs);
flipedSignal = [flip(ecgSignal);ecgSignal;flip(ecgSignal)];
signalResampled = resample(flipedSignal,newFs,Fs);
figure; subplot(211);plot(signalResampled,'b'); title('Flip and Shift ECG signal');
hold on; plot(L:2*L-1,signalResampled(L:2*L-1),'r');
cutSignal = signalResampled(L:2*L-1);
subplot(212);plot(t2,cutSignal,'r'); title('Cutting signal');