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 of fftSize 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() returns nullptr. 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.
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.