Improve spectrogram time alignment #227
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
SpectrogramPlot::getLine()
uses the sample parameter to determine the index of the first sample that is used to calculate the FFT for a particular spectrogram line. Since the FFT is in some sense an average offftSize
samples, this causes features (such as the start and end of packet bursts) to appear somewhat sooner in the spectrogram compared to their actual locations in the IQ file.This improves the time alignment of the spectrogram plot by making sample refer to the middle sample of the FFT (so the samples used to compute the FFT start at
sample - fftSize / 2
.For the beginning of the file we need to make an exception, because if we try to fetch samples before the beginning of the file, then
inputSource->getSamples()
returnsnullptr
.SpectrogramPlot::getLine()
handles this gracefully, but an ugly red bar appears at the beginning of the file when the FFT size and zoom are large. To solve this, we cheat and force the FFT to start at the beginning of the file. To be more precise we could pad the beginning with zeros instead.To test this, I'm using the following script to generate a 100 ms SigMF file at 1 Msps with an AWGN noise floor and a chunk of much stronger AWGN between 10 and 11 ms (which simulates a digital communications packet). A SigMF annotation marks this stronger noise chunk.
The main branch shows the following. The packet appears to begin before it should.
This PR shows the following. The start and end of the packet "bleed over" outside of the annotation box, but this is inevitable when using FFTs. I think that this is a better representation of the signal.