Skip to content

Commit

Permalink
Fixed gradual unalignment error & padding
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaZingale committed Nov 2, 2023
1 parent f08d57d commit 83054b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/matlab/spectral_analysis/dtDefaultBlockBoundaries.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
blocks = zeros(0,2);

%frames_per_s = Fs/advance_samples;

first = true;
while(StopBlock_s < (file_len_s - Advance_s - shift_samples_s))
StopBlock_s = min(StartBlock_s + block_len_s + 2 * block_pad_s, file_len_s);
if (first)
StopBlock_s = min(StartBlock_s + block_len_s + block_pad_s, file_len_s);
first = false;
else
StopBlock_s = min(StartBlock_s + block_len_s + 2 * block_pad_s, file_len_s);
end


%fprintf('Processing raw block from %.10f to %.10f\n', StartBlock_s, StopBlock_s);
blocks = vertcat(blocks, [StartBlock_s, StopBlock_s]);
Expand All @@ -21,7 +27,7 @@

%StartBlock_s = Indices.timeidx(end) + Advance_s - shift_samples_s;
%StartBlock_s = StopBlock_s - shift_samples_s;
StartBlock_s = StartBlock_s + block_len_s - shift_samples_s;
StartBlock_s = max(StopBlock_s - shift_samples_s - 2 * block_pad_s, 0);
end
end

17 changes: 14 additions & 3 deletions src/matlab/user_interface/dtPlotSpecgram.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,16 @@
shift_samples = 0;
shift_samples_s = shift_samples / header.fs;

block_pad_s = 1 / thr.high_cutoff_Hz;
% Padding the number of samples/frame allows for the full block length
% to be generated with full FFT frames.
% Because of how SNR is calculated, we have n_bad_snr_frames poorly
% rendered pixels at the end of a block.
% TODO: There likely does not need to be any padding at the beginning, but
% the padding currently is equal on both sides. Maybe remove pre-padding
% elsewhere in code.
n_bad_snr_frames = 1;
block_pad_frames = Length_samples + n_bad_snr_frames;
block_pad_s = block_pad_frames * Length_s/Length_samples; % 1 / thr.high_cutoff_Hz;

% Determine what padding is needed.
% padding will be added to each side of the current
Expand Down Expand Up @@ -302,8 +311,9 @@
%fprintf('Block(%.4f - %.4f) = TimeIdx(%.4f - %.4f)\n', blkstart_s, blkend_s, Indices_blk.timeidx(1), Indices_blk.timeidx(end));

% Plot spectrogram with image().
snr_dB_blk = snr_dB_blk(:, 1:floor((Indices_blk.FrameLastComplete - n_bad_snr_frames)));
if (strcmp(FilterBank,'linear'))
ImageH(hidx) = image(Indices_blk.timeidx, frequencyAxis, snr_dB_blk, 'Parent', AxisH);
ImageH(hidx) = image(Indices_blk.timeidx(1:floor((Indices_blk.FrameLastComplete - n_bad_snr_frames))), frequencyAxis, snr_dB_blk, 'Parent', AxisH);
elseif (strcmp(FilterBank,'constantQ'))
ImageH(hidx) = image(Indices_blk.timeidx, log10(frequencyAxis), snr_dB_blk, 'Parent', AxisH);
end
Expand Down Expand Up @@ -333,7 +343,8 @@
end

fclose(handle);
set(AxisH, 'XLim', [Start_s, Stop_s]);
% Padding was added to Stop_s earlier and now must be deducted
set(AxisH, 'XLim', [Start_s, Stop_s - block_pad_s]);
set(AxisH, 'YDir', 'normal');
if strcmp(FilterBank, 'linear')
set(AxisH, 'YLim', [frequencyAxis(1), frequencyAxis(end)]);
Expand Down
4 changes: 3 additions & 1 deletion src/matlab/user_interface/dtTonalAnnotate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,9 @@ function annotationFilenameToClipboard_Callback(hObject, eventdata, handles)

% Images will painted on top of any preview or selected points,
% Reorder, placing images at end of list
axisChildren = get(axisH, 'Children');
% "fliplr" is to ensure that the earlier block is rendered above
% the latter: this hides visual artifacts of the snr averaging filter
axisChildren = fliplr(get(axisH, 'Children')')';
axisIndcs = 1:length(axisChildren);
% Locate the images in the list of children
imageIndcs = zeros(length(handles.image), 1);
Expand Down

0 comments on commit 83054b4

Please sign in to comment.