From bdf01b5ffbdf0139ed4522a5de7b8fd82335e1ef Mon Sep 17 00:00:00 2001 From: Vincenzo Petrolo Date: Sun, 4 Jul 2021 12:39:16 +0200 Subject: [PATCH] fix : correct mapping for frequencies Signed-off-by: Vincenzo Petrolo --- Desktop_Interface/asyncdft.cpp | 13 ++++++------- Desktop_Interface/asyncdft.h | 4 ++-- Desktop_Interface/isodriver.cpp | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Desktop_Interface/asyncdft.cpp b/Desktop_Interface/asyncdft.cpp index 1617dfbb..f97ce44d 100644 --- a/Desktop_Interface/asyncdft.cpp +++ b/Desktop_Interface/asyncdft.cpp @@ -1,6 +1,7 @@ #include "asyncdft.h" #include #include +#include "isobuffer.h" #define DBG 0 @@ -15,7 +16,7 @@ AsyncDFT::AsyncDFT() /*Initializing time domain window to 0s*/ /*FFTW3 inits*/ fftw_init_threads(); - fftw_plan_with_nthreads(omp_get_max_threads()); + fftw_plan_with_nthreads(omp_get_max_threads() * 2); #if DBG std::cout << "Starting with " << omp_get_max_threads() << "threads" << std::endl; #endif @@ -114,14 +115,12 @@ QVector AsyncDFT::getPowerSpectrum(QVector input) return amplitude; } -QVector AsyncDFT::getFrequenciyWindow() +QVector AsyncDFT::getFrequenciyWindow(int samplesPerSeconds) { - int max_freq = 62500; - double delta_freq = ((double) 350000)/ ((double) n_samples); - int tot = max_freq/delta_freq + 1; - QVector f(tot); + double delta_freq = ((double) samplesPerSeconds)/ ((double) n_samples); + QVector f(n_samples/2 + 1); - for (int i = 0; i < tot; i++) { + for (int i = 0; i < n_samples/2 + 1; i++) { f[i] = i*delta_freq; } diff --git a/Desktop_Interface/asyncdft.h b/Desktop_Interface/asyncdft.h index bae58d03..70e4fd4f 100644 --- a/Desktop_Interface/asyncdft.h +++ b/Desktop_Interface/asyncdft.h @@ -13,11 +13,11 @@ class AsyncDFT public: AsyncDFT(); ~AsyncDFT(); - static const int n_samples = 350000; + static const int n_samples = 1<<17; /* Raise exception if not ready yet*/ QVector getPowerSpectrum(QVector input); - QVector getFrequenciyWindow(); + QVector getFrequenciyWindow(int samplesPerSeconds); /*Add a sample to the time domain samples*/ void addSample(short sample); diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index 9f96b175..68c7b4b6 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -740,7 +740,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) if (spectrum) { /*If frequency spectrum mode*/ try { QVector amplitude = internalBuffer375_CH1->async_dft.getPowerSpectrum(converted_dt_samples); - QVector f = internalBuffer375_CH1->async_dft.getFrequenciyWindow(); + QVector f = internalBuffer375_CH1->async_dft.getFrequenciyWindow(internalBuffer375_CH1->m_samplesPerSecond); double maximum = internalBuffer375_CH1->async_dft.maximum; axes->graph(0)->setData(f,amplitude); #if 0 @@ -749,7 +749,7 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) axes->graph(1)->setData(f,amplitude); } #endif - axes->xAxis->setRange(f.length(), 0); + axes->xAxis->setRange(f.last(), f.front()); axes->yAxis->setRange(maximum,0); } catch (std::exception) { std::cout << "Cannot yet get correct value for DFT" << std::endl;