include check scripts to the project.
changed pulseWidth to pulseT.
This commit is contained in:
116
utilities/post_processing/checkCounterSamples.m
Normal file
116
utilities/post_processing/checkCounterSamples.m
Normal file
@@ -0,0 +1,116 @@
|
||||
%% =========================================================
|
||||
% Data
|
||||
% =========================================================
|
||||
clc;
|
||||
X = raw_DPW.Data; % [512 x nFrames x nTime]
|
||||
|
||||
% Remove first DPW if needed (initialization artifact)
|
||||
X = X(:,:,2:end);
|
||||
|
||||
[nSamples, nFrames_cfg, nTime] = size(X);
|
||||
|
||||
%% =========================================================
|
||||
% PARAMETERS
|
||||
% =========================================================
|
||||
COUNTER_MAX = 511; % counter: 0..511
|
||||
|
||||
%% =========================================================
|
||||
% VALIDATION
|
||||
% =========================================================
|
||||
for t = 1:nTime
|
||||
|
||||
fprintf('\n=== Checking DPW %d ===\n', t);
|
||||
|
||||
X_dpw = X(:,:,t);
|
||||
|
||||
% Flatten stream
|
||||
x_seq = reshape(X_dpw, [], 1);
|
||||
|
||||
% Extract stored integers
|
||||
real_seq = double(storedInteger(real(x_seq))); % sample counter
|
||||
frame_seq = double(storedInteger(imag(x_seq))); % frame index
|
||||
|
||||
%% -----------------------------------------------------
|
||||
% 1. Sample progression
|
||||
% -----------------------------------------------------
|
||||
d_real = diff(real_seq);
|
||||
|
||||
valid_steps = (d_real == 1) | (d_real == -COUNTER_MAX);
|
||||
|
||||
if all(valid_steps)
|
||||
fprintf('✔ Sample progression OK\n');
|
||||
else
|
||||
idx = find(~valid_steps, 1);
|
||||
fprintf('❌ Sample progression ERROR at index %d\n', idx);
|
||||
end
|
||||
|
||||
%% -----------------------------------------------------
|
||||
% 2. Detect counter wraps (511 → 0)
|
||||
% -----------------------------------------------------
|
||||
wrap_idx = find(real_seq(1:end-1) == COUNTER_MAX & real_seq(2:end) == 0);
|
||||
|
||||
fprintf('Detected wraps: %d (configured: %d)\n', ...
|
||||
length(wrap_idx), nFrames_cfg);
|
||||
|
||||
if length(wrap_idx) == nFrames_cfg
|
||||
fprintf('✔ Wrap count matches configuration\n');
|
||||
else
|
||||
fprintf('❌ Wrap count mismatch\n');
|
||||
end
|
||||
|
||||
%% -----------------------------------------------------
|
||||
% 3. Check frame increment at wraps (no wrap logic)
|
||||
% -----------------------------------------------------
|
||||
ok_wrap = true;
|
||||
|
||||
for k = 1:length(wrap_idx)
|
||||
|
||||
i = wrap_idx(k);
|
||||
|
||||
f_before = frame_seq(i);
|
||||
f_after = frame_seq(i+1);
|
||||
|
||||
if f_after ~= f_before + 1
|
||||
fprintf('❌ Frame increment error at idx %d (%d → %d)\n', ...
|
||||
i, f_before, f_after);
|
||||
ok_wrap = false;
|
||||
break;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if ok_wrap
|
||||
fprintf('✔ Frame increments correctly at all wraps\n');
|
||||
end
|
||||
|
||||
%% -----------------------------------------------------
|
||||
% 4. Informative: frame regions (+1 effect)
|
||||
% -----------------------------------------------------
|
||||
d_frame = diff(frame_seq);
|
||||
nFrames_detected = sum(d_frame == 1) + 1;
|
||||
|
||||
fprintf('Frame regions (including partial): %d (expected: %d + 1)\n', ...
|
||||
nFrames_detected, nFrames_cfg);
|
||||
|
||||
%% -----------------------------------------------------
|
||||
% 5. Optional: per-frame sanity (≤2 indices)
|
||||
% -----------------------------------------------------
|
||||
frame_idx_matrix = storedInteger(imag(X_dpw));
|
||||
|
||||
frame_ok = true;
|
||||
|
||||
for f = 1:nFrames_cfg
|
||||
u = unique(frame_idx_matrix(:,f));
|
||||
|
||||
if length(u) > 2
|
||||
fprintf('❌ Frame %d has >2 frame indices\n', f);
|
||||
frame_ok = false;
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
if frame_ok
|
||||
fprintf('✔ Frame structure OK (≤2 indices per frame)\n');
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user