- Your data
- Your code
I need data points from Labchart file according to stimulus time points in a other channel , how can i get it?
3 views (last 30 days)
Show older comments
I am studying the auditory brainstem response using a labchart software. For that we have made a matlab code that can extract the data from text file according to the stimulus threshold. The stimulus being represented in channel 1 of the file and response to that stimuli is in channel three of the dataset. We need the excel sheet for the actual time points that matlab code is taking for the averaging purpose. We wanted to confirm whether the code is taking 10ms data after the stimulus representation or not? Its so difficult to do it mannually. So i need a help how easily i can have those 10ms data points for averaging purpose.
Please this is an request I am not from this field.
Please help.
Thank you.....
2 Comments
Answers (2)
Peter Perkins
on 5 Jun 2023
Avinash, I'm not really sure what you are trying to do, but this should get you started:
>> t = readtable("90.txt",HeaderLines=6);
>> t.Properties.VariableNames = ["Time" "Channel_1" "Channel_3"];
>> t.Time = seconds(t.Time);
>> tt = table2timetable(t)
tt =
67398×2 timetable
Time Channel_1 Channel_3
___________ __________ _________
0 sec 0.0175 -0.00125
5e-05 sec 0.018125 -0.0025
0.0001 sec 0.018437 -0.00625
0.00015 sec 0.01875 -0.010625
0.0002 sec 0.020625 -0.01375
0.00025 sec 0.014375 -0.016875
0.0003 sec -0.001875 -0.01875
0.00035 sec 0.040625 -0.019375
0.0004 sec 0.1025 -0.01875
0.00045 sec 0.047188 -0.019375
0.0005 sec -0.082812 -0.01875
0.00055 sec -0.10531 -0.018125
0.0006 sec 0.025937 -0.01875
0.00065 sec 0.14188 -0.018125
0.0007 sec 0.10562 -0.01875
0.00075 sec 0.0009375 -0.018125
0.0008 sec -0.0375 -0.0175
0.00085 sec -0.0075 -0.0175
0.0009 sec 0.021875 -0.016875
0.00095 sec 0.014063 -0.0175
: : :
0.011 sec -0.0034375 0.0075
0.01105 sec -0.0034375 0.006875
0.0111 sec -0.0034375 0.00625
0.01115 sec -0.0034375 0.005
0.0112 sec -0.0034375 0.004375
0.01125 sec -0.003125 0.00375
0.0113 sec -0.0034375 0.00375
0.01135 sec -0.0034375 0.003125
0.0114 sec -0.0034375 0.003125
0.01145 sec -0.003125 0.00375
0.0115 sec -0.003125 0.003125
0.01155 sec -0.003125 0.001875
0.0116 sec -0.003125 0.0025
0.01165 sec -0.003125 0.001875
0.0117 sec -0.003125 0.00125
0.01175 sec -0.003125 0.000625
0.0118 sec -0.003125 0
0.01185 sec -0.003125 -0.000625
0.0119 sec -0.003125 0
0.01195 sec -0.003125 0.00125
Display all 67398 rows.
Star Strider
on 5 Jun 2023
Your data initially appeared to be chaotic when I plotted them, so I took a closer look and found that most of them aere arranged in similarly-sized individual ensembles. They were relatively straightforward to determine after that, however while all have three columns, sevral have only one row. This code selects only the ‘complete’ ensembles, ignoring the others, so out of the original 1878, 240 are ‘complete’.and end up in the analysis.
T1 = readtable('90.txt', 'VariableNamingRule','preserve')
figure
plot(T1{:,1}, T1{:,[2 3]})
grid
xlabel('Time')
ylabel('Signals')
legend('Stimulus','Response', 'Location','best')
figure
plot(T1{:,1}, T1{:,[2 3]})
grid
xlabel('Time')
ylabel('Signals')
legend('Stimulus','Response', 'Location','best')
xlim([0.0020 0.0022])
[Ut11,ia,ib] = unique(T1{:,1});
Ensembles = accumarray(ib, (1:numel(ib)).', [], @(x){T1{x,:}}) % Collect Ensembles
EnsemblesRowSize = cellfun(@(x)size(x,1), Ensembles); % Determine Row Sized
EnsemblesColSize = cellfun(@(x)size(x,2), Ensembles); % Determine Column Sizes
URows = unique(EnsemblesRowSize,'stable') % Row Size Determination
Lv = EnsemblesRowSize == max(URows); % Logical Vector Of Ensembles With Complete Row Sizes
Matching = nnz(Lv) % Number With Complete Row Sizes
Ensembles = Ensembles(Lv); % Select Full Ensmebles For Analysis
UCols = unique(EnsemblesColSize,'stable'); % All Have Three Columns
Ensembles3 = cat(3,Ensembles{:}); % Concatenate Ensembles
SzEns3 = size(Ensembles3)
EnsPer = permute(Ensembles3, [3 2 1]); % Permute Array (To Make It Easier To Work With)
SzEnsPer = size(EnsPer)
Ens = EnsPer(:,:,1) % Check The First Ensemble
% figure
% plot(Ens(:,1), Ens(:,[2 3]))
% grid
% xlabel('Time')
% ylabel('Signals')
% title('Ensemble #1')
% legend('Stimulus','Response', 'Location','best')
figure
plot(EnsPer(:,1,1), EnsPer(:,[2 3],1))
grid
xlabel('Time')
ylabel('Signals')
title('Ensemble #1')
legend('Stimulus','Response', 'Location','best')
figure
plot(EnsPer(:,1,end), EnsPer(:,[2 3],end))
grid
xlabel('Time')
ylabel('Signals')
title('Ensemble #274')
legend('Stimulus','Response', 'Location','best')
figure
tiledlayout(3,3)
for k = 1:fix(274/8):274
nexttile
plot(EnsPer(:,1,k), EnsPer(:,[2 3],k))
grid
xlabel('Time')
ylabel('Amplitude')
title("Ensemble "+k)
end
EnsAvg = mean(EnsPer,3)
EnsStd = std(EnsPer, [], 3);
EnsSEM = EnsStd/sqrt(size(EnsPer,3));
CI2 = 1.96*EnsSEM(:,2)*[-1 1];
CI3 = 1.96*EnsSEM(:,3)*[-1 1];
figure
hp1 = plot(EnsAvg(:,1), EnsAvg(:,2),'-b', 'DisplayName','Stimulus Ensemble Average');
hold on
hp2 = plot(EnsAvg(:,1), EnsAvg(:,3),'-r', 'DisplayName','Response Ensemble Average');
hp3 = plot(EnsAvg(:,1), CI2+EnsAvg(:,2), '--b', 'DisplayName','Stimulus 95% Confidence Interval');
hp4 = plot(EnsAvg(:,1), CI3+EnsAvg(:,3), '--r', 'DisplayName','Response 95% Confidence Interval');
hold off
grid
xlabel('Time')
ylabel('Signals')
title('Ensemble Average')
legend([hp1 hp2 hp3(1) hp4(1)],'Location','best')
I am not certain what you want to do with these at this point, however my code finds the individual ensembles, isolates them, and presents them, and illustrates how to recover them from the ‘EnsPer’ (‘Ensemble Permuted’) matrix to work with them.
I leave all further analyses to you, since I know nothing more about your study than you shared in your initial post.
.
2 Comments
Star Strider
on 8 Jun 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
See Also
Categories
Find more on Predictive Maintenance Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!