Skip to content
3 changes: 3 additions & 0 deletions PIDscope.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@

set(0,'defaultUicontrolFontName', 'Helvetica')
% defaultUicontrolFontSize is set after fontsz is calculated (below)
% plots carry log names and field names (quad_bf.01.csv, debug_0_): TeX would make subscripts of them
set(0,'defaultTextInterpreter', 'none')
set(0,'defaultAxesTickLabelInterpreter', 'none')

%%%% assign main figure handle and define some UI variables
PSfig = figure(1);
Expand Down
47 changes: 43 additions & 4 deletions THIRD-PARTY-LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,50 @@ signal 1.4.7, statistics 1.8.3) with their notices retained in place. The macOS
package ships no Octave packages at all - `pidscope.command` installs control
and signal from Octave Forge on first launch.

## MATLAB File Exchange helpers
## b2r colormap (releases up to v26.10.0)

`src/` contains a small number of helper functions originating from the
MathWorks File Exchange. Their original headers, author names and licence
terms are retained in the respective files.
| | |
| --- | --- |
| Upstream | https://www.mathworks.com/matlabcentral/fileexchange/36212-b2r-cmin-input-cmax-input- |
| Author | Cunjie Zhang |
| Licence | BSD-2-Clause |
| Copyright | Copyright (c) 2015, LoveUltraman |

Every release from v26.02-beta1 to v26.10.0 shipped `b2r.m`, a blue-white-red
colormap from the MATLAB File Exchange inherited from PIDtoolbox, unmodified:
at the top level up to v26.02-beta4, as `src/util/b2r.m` from v26.02-rc1 on.
Releases up to v26.03.1 also carried a copy of the same function inside the
statistics plot (`PTplotStats.m`, later `src/plot/PSplotStats.m`). Those files
kept the author's name but not the licence the File Exchange distributes with
the submission, so it is reproduced here for those releases. Later releases do
not contain the code.

```
Copyright (c) 2015, LoveUltraman
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
```

## Obtaining the source

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
26.10.0
26.10.1
11 changes: 9 additions & 2 deletions src/compat/dkl2rgb.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
% dkl2rgb - convert DKL cone opponent colors to RGB
% rgb = dkl2rgb(dkl)
% input (dkl) is [luminance; red/green; blue/yellow]
% 'magic numbers', based on 'average' crt monitor and derived using
% Smith & Pokorny cone fundamentals % V. C. Smith & J. Pokorny (1975), Vision Res. 15, 161-172.
%
% Copyright (C) 2026 Grzegorz Sterniczuk
% License: GPL v3 (see LICENSE)
% Extracted from PScolormap.m for Octave compatibility
%
% ----------------------------------------------------------------------------------
% "THE BEER-WARE LICENSE" (Revision 42):
% <brian.white@queensu.ca> wrote this file. As long as you retain this notice you
% can do whatever you want with this stuff. If we meet some day, and you think
% this stuff is worth it, you can buy me a beer in return. -Brian White
% ----------------------------------------------------------------------------------

M_dkl2rgb = [
1.0000 1.0000 -0.3495
Expand Down
54 changes: 43 additions & 11 deletions src/compat/kstest2.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
% [h, p] = kstest2(x1, x2, alpha)
% [h, p] = kstest2(x1, x2, 'alpha', alpha)
%
% Two-sided test only. Asymptotic p-value after Numerical Recipes 14.3.
% Two-sided test only. Asymptotic p-value from the Kolmogorov distribution,
% with Stephens' (1970) small-sample correction applied to lambda.

alpha = 0.05;
if numel(varargin) == 1 && isnumeric(varargin{1})
Expand All @@ -33,17 +34,48 @@
error('kstest2: both samples must be non-empty');
end

edges = [-Inf; sort([x1; x2]); Inf];
cdf1 = cumsum(histc(x1, edges)) / n1;
cdf2 = cumsum(histc(x2, edges)) / n2;
ks2stat = max(abs(cdf1(1:end-1) - cdf2(1:end-1)));
[xs, idx] = sort([x1; x2]);
in1 = idx <= n1;
% both ECDFs have to include every copy of a tied value before comparing
last = [diff(xs) ~= 0; true];
d = cumsum(in1) / n1 - cumsum(~in1) / n2;
ks2stat = max(abs(d(last)));

n = n1 * n2 / (n1 + n2);
lambda = max((sqrt(n) + 0.12 + 0.11 / sqrt(n)) * ks2stat, 0);
nEff = n1 * n2 / (n1 + n2);
lambda = (sqrt(nEff) + 0.12 + 0.11 / sqrt(nEff)) * ks2stat;
pValue = min(max(ksSurvival(lambda), 0), 1);

v = 1:101;
pValue = 2 * sum((-1) .^ (v - 1) .* exp(-2 * lambda * lambda * v .^ 2));
pValue = min(max(pValue, 0), 1);
H = (pValue <= alpha);
end

H = (alpha >= pValue);
function p = ksSurvival(lambda)
% P(K > lambda). The alternating series in exp(-2 j^2 lambda^2) needs many
% terms and cancels badly for small lambda; there the theta-function form
% of the same distribution converges in two or three terms.
if lambda <= 0
p = 1;
return;
end
s = 0;
if lambda < 1
c = -pi^2 / (8 * lambda^2);
for k = 1:50
t = exp(c * (2*k - 1)^2);
s = s + t;
if t <= eps * s
break;
end
end
p = 1 - sqrt(2*pi) / lambda * s;
else
c = -2 * lambda^2;
for j = 1:50
t = exp(c * j^2);
s = s + (-1)^(j - 1) * t;
if t <= eps * abs(s)
break;
end
end
p = 2 * s;
end
end
10 changes: 7 additions & 3 deletions src/plot/PSplotSpec2D.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@
else
tmpDbgIdx = struct('GYRO_SCALED',6,'GYRO_FILTERED',3,'RC_INTERPOLATION',7,'FFT_FREQ',17,'FEEDFORWARD',59);
end
% BF 4.5+ logs gyroUnfilt whatever the debug mode, and 2025.12 has no GYRO_SCALED
hasPrefilt_ = isfield(T{tmpFileIdx}, 'gyroPrefilt_0_') || debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_SCALED || debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_FILTERED || debugmode(tmpFileIdx) == 1 || debugmode(tmpFileIdx) == 0;
if get(guiHandlesSpec2.Delay, 'Value') == 1 && a == 1
if debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_SCALED || debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_FILTERED || debugmode(tmpFileIdx) == 1 || debugmode(tmpFileIdx) == 0
if hasPrefilt_
h=text(65, climScale2(get(guiHandlesSpec2.checkboxPSD, 'Value')+1)-(f*4), ['Gyro Filter: ' Debug01{tmpFileIdx} 'ms | Dterm Filter: ' FilterDelayDterm{tmpFileIdx} 'ms']);
set(h,'Color',[lineCol],'fontsize',fontsz);
else
Expand All @@ -404,7 +406,7 @@
end
end
if get(guiHandlesSpec2.Delay, 'Value') == 4 && a == 1
if debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_SCALED || debugmode(tmpFileIdx) == tmpDbgIdx.GYRO_FILTERED || debugmode(tmpFileIdx) == 1 || debugmode(tmpFileIdx) == 0
if hasPrefilt_
h=text(65, climScale2(get(guiHandlesSpec2.checkboxPSD, 'Value')+1)-(f*4), ['Gyro Phase: ' num2str(gyro_phase_shift_deg(tmpFileIdx)) 'deg | Dterm Phase: ' num2str(dterm_phase_shift_deg(tmpFileIdx)) 'deg']);
set(h,'Color',[lineCol],'fontsize',fontsz);
else
Expand Down Expand Up @@ -489,6 +491,8 @@
else
h=legend(legnd, 'Location','NorthEast');
end
% entries carry log file names; Octave has no root default for the legend interpreter
set(h, 'Interpreter', 'none');
try PSstyleLegend(h, th); catch, end
end
catch, end
Expand All @@ -502,7 +506,7 @@
delete(findobj(PSspecfig2, 'Tag', 'prefiltWarn'));
axW_ = findobj(PSspecfig2, 'Type', 'axes', 'Tag', 'PSspec2_1');
if ~isempty(axW_)
text(axW_, 0.5, 0.5, {'No pre-filter gyro data.', 'Requires gyroUnfilt (BF 4.5+) or debug\_mode = GYRO\_SCALED.'}, ...
text(axW_, 0.5, 0.5, {'No pre-filter gyro data.', 'Requires gyroUnfilt (BF 4.5+) or debug_mode = GYRO_SCALED.'}, ...
'Units', 'normalized', 'HorizontalAlignment', 'center', 'FontSize', fontsz+1, ...
'Color', [.8 .3 .3], 'Tag', 'prefiltWarn');
end
Expand Down
3 changes: 2 additions & 1 deletion src/ui/PSTestSignalConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ function mkSection(txt, col)
winSecs = [0.5 1 2 5 inf];
wSec = winSecs(winIdx);

idx = tIND{fileIdx};
% tIND is a mask; centre the preview on the samples it keeps
idx = find(tIND{fileIdx});
if isempty(idx), idx = 1:N; end
midSample = round(mean([idx(1) idx(end)]));
if wSec >= tFull(end)
Expand Down
8 changes: 8 additions & 0 deletions src/ui/PSautotuneUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ function tick(frac, msg)
end
end
lines = {};
if numel(bad) == 3
% nothing was measured, so there is no verdict either way
allWell = false;
headline = 'NO AXIS COULD BE MEASURED';
lines{end+1} = sprintf('%s could not be read from this log.', strjoin(bad, ' and '));
lines{end+1} = 'The reason is shown in each plot.';
return
end
allWell = isempty(flagged);
if ~allWell
verb = 'NEEDS';
Expand Down
96 changes: 34 additions & 62 deletions src/util/PSdatatip.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
function [output_txt] = PSdatatip(obj,event_obj)
%% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
% this is a minor modification of the Matlab datatip tool to display
% relevant units for this project, deg/s and time with ms precision
% - B. White
function txt = PSdatatip(obj, evt)
% datacursormode UpdateFcn, MATLAB only (Octave goes through PSdatatip_click).
% Log viewer traces get up to 6 significant digits on x so time keeps ms
% precision; below -logviewerYscale the lower panel reads in percent.
% Spectrogram images show %T, Hz and the value under the cursor.
%
% ----------------------------------------------------------------------------------
% "THE BEER-WARE LICENSE" (Revision 42):
Expand All @@ -17,62 +14,37 @@

global logviewerYscale

fontsz2=16;
fontsz2 = 16;
try
a=event_obj.Target.Type;
c=event_obj.Target.Color;
a = evt.Target.Type;
c = evt.Target.Color;
catch
end
c1=[0.9300 0.5000 0.3000];
c2=[0.3000 0.6500 0.9500];
if ~strcmp(a,'image') % ugly workaround
pos = get(event_obj,'Position');
if pos(1)<100,
dgts=5;
else
dgts=6;
end
if pos(2) > -logviewerYscale
output_txt = {['x: ',num2str(pos(1),dgts)],...
['y: ',num2str(pos(2),4)]};
else
output_txt = {['sec: ',num2str(pos(1),dgts)],...
['%: ',num2str(((pos(2)+(logviewerYscale*2)) / (logviewerYscale/100)),4)]};
end


% dataTipH=plot([pos(1) pos(1)], [-2400 2400],'r-');
% get(dataTipH)
if c==c1 | c==c2
output_txt = {['x: ',num2str(pos(1),4)],...
['y: ',num2str(pos(2),4)]};
end
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
set(findall(gcf,'type','hggroup'),'FontSize',fontsz2,'FontWeight', 'bold')
else
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)]};
c1 = [0.9300 0.5000 0.3000];
c2 = [0.3000 0.6500 0.9500];
p = get(evt, 'Position');

% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
if strcmp(a,'image')
% pos = get(event_obj,'Position');
% output_txt = {['X: ',num2str(pos(1),4)],...
% ['Y: ',num2str(pos(2),4)]};

y=(obj.Parent.YLim(2)-pos(2)) / (.3);
output_txt = {['%T: ',num2str(pos(1),4)],...
['Hz: ',num2str(y,4)]};

z=event_obj.Target.CData(pos(2),pos(1));
output_txt{end+1} = ['Z: ',num2str(z,4)];
end
set(findall(gcf,'type','hggroup'),'FontSize',fontsz2,'FontWeight', 'bold')
if ~strcmp(a, 'image')
if p(1) < 100
dgts = 5;
else
dgts = 6;
end
if p(2) > -logviewerYscale
txt = {['x: ' num2str(p(1), dgts)], ['y: ' num2str(p(2), 4)]};
else
txt = {['sec: ' num2str(p(1), dgts)], ...
['%: ' num2str((p(2) + logviewerYscale*2) / (logviewerYscale/100), 4)]};
end
if c == c1 | c == c2
txt = {['x: ' num2str(p(1), 4)], ['y: ' num2str(p(2), 4)]};
end
if numel(p) > 2
txt{end+1} = ['Z: ' num2str(p(3), 4)];
end
else
hz = (obj.Parent.YLim(2) - p(2)) / .3;
txt = {['%T: ' num2str(p(1), 4)], ['Hz: ' num2str(hz, 4)], ...
['Z: ' num2str(evt.Target.CData(p(2), p(1)), 4)]};
end
set(findall(gcf, 'type', 'hggroup'), 'FontSize', fontsz2, 'FontWeight', 'bold')
Loading
Loading