Skip to content

Instantly share code, notes, and snippets.

@jreyes1108
Created July 24, 2010 00:17
Show Gist options
  • Save jreyes1108/488239 to your computer and use it in GitHub Desktop.
Save jreyes1108/488239 to your computer and use it in GitHub Desktop.
% Plot SQLstream detections
% Juan C. Reyes
% [email protected]
%
% Load data exported by SQLstream signal detector
% into local variables and plot.
% To Run: plot.m file.data
clear;
clc;
% Format of columns:
% The data is text, with tab-separated columns:
%
%
% SOURCENAME PKTID T SIGNAL STA LTA LTA_at_tOn LTA2 R1 R1A
% %s %d %f %f %f %f %f %f %f %f
%
% R2 threshOn threshOff threshOnTrigger threshOffTrigger
% %f %f %f %s %s
%
% ACTIVE ACTIVE2 tOn tD tOff tPeak detectionIndex
% %s %s %f %f %f %f %f
%
fid = fopen('Good_SQL_Detect.txt');
file = textscan(fid, '%s %d %f %f %f %f %f %f %f %f %f %f %f %s %s %s %s %f %f %f %f %f','delimiter','\t','EmptyValue', NaN);
fclose(fid);
name = file{1};
pktid = file{2};
time = file{3};
signal = file{4};
sta = file{5};
lta = file{6};
lta_at_on = file{7};
lta_2 = file{8};
r1 = file{9};
r1_2 = file{10};
r2 = file{11};
thresh_on = file{12};
thresh_off = file{13};
tON = file{14};
tOFF = file{15};
active = file{16};
t_on = file{17};
t_off = file{18};
t_peak = file{19};
detection_i = file{20};
CIA = []; CIA_tON = []; CIA_tOFF = []; CIA_rON = []; CIA_rOFF = []; CIA_time = []; CIA_sta = [];
CIA_lta = []; CIA_r1 = []; CIA_r2 = []; CIA_t_on = []; CIA_t_off = []; CIA_lta_on = []; CIA_r1_2 = [];
for i=1:14000
if strcmp(name(i),'CIA.def')
CIA = [CIA signal(i)];
CIA_tON = [CIA_tON tON(i)];
CIA_tOFF= [CIA_tOFF tOFF(i)];
CIA_time = [CIA_time time(i)];
CIA_sta = [CIA_sta sta(i)];
CIA_lta = [CIA_lta lta(i)];
CIA_r1 = [CIA_r1 r1(i)];
CIA_r1_2 = [CIA_r1_2 r1_2(i)];
CIA_r2 = [CIA_r2 r2(i)];
CIA_lta_on = [CIA_lta_on 0];
CIA_t_on = [CIA_t_on thresh_on(i)];
CIA_t_off = [CIA_t_off thresh_off(i)];
end
end
ax(1) =subplot(4,1,1);
h = plot(CIA_time,CIA);
set(h,'XDataSource','CIA_time')
set(h,'YDataSource','CIA')
legend('WF',2);
ax(2) =subplot(4,1,2);
m = plot(CIA_time,CIA_sta,'color','k');
set(m,'XDataSource','CIA_time')
set(m,'YDataSource','CIA_sta')
hold on;
n = plot(CIA_time,CIA_lta,'color','b');
set(n,'XDataSource','CIA_time')
set(n,'YDataSource','CIA_lta')
m = plot(CIA_time,CIA_lta_on,'color','g');
set(m,'XDataSource','CIA_time')
set(m,'YDataSource','CIA_lta_on')
legend('STA','LTA','LTA_AT_ON',2);
ax(3) =subplot(4,1,3);
o = plot(CIA_time,CIA_r1,'color','k');
set(o,'XDataSource','CIA_time')
set(o,'YDataSource','CIA_r1')
hold on;
h = plot(CIA_time,CIA_r1_2,'color','b');
set(h,'XDataSource','CIA_time')
set(h,'YDataSource','CIA_r1_2')
q = plot(CIA_time,CIA_t_on,'color','r');
set(q,'XDataSource','CIA_time')
set(q,'YDataSource','CIA_t_on')
r = plot(CIA_time,CIA_t_off,'color','g');
set(r,'XDataSource','CIA_time')
set(r,'YDataSource','CIA_t_off')
legend('R1','R2','T_ON','T_OFF',2);
ax(3) =subplot(4,1,4);
o = plot(CIA_time,CIA_r1,'color','k');
set(o,'XDataSource','CIA_time')
set(o,'YDataSource','CIA_r1')
hold on;
p = plot(CIA_time,CIA_r2,'color','b');
set(p,'XDataSource','CIA_time')
set(p,'YDataSource','CIA_r2')
u = plot(CIA_time,CIA_t_on,'color','r');
set(u,'XDataSource','CIA_time')
set(u,'YDataSource','CIA_t_on')
v = plot(CIA_time,CIA_t_off,'color','g');
set(v,'XDataSource','CIA_time')
set(v,'YDataSource','CIA_t_off')
legend('R1','R2','T_ON','T_OFF',2);
speed = 0;
for i=14000:length(name)
if strcmp(name(i),'CIA.def')
CIA = [CIA signal(i)];
CIA_tON = [CIA_tON tON(i)];
CIA_tOFF= [CIA_tOFF tOFF(i)];
CIA_time = [CIA_time time(i)];
CIA_sta = [CIA_sta sta(i)];
CIA_r1_2 = [CIA_r1_2 r1_2(i)];
if lta_at_on(i) > 0
CIA_lta_on = [CIA_lta_on lta_at_on(i)];
else
CIA_lta_on = [CIA_lta_on 0];
end
CIA_lta = [CIA_lta lta(i)];
CIA_r1 = [CIA_r1 r1(i)];
CIA_r2 = [CIA_r2 r2(i)];
CIA_t_on = [CIA_t_on thresh_on(i)];
CIA_t_off = [CIA_t_off thresh_off(i)];
if speed > 3
refreshdata
drawnow
speed = 0;
else
speed = speed + 1;
end
if strcmp(CIA_tON(end),'true')
ax(1) = subplot(4,1,1);
hold on;
plot(CIA_time(end),CIA(end),'o','MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',5);
ax(2) = subplot(4,1,4);
hold on;
plot(CIA_time(end),CIA_r1(end),'o','MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',5);
end
if strcmp(CIA_tOFF(end),'true')
ax(1) = subplot(4,1,1);
hold on;
plot(CIA_time(end),CIA(end),'o','MarkerEdgeColor','k', 'MarkerFaceColor','y', 'MarkerSize',5);
ax(2) = subplot(4,1,4);
hold on;
plot(CIA_time(end),CIA_r1(end),'o','MarkerEdgeColor','k', 'MarkerFaceColor','y', 'MarkerSize',5);
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment