1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Merge pull request #1451 from srcejon/spectrum_save

Spectrum GUI: Add button to save spectrum data to text file
This commit is contained in:
Edouard Griffiths 2022-09-26 21:39:35 +02:00 committed by GitHub
commit c099a47327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View File

@ -21,6 +21,8 @@
#include <QLineEdit>
#include <QToolTip>
#include <QFileDialog>
#include <QMessageBox>
#include "gui/glspectrumgui.h"
#include "dsp/fftwindow.h"
@ -491,6 +493,46 @@ void GLSpectrumGUI::on_markers_clicked(bool checked)
applySettings();
}
// Save spectrum data to a CSV file
void GLSpectrumGUI::on_save_clicked(bool checked)
{
(void) checked;
// Get filename to write
QFileDialog fileDialog(nullptr, "Select file to save data to", "", "*.csv");
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
if (fileDialog.exec())
{
QStringList fileNames = fileDialog.selectedFiles();
if (fileNames.size() > 0)
{
// Get spectrum data (This vector can be larger than fftSize)
std::vector<Real> spectrum;
m_spectrumVis->getPowerSpectrumCopy(spectrum);
// Write to text file
QFile file(fileNames[0]);
if (file.open(QIODevice::WriteOnly))
{
QTextStream out(&file);
float frequency = m_glSpectrum->getCenterFrequency() - (m_glSpectrum->getSampleRate() / 2.0f);
float rbw = m_glSpectrum->getSampleRate() / (float)m_settings.m_fftSize;
out << "\"Frequency\",\"Power\"\n";
for (int i = 0; i < m_settings.m_fftSize; i++)
{
out << frequency << "," << spectrum[i] << "\n";
frequency += rbw;
}
file.close();
}
else
{
QMessageBox::critical(this, "Spectrum", QString("Failed to open file %1").arg(fileNames[0]));
}
}
}
}
void GLSpectrumGUI::on_refLevel_valueChanged(int value)
{
m_settings.m_refLevel = value - m_calibrationShiftdB;

View File

@ -107,6 +107,7 @@ private slots:
void on_linscale_toggled(bool checked);
void on_wsSpectrum_toggled(bool checked);
void on_markers_clicked(bool checked);
void on_save_clicked(bool checked);
void on_waterfall_toggled(bool checked);
void on_spectrogram_toggled(bool checked);

View File

@ -1023,6 +1023,20 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="save">
<property name="toolTip">
<string>Save spectrum data to file</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/res.qrc">
<normaloff>:/save.png</normaloff>:/save.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="wsSpectrum">
<property name="toolTip">