Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help regarding an error in Matlab

Status
Not open for further replies.

kalmarulez

Newbie level 3
Newbie level 3
Joined
Apr 6, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,300
Hello !

I would like to use this, to convert a Physionet file so i can use it to analyze more ecg signals. My problem is that I get this error when running the Physionet_ECG_Exporter_2.m file

Any idea how could I fix it ?

Any help is appriciated,

Thanks in advance.
 

Attachments

  • error.jpg
    error.jpg
    66.3 KB · Views: 113

fgetl is a built in function to read line from file, so it should work.Try to write "help fgetl" in Matlab window, Matlab should show you to description of that method. If not, maybe You have some other function that has the same name. Then try to change Matlab directory.
However it is much better to use Physionet tools to read their ECG signals (any format - 212, 16b etc). It is much easier.
https://physionet.org/physiotools/matlab/wfdb-app-matlab/

rdsamp - read signal files
rdann - read annotations etc.
 

I know that, but i'm using this converter because it generates an ecg_xy.m file that I can use with this . I'm not so good in matlab to rewrite that code to work with Physionet generated files.
 

OK!
So instal the WFDB toolbox and try this :
Code:
%**************************************************************************
% 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
%**************************************************************************

but take a closer look at this part:

Code:
annotation = rdann(FILE,'atr', 'start', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);
signal = rdsamp(FILE, 'begin', ['00:00:' SAMPLESTART], 'stop', ['00:00:' SAMPLEEND]);

it's a dummy solution. You have to convert time in seconds from the input to the MIT time format HH:MM:SS
Right now it works only for signals started from first minute and anding in the first minute i.e. from 00:00 : xx to 00:00:yy
 
Thanks for the help but I figured it out with another solution. I looked up how fopen works, because my fid1 variable was getting -1 every time. So I deleted the part where it was wasking for the PATH and simply added the files to my work directory . Now it looks like this
Code:
%**************************************************************************
% 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);

And it works , my license work at the university might be just saved :D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top