From 628b89ae91a92d694b05ce3a54b9627c130f5b82 Mon Sep 17 00:00:00 2001 From: Vincenzo Petrolo Date: Sun, 9 May 2021 01:52:34 +0200 Subject: [PATCH] build : successful build, need to be tested Signed-off-by: Vincenzo Petrolo --- Desktop_Interface/Labrador.pro | 4 ++++ Desktop_Interface/isodriver.cpp | 27 +++++++++++++++++++++++++-- Desktop_Interface/isodriver.h | 10 ++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Desktop_Interface/Labrador.pro b/Desktop_Interface/Labrador.pro index 20d61baf..b4594110 100644 --- a/Desktop_Interface/Labrador.pro +++ b/Desktop_Interface/Labrador.pro @@ -350,3 +350,7 @@ DISTFILES += \ build_android/package_source/gradle/wrapper/gradle-wrapper.properties \ build_android/package_source/gradlew.bat \ build_android/package_source/res/xml/device_filter.xml + +unix|win32: LIBS += -ldrfftw + +unix|win32: LIBS += -ldfftw diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index 04e1df65..490cc648 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -5,7 +5,6 @@ #include #include "daqloadprompt.h" - isoDriver::isoDriver(QWidget *parent) : QLabel(parent) { this->hide(); @@ -33,6 +32,15 @@ isoDriver::isoDriver(QWidget *parent) : QLabel(parent) slowTimer->setTimerType(Qt::PreciseTimer); slowTimer->start(MULTIMETER_PERIOD); connect(slowTimer, SIGNAL(timeout()), this, SLOT(slowTimerTick())); + + /*Creating DFT plan*/ + /*Create more plans, for larger input sizes*/ + this->N = MAX_WINDOW_SIZE*ADC_SPS/20*21; + this->plan = rfftw_create_plan(N, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE); + this->in_buffer = (fftw_real *) malloc(sizeof(fftw_real)*N); + this->out_buffer = (fftw_real *) malloc(sizeof(fftw_real)*N); + this->power_spectrum = (fftw_real *) malloc(sizeof(fftw_real)*N); + } void isoDriver::setDriver(genericUsbDriver *newDriver){ @@ -728,8 +736,23 @@ void isoDriver::frameActionGeneric(char CH1_mode, char CH2_mode) } else { /*Size of input buffer is 375ks*/ } - /*Compute FFT*/ + /*Compute FFT, real to complex*/ + rfftw_one(this->plan, CH1.data(), this->out_buffer); + power_spectrum[0] = out_buffer[0]*out_buffer[0]; /* DC component */ + for (int k = 1; k < (N+1)/2; ++k) /* (k < N/2 rounded up) */ + power_spectrum[k] = out_buffer[k]*out_buffer[k] + out_buffer[N-k]*out_buffer[N-k]; + if (N % 2 == 0) /* N is even */ + power_spectrum[N/2] = out_buffer[N/2]*out_buffer[N/2]; /* Nyquist freq. */ /*Write output to new arrays, and plot them*/ + QVector pow_spec_vect; + pow_spec_vect.reserve(N/2); + std::copy(power_spectrum, power_spectrum + N/2, std::back_inserter(pow_spec_vect)); + /*Power spectrum is on power_spectrum N/2 array, it represents positive frequencies*/ + QCPCurve* curve = reinterpret_cast(axes->plottable(0)); + curve->setData(pow_spec_vect, CH2); + /*Should only print half of the total screen output*/ + axes->xAxis->setRange(xmin, xmax); + axes->yAxis->setRange(ymin, ymax); } else if(XYmode){ QCPCurve* curve = reinterpret_cast(axes->plottable(0)); curve->setData(CH1, CH2); diff --git a/Desktop_Interface/isodriver.h b/Desktop_Interface/isodriver.h index 528ec248..63513d81 100644 --- a/Desktop_Interface/isodriver.h +++ b/Desktop_Interface/isodriver.h @@ -5,6 +5,8 @@ #include #include #include +#include + #include "qcustomplot.h" #include "genericusbdriver.h" #include "desktop_settings.h" @@ -124,6 +126,14 @@ private: bool firstFrame = true; bool hexDisplay_CH1 = false; bool hexDisplay_CH2 = false; + //DFT + rfftw_plan plan; + fftw_real *in_buffer; + fftw_real *out_buffer; + fftw_real *power_spectrum; + int N; + + //Generic Functions void analogConvert(short *shortPtr, QVector *doublePtr, int TOP, bool AC, int channel); void digitalConvert(short *shortPtr, QVector *doublePtr);