kalmarulez
Newbie level 3
- Joined
- Apr 6, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,300
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
%**************************************************************************
% James Lamberg 28Apr05
% EE 5821 Biomedical Modeling
% Imports a .dat file containing two signals in PhysioNet format 212
% Outputs a .MAT matrix
% The matrix can then be used in the Wavelets toolbox.
% This program is based on rddata.m by Robert Tratnig.
% The algorithm was based on a program written by Klaus Rheinberger.
% 10May05 - Updated so output file name was how I wanted it
% 17 May 2005 - Added check that input contains exactly two signals -- GBM
%**************************************************************************
clc; clear all; close all;
%**************************************************************************
% Get Data & User Inputs
%**************************************************************************
PATH = input('Path Where Data Is Stored, Else Leave Blank = ','s');
FILE = input('ECG File Name = ','s'); % Input String Filename
HEADERFILE = strcat(FILE,'.hea'); % Header In TXT Format
ATRFILE = strcat(FILE,'.atr'); % Attributes In Binary Format
DATAFILE = strcat(FILE,'.dat'); % ECG Data File
SAMPLESTART = input('ECG Start Time = ','s');
SAMPLEEND = input('ECG End Time = ','s');
SAMPLESTART_1 = str2num(SAMPLESTART); % The Start Time In Seconds
SAMPLEEND_1 = str2num(SAMPLEEND); % The End Time In Seconds
%**************************************************************************
% Load Header Data
%**************************************************************************
% clear A;
info = wfdbdesc(FILE,false);
sfreq = info.samplingFrequency; % Sample Rate Of Data
SAMPLESTART_2 = sfreq * SAMPLESTART_1; % Samples/Second * Seconds
SAMPLEEND_2 = sfreq * SAMPLEEND_1; % Samples/Second * Seconds
nosig = length(info.groups.signals); % Number Of Signals
if nosig ~= 2
error('Error: Input must have exactly 2 signals');
end;
for k = 1:nosig
dformat(k) = info.groups.storageFormat; % Format - 212 Only
gain(k) = info.groups.signals(k).gain; % Integers Per mV
%bitres(k) = A(3); % Bit Resolution
zerovalue(k) = info.groups.signals(k).adcZero; % Value Of ECG Zero Point
firstvalue(k) = info.groups.signals(k).initVal; % First Value Of Signal
end;
%**************************************************************************
% Fix Minor Data Problems
%**************************************************************************
if SAMPLESTART_2 == 0 % If User Starts At Zero
SAMPLESTART_2 = 1; % We Start At The First Entry
end;
if SAMPLEEND_1 == 0 % If User Wants To End At Zero
error('Error: Results In No ECG Data');
end;
if SAMPLESTART_1 < 0 | SAMPLEEND_1 < 0 % If User Enters Negative Time
error('Error: ECG Start & End Time Must Be Positive');
end;
if SAMPLESTART_1 > SAMPLEEND_1 % If User Sets End Before Start
error('Error: ECG Start Time Should Be Before ECG End Time');
end;
switch nosig
case 2
TIME = (0:(SAMPLEEND_2 - 1))/sfreq;
case 1
TIME = (0:2*(SAMPLEEND_2)-1)/sfreq;
otherwise
disp('Error: Sorting Algorithm For > 2 Signals Not Programmed Yet!');
end;
%**************************************************************************
% WFDB
%**************************************************************************
annotation = rdann(FILE,'atr', 'start', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);
signal = rdsamp(FILE, 'begin', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);
ECG_1 = (signal(:,2)- zerovalue(1))./gain(1);
ECG_2 = (signal(:,3)- zerovalue(2))./gain(2);
for i = 1 : length(annotation)
ATRTIMED(i) = annotation(i).timeInSeconds;
end
Time_Adjusted = TIME(SAMPLESTART_2 : SAMPLEEND_2);
%**************************************************************************
% Display Data
%**************************************************************************
figure(1); clf, box on, hold on
plot(Time_Adjusted, ECG_1,'r');
if nosig == 2
plot(Time_Adjusted, ECG_2,'b');
end;
for k = 1:length(ATRTIMED)
text(ATRTIMED(k),0, annotation(k).typeMnemonic);
end;
xlim([Time_Adjusted(1), Time_Adjusted(end)]);
xlabel('Time (Seconds)'); ylabel('Voltage (mV)');
string = ['ECG Signal ',DATAFILE];
title(string);
fprintf(1,'\\n$> DISPLAYING DATA FINISHED \n');
%**************************************************************************
% Output Data File Into Current Working Directory
%**************************************************************************
save(strcat(FILE,'_ECG_',SAMPLESTART,'_',SAMPLEEND) ...
, 'ECG_1' , 'ECG_2' , 'Time_Adjusted');
fprintf(1,'\\n$> ALL FINISHED \n');
%**************************************************************************
% End Of Code
%**************************************************************************
annotation = rdann(FILE,'atr', 'start', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);
signal = rdsamp(FILE, 'begin', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);
%**************************************************************************
% Get Data & User Inputs
%**************************************************************************
FILE = input('File Name = ','s'); % Input String Filename
HEADERFILE = strcat(FILE,'.hea'); % Header In TXT Format
ATRFILE = strcat(FILE,'.atr'); % Attributes In Binary Format
DATAFILE = strcat(FILE,'.dat'); % ECG Data File
SAMPLESTART = input('ECG Start Time = ','s');
SAMPLEEND = input('ECG End Time = ','s');
SAMPLESTART_1 = str2num(SAMPLESTART); % The Start Time In Seconds
SAMPLEEND_1 = str2num(SAMPLEEND); % The End Time In Seconds
%**************************************************************************
% Load Header Data
%**************************************************************************
fprintf(1,'\\n$> WORKING ON %s ...\n', HEADERFILE);
fid1 = fopen('100.hea.txt','r');
z = fgetl(fid1);