Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
j-ferretti committed Jun 15, 2017
1 parent 2c5393b commit 171a587
Show file tree
Hide file tree
Showing 66 changed files with 16,259 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
**/Backup/
**/codegentemp/
**/Generated_Source/
**/CortexM3/
**/Export/
*.cywrk.*
*.rpt
*.svd
*.html
*.cyprj.*
*.mat
*.txt

# For PCBs designed using KiCad: http://www.kicad-pcb.org/

# Temporary files
*.000
*.bak
*.bck
*.kicad_pcb-bak
*~
_autosave-*
*.tmp

# Netlist files (exported from Eeschema)
*.net

# Autorouter files (exported from Pcbnew)
.dsn

# Exported BOM files
*.xml
*.csv

# Cache and Autosave
*cache*
*autosave*
Binary file added Abstract.pdf
Binary file not shown.
39 changes: 39 additions & 0 deletions Matlab scripts/OAED_ContinuousPlot.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function [y] = OAED_ContinuousPlot(s1)
fh = figure;
lh = animatedline;
n = 0;
x = 0;

lh.Color = 'red';
lh.LineWidth = 0.1;

fwrite(s1,'C');

try
while(isvalid(fh))
while(s1.BytesAvailable == 0)
end

t = tic;
data = fread(s1,s1.BytesAvailable);
l = length(data);
y(1 : floor(l/2) ) = byte2word(data);
n = n + l/2;
x = x(end) + (1:length(y))/4000;
[xx,yy] = getpoints(lh);
if(length(xx)>50000)
clearpoints(lh);
addpoints(lh,[xx(end-4000:end) x], [yy(end-4000:end) y]);
else
addpoints(lh,x,y)
end
xlim([ x(end)-1 x(end)]);
drawnow limitrate
toc(t)
end
fwrite(s1,'C');
catch
fwrite(s1,'C');
end

end
53 changes: 53 additions & 0 deletions Matlab scripts/OAED_ECGanalysis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function [SCA, results, values, ecgf] = OAED_ECGanalysis(dat_list, n, suppress_plot)
%% Default parameters
if(nargin == 1)
n = size(dat_list, 1);
end
if(nargin < 3)
suppress_plot = false;
end

%% Loop
for k = 1:n
time = tic;
%% Load next signal
disp([num2str(toc(time)) ' : Loading ' dat_list(k).name]);
[ecg, fs, te] = rdsamp(dat_list(k).name, 1);
ecg = ecg';
te = te';
disp([num2str(toc(time)) ' : Loaded']);

%% apply biquad iir filter
disp([num2str(toc(time)) ' : Filtering']);
[ecgf] = OAED_FiltECG(ecg, fs, 3, 40);

%% Perform rhythm evaluation
disp([num2str(toc(time)) ' : Evaluating rhythm']);
t = tic;
[SCA, results, values] = OAED_RhythmEvaluation(ecgf, fs,...
~suppress_plot, ~suppress_plot);
exectime = toc(t);
disp([num2str(toc(time)) ' : Done']);

%% Display numeric result
disp([num2str(toc(time)) ' : Results']);
disp(['Total execution time : ' num2str(toc(time))]);
disp(['TCI : ' num2str(sum(SCA(1,:)))]);
disp(['VF filter : ' num2str(sum(SCA(2,:)))]);
disp(['TCSC : ' num2str(sum(SCA(3,:)))]);
disp(['PSR : ' num2str(sum(SCA(4,:)))]);
disp(['HILB : ' num2str(sum(SCA(5,:)))]);
disp(['SCA evauation'])
disp(['At least 2 positive : ' num2str(length(find(sum(SCA) >= 2)))])
disp(['At least 3 positive : ' num2str(length(find(sum(SCA) >= 3)))])
disp(['At least 4 positive : ' num2str(length(find(sum(SCA) >= 4)))])
disp(['5 positive : ' num2str(length(find(sum(SCA) == 5)))])

if( k ~= n)
disp('Press enter to move to the next signal');
else
disp('Press enter to finish');
end
pause();

end
51 changes: 51 additions & 0 deletions Matlab scripts/OAED_ECGinterface.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
%clc

%%
n = 0;
m = 0;
if (1 ~= exist('ECG'))
ECG = [];
end
while(true)

in = input('in ');

if(~psoc.reload)
disp('Cannot reload psoc');
break;
end

for k = 1:in
psoc.message = 'a';
psoc.send;
pause(0.1);

tmp = psoc.receive;
ECG = [ECG tmp];
tmp = psoc.receive;
ECG = [ECG tmp];

% tmp = psoc.receive;
% Z = [Z tmp];
% tmp = psoc.receive;
% Z = [Z tmp];

tmp = psoc.receive;
disp(tmp);
n = n+1;

if(psoc.message == 'A')
tmp = psoc.receive;
raw = [raw tmp];
m = m+1;
end

disp(n);
t = [1:length(ECG)]/4000;
plot(t, ECG)
end

break;
end

clear m n in k tmp
34 changes: 34 additions & 0 deletions Matlab scripts/OAED_FiltECG.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function [ecgf] = OAED_FiltECG(ecg, fs, hp, lp, notch)
%% Default parameters
if(nargin < 5)
notch = false;
end
if(nargin < 4)
lp = 40;
end
if(nargin < 3)
hp = 3;
end
if(nargin < 2)
return;
end

%% apply biquad HP iir filter
[zhi,phi,khi] = butter(2, hp/(2*fs),'high'); % 2nd order
soshi = zp2sos(zhi,phi,khi);
ecgf = sosfilt(soshi, ecg);

%% apply biquad LP iir filter
[zhi,phi,khi] = butter(4, lp/(2*fs),'low'); % 4th order
soshi = zp2sos(zhi,phi,khi);
ecgf = sosfilt(soshi, ecgf);

return; % notch still need testing
%% apply biquad notch iir filter
if(notch)
[zhi,phi,khi] = butter(2, [40 60]/(2*fs),'stop'); % 2nd order
soshi = zp2sos(zhi,phi,khi);
ecgf = sosfilt(soshi, ecgf);
end

end
40 changes: 40 additions & 0 deletions Matlab scripts/OAED_HILB.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function [SCA, d, di] = OAED_HILB(ecg, fs, echo)

if(nargin == 2)
echo = false;
end
d0 = 0.25;
n = 40;

%%
ecg = 2^31*ecg/max(ecg);
ecgh = hilbert(ecg, 2^ceil(log2(4*fs)));
ecg1 = ecgh - min(real(ecgh)) - min(imag(ecgh))*1i;
deltax = ceil(max(real(ecg1)+1)/n);
deltay = ceil(max(imag(ecg1)+1)/n);

%%
di = zeros(n);
for k = 1:length(ecg1)
zx = 1 + floor( real(ecg1(k))/deltax );
zy = 1 + floor( imag(ecg1(k))/deltay );
%di(zx,zy) = di(zx,zy) + 1;
di(zx,zy) = 1;
end

d = sum(sum(di))/(n*n);

%%
if(d>d0)
if(echo)
disp('VF confirmed');
end
SCA = true;
else
if(echo)
disp('Normal sinus rhythm');
end
SCA = false;
end

end
39 changes: 39 additions & 0 deletions Matlab scripts/OAED_PSR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function [SCA, d, di] = OAED_PSR (ecg, fs, echo)

if(nargin == 2)
echo = false;
end
tau = floor(fs * 0.5);
d0 = 0.2;
n = 40;

%%
ecg2 = ecg - min(ecg);
ecg2 = 2^31*ecg2/max(ecg2);
delta = ceil(max(ecg2+1)/n);

%%
di = zeros(n);
for k = 1:length(ecg)-tau
zx = 1 + floor( ecg2(k)/delta );
zy = 1 + floor( ecg2(k + tau)/delta );
%di(zx,zy) = di(zx,zy) + 1;
di(zx,zy) = 1;
end

d = sum(sum(di))/(n*n);

%%
if(d>d0)
if(echo)
disp('VF confirmed');
end
SCA = true;
else
if(echo)
disp('Normal sinus rhythm');
end
SCA = false;
end

end
14 changes: 14 additions & 0 deletions Matlab scripts/OAED_RecognitionPlot.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function OAED_RecognitionPlot(te, ecg, threshold, c, cmax, wl)
if(nargin == 4)
cmax = max(c);
end
if(nargin < 6)
wl = 4;
end
figure, hold on;
plot( te, 2*ecg/max(ecg));
plot( ones(1, ceil(te(end))) * threshold, 'LineWidth', 3);
plot( (1:length(c))*wl, c/cmax, 'LineWidth', 2);
hold off;
return;
end
Loading

1 comment on commit 171a587

@alireza110110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to the infotmation of transformer to design and build it.please help me.tnx

Please sign in to comment.