-
Notifications
You must be signed in to change notification settings - Fork 3
/
plotascans.m
89 lines (73 loc) · 2.81 KB
/
plotascans.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function [row, col] = plotascans(fileName,outFolder,rowRange,colRange, ...
dt,minProm1,noiseThresh)
%PLOTASCANS Plot A-scans.
% [row, col] = PLOTASCANS(fileName,outFolder,rowRange,colRange,dt,...
% minProm1,noiseThresh) Plots A-scans over requested row and column range
% and finds peaks. Uses found peaks to fit smoothing spline and plots
% spline. Plots and displays peak of peaks information.
%
% Inputs:
%
% FILENAME: Name of .mat file to read
% OUTFOLDER: Folder path to .mat output files
% ROWRANGE: Range of rows to plot A-scans
% COLRANGE: Range of columns to plot A-scans
% DT: Sampling period in microseconds
% MINPROM1: Min prominence in findpeaks for a peak to be identified
% NOISETHRESH: If the average signal at a point is lower than
% noiseThresh, then the point is ignored
% Load variable
loadVar = "cscan";
inFile = strcat(outFolder,"\",loadVar,"\",fileName,'-',...
loadVar,'.mat');
load(inFile,loadVar);
% Find # data points/A-scan
[row, col, pts] = size(cscan); %#ok<USENS>
% Create time vector
tend = (pts-1)*dt;
t = 0:dt:tend;
% Find number of rows and columns requested
nCol = length(colRange); nRow = length(rowRange);
% Full screen figure
figure('WindowState','maximized');
n = 0; % subplot counter
for j = 1:nCol
for i = 1:nRow
n = n + 1;
subplot(nRow,nCol,n); hold on;
point = squeeze(cscan(rowRange(i),colRange(j),:))';
[p, l] = findpeaks(point,t);
% Force signal to be zero at beginning and end
p = [0 p 0]; %#ok<AGROW>
l = [0 l t(end)]; %#ok<AGROW>
% Fit smoothing spline to found peaks
fits = fit(l',p','smoothingspline');
% Evaluate smoothing spline for t
pFit = feval(fits,t);
% Plot A-scan
plot(t,point,'Color',[0.5,0.5,0.5]);
findpeaks(pFit,t,'MinPeakProminence',minProm1,'WidthReference', ...
'halfheight','Annotate','extents');
% Find peaks
[peak,loc,width,prom] = findpeaks(pFit,t','MinPeakProminence', ...
minProm1,'WidthReference','halfheight','Annotate','extents');
% Display peak info
peakInfo = table(peak,loc,width,prom);
figTitle = strcat("Row ",num2str(rowRange(i)), ...
", Col ",num2str(colRange(j)),", #",num2str(n));
disp(figTitle)
disp(peakInfo)
% Plot smoothing spline fit
plot(t,pFit,'-k','LineWidth',2);
plot([0,t(end)],[noiseThresh noiseThresh],'--r');
% Format figure
grid minor
title(figTitle);
xlabel('Time (microseconds)');
ylabel('Magnitude');
s = findobj('type','legend');
delete(s)
end
end
sgtitle(fileName);
end