mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -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:
commit
c099a47327
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user