invertIfNecessary

PURPOSE ^

invertIfNecessary - Decides whether or not to invert the ECG signal

SYNOPSIS ^

function [ res ] = invertIfNecessary( rawEcg, fs, windowInSeconds )

DESCRIPTION ^

invertIfNecessary - Decides whether or not to invert the ECG signal
   Based on the analysis of a signal segment, we decide whether or
   not to invert the original signal.

   Input:
       rawEcg: raw ECG signal
       fs: sampling frequency
       windowInSeconds: Window of time on which we run the analysis
   Outputs:
       res: the final signal (equal to rawEcg or -rawEcg)

   Example:
       [ res ] = invertIfNecessary( ecgSig, 1000, 600 )

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ res ] = invertIfNecessary( rawEcg, fs, windowInSeconds )
0002 %invertIfNecessary - Decides whether or not to invert the ECG signal
0003 %   Based on the analysis of a signal segment, we decide whether or
0004 %   not to invert the original signal.
0005 %
0006 %   Input:
0007 %       rawEcg: raw ECG signal
0008 %       fs: sampling frequency
0009 %       windowInSeconds: Window of time on which we run the analysis
0010 %   Outputs:
0011 %       res: the final signal (equal to rawEcg or -rawEcg)
0012 %
0013 %   Example:
0014 %       [ res ] = invertIfNecessary( ecgSig, 1000, 600 )
0015 
0016 rawEcgSample = rawEcg(1:windowInSeconds*fs);
0017 windowSize = 200;
0018 
0019 % Normal Signal
0020 [ sig, detrended ] = preprocessingNew(rawEcgSample, fs);
0021 [ R_locs ] = kota(sig, detrended, fs);
0022 [ peakVal, meanVal, stdVal ] = getEnsembleInfo(detrended, R_locs, windowSize);
0023 
0024 
0025 % Inverted Signal
0026 invEcg = - rawEcgSample;
0027 [ sig, detrended ] = preprocessingNew(invEcg, fs);
0028 [ R_locs ] = kota(sig, detrended, fs);
0029 [ invPeakVal, invMeanVal, invStdVal ] = getEnsembleInfo(detrended, R_locs, windowSize);
0030 
0031 
0032 heightNormal = abs(peakVal - meanVal) / stdVal;
0033 heightInv = abs(invPeakVal - invMeanVal) / invStdVal;
0034 
0035 if(heightNormal > heightInv)
0036     res = rawEcg;
0037     return;
0038 else
0039     res = -rawEcg;
0040     return;
0041 end
0042 
0043     function [ ensemble_peak, ensemble_mean, ensemble_std ] = getEnsembleInfo(detrended_sig, R_locs, windowSize)
0044         avg = zeros(1,(2*windowSize+1));
0045         left = R_locs-windowSize;
0046         right = R_locs+windowSize;
0047         totalLength = length(R_locs);
0048         
0049         parfor i=1:length(R_locs)
0050             if(R_locs(i) < windowSize + 1)
0051                 continue;
0052             elseif(R_locs(i) > totalLength-windowSize)
0053                 continue;
0054             end
0055             complex = detrended_sig(left(i):right(i));
0056             avg = avg + complex;
0057         end
0058         ensemble_peak = max(avg);
0059         ensemble_mean = mean(avg);
0060         ensemble_std = std(avg);
0061     end
0062 
0063 end
0064

Generated on Thu 15-Mar-2018 13:51:08 by m2html © 2005