Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ MainWindow::MainWindow()
connect(dock, SIGNAL(fftOrZoomChanged(int, int)), plots, SLOT(setFFTAndZoom(int, int)));
connect(dock->powerMaxSlider, SIGNAL(valueChanged(int)), plots, SLOT(setPowerMax(int)));
connect(dock->powerMinSlider, SIGNAL(valueChanged(int)), plots, SLOT(setPowerMin(int)));
connect(dock->timeResolutionSlider, SIGNAL(valueChanged(int)), plots, SLOT(setTimeResolution(int)));
connect(dock->cursorsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableCursors);
connect(dock->scalesCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableScales);
connect(dock->cursorSymbolsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), plots, &PlotView::setCursorSegments);
Expand Down
11 changes: 9 additions & 2 deletions plotview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,27 @@ void PlotView::setFFTAndZoom(int size, int zoom)

void PlotView::setPowerMin(int power)
{
powerMin = power;
// HVI_REVIEW: Not needed? powerMin = power;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look like these are unused and should be removed. I'd prefer that as a separate commit that just deletes the lines, rather than commenting them out

if (spectrogramPlot != nullptr)
spectrogramPlot->setPowerMin(power);
updateView();
}

void PlotView::setPowerMax(int power)
{
powerMax = power;
// HVI_REVIEW: Not needed? powerMax = power;
if (spectrogramPlot != nullptr)
spectrogramPlot->setPowerMax(power);
updateView();
}

void PlotView::setTimeResolution(int resolution)
{
if (spectrogramPlot != nullptr)
spectrogramPlot->setTimeResolution(resolution);
// updateView(true);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be commented out, it should just be deleted

}

void PlotView::paintEvent(QPaintEvent *event)
{
if (mainSampleSource == nullptr) return;
Expand Down
5 changes: 3 additions & 2 deletions plotview.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public slots:
void setFFTAndZoom(int fftSize, int zoomLevel);
void setPowerMin(int power);
void setPowerMax(int power);
void setTimeResolution(int resolution);

protected:
void contextMenuEvent(QContextMenuEvent * event) override;
Expand All @@ -70,8 +71,8 @@ public slots:

int fftSize = 1024;
int zoomLevel = 0;
int powerMin;
int powerMax;
// int powerMin;
// int powerMax;
bool cursorsEnabled;
off_t sampleRate = 0;
bool timeScaleEnabled;
Expand Down
4 changes: 4 additions & 0 deletions spectrogramcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
powerMinSlider->setRange(-140, 10);
layout->addRow(new QLabel(tr("Power min:")), powerMinSlider);

timeResolutionSlider = new QSlider(Qt::Horizontal, widget);
timeResolutionSlider->setRange(0, 99);
layout->addRow(new QLabel(tr("Time resolution:")), timeResolutionSlider);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but I'd prefer this to be just under the zoom slider - it makes sense to group FFT size/zoom/resolution together.

scalesCheckBox = new QCheckBox(widget);
scalesCheckBox->setCheckState(Qt::Checked);
layout->addRow(new QLabel(tr("Scales:")), scalesCheckBox);
Expand Down
1 change: 1 addition & 0 deletions spectrogramcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private slots:
QSlider *zoomLevelSlider;
QSlider *powerMaxSlider;
QSlider *powerMinSlider;
QSlider *timeResolutionSlider;
QCheckBox *cursorsCheckBox;
QSpinBox *cursorSymbolsSpinBox;
QLabel *rateLabel;
Expand Down
46 changes: 43 additions & 3 deletions spectrogramplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@

SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float>>> src) : Plot(src), inputSource(src), fftSize(512), tuner(fftSize, this)
{
setFFTSize(fftSize);
zoomLevel = 1;
powerMax = 0.0f;
powerMin = -50.0f;
timeResolution = 0.0;
sampleRate = 0;
frequencyScaleEnabled = false;
setFFTSize(fftSize);

for (int i = 0; i < 256; i++) {
float p = (float)i / 256;
Expand Down Expand Up @@ -271,15 +272,46 @@ std::shared_ptr<AbstractSampleSource> SpectrogramPlot::output()
return tunerTransform;
}

static float bessel(float x, int kmax = 5)
{
int k;
float kfactorial = 1.0;
float half_x_to_k_pow = 1.0;
float term;
float result = 1.0;
for(k = 1; k < kmax; k++) {
half_x_to_k_pow *= x/2.0;
kfactorial *= k;
term = half_x_to_k_pow / kfactorial;
result += term * term;
}
return result;
}

void SpectrogramPlot::setFFTSize(int size)
{
float sizeScale = float(size) / float(fftSize);
float beta = 20;
float denominator = bessel(beta);

fftSize = size;
fft.reset(new FFT(fftSize));

window.reset(new float[fftSize]);
for (int i = 0; i < fftSize; i++) {
window[i] = 0.5f * (1.0f - cos(Tau * i / (fftSize - 1)));
int zeroCount = (fftSize * timeResolution) / 100;
if ((zeroCount >= 0) && (zeroCount <= fftSize)) {
int windowSize = fftSize - zeroCount;
for (int i = 0; i < windowSize; i++) {
float term = float(2*i - windowSize + 1) / windowSize;
window[i] = bessel(beta * sqrt(1.0 - term * term)) / denominator;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I notice that the spectrogram shifts to the right as you increase the time resolution slider. To stop that happening, I think that the non-zero values should be centered in the window, rather than left-aligned.

}
for (int i = windowSize; i < fftSize; i++) {
window[i] = 0;
}
} else {
for(int i = 0; i < fftSize; i++) {
window[i] = 0;
}
}

setHeight(fftSize);
Expand All @@ -301,6 +333,14 @@ void SpectrogramPlot::setPowerMin(int power)
{
powerMin = power;
pixmapCache.clear();
// HVI_REVIEW: Why no tunerMoved like in setPowerMax()?
}

void SpectrogramPlot::setTimeResolution(int resolution)
{
timeResolution = resolution;
setFFTSize(fftSize);
invalidateEvent();
}

void SpectrogramPlot::setZoomLevel(int zoom)
Expand Down
2 changes: 2 additions & 0 deletions spectrogramplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public slots:
void setPowerMax(int power);
void setPowerMin(int power);
void setZoomLevel(int zoom);
void setTimeResolution(int res);
void tunerMoved();

private:
Expand All @@ -71,6 +72,7 @@ public slots:
int zoomLevel;
float powerMax;
float powerMin;
int timeResolution;
off_t sampleRate;
bool frequencyScaleEnabled;

Expand Down