diff --git a/src/matlab/spectral_analysis/dtDefaultBlockBoundaries.m b/src/matlab/spectral_analysis/dtDefaultBlockBoundaries.m index 0b9260a..5882b00 100644 --- a/src/matlab/spectral_analysis/dtDefaultBlockBoundaries.m +++ b/src/matlab/spectral_analysis/dtDefaultBlockBoundaries.m @@ -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]); @@ -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 diff --git a/src/matlab/user_interface/dtPlotSpecgram.m b/src/matlab/user_interface/dtPlotSpecgram.m index eb20a3d..17bab56 100644 --- a/src/matlab/user_interface/dtPlotSpecgram.m +++ b/src/matlab/user_interface/dtPlotSpecgram.m @@ -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 @@ -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 @@ -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)]); diff --git a/src/matlab/user_interface/dtTonalAnnotate.m b/src/matlab/user_interface/dtTonalAnnotate.m index b61f98a..36d813b 100644 --- a/src/matlab/user_interface/dtTonalAnnotate.m +++ b/src/matlab/user_interface/dtTonalAnnotate.m @@ -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);