1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-13 20:01:46 -05:00

Save spectrum as CSV file with frequency and header

This commit is contained in:
Jon Beniston 2022-09-26 18:03:14 +01:00
parent b935b32274
commit f85045b291

View File

@ -493,13 +493,13 @@ void GLSpectrumGUI::on_markers_clicked(bool checked)
applySettings(); applySettings();
} }
// Save spectrum data to a text file // Save spectrum data to a CSV file
void GLSpectrumGUI::on_save_clicked(bool checked) void GLSpectrumGUI::on_save_clicked(bool checked)
{ {
(void) checked; (void) checked;
// Get filename to write // Get filename to write
QFileDialog fileDialog(nullptr, "Select file to save data to", "", "*.*"); QFileDialog fileDialog(nullptr, "Select file to save data to", "", "*.csv");
fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setAcceptMode(QFileDialog::AcceptSave);
if (fileDialog.exec()) if (fileDialog.exec())
{ {
@ -515,8 +515,13 @@ void GLSpectrumGUI::on_save_clicked(bool checked)
if (file.open(QIODevice::WriteOnly)) if (file.open(QIODevice::WriteOnly))
{ {
QTextStream out(&file); QTextStream out(&file);
for (int i = 0; i < m_settings.m_fftSize; i++) { float frequency = m_glSpectrum->getCenterFrequency() - (m_glSpectrum->getSampleRate() / 2.0f);
out << spectrum[i] << "\n"; 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(); file.close();
} }