diff --git a/QLop.pro b/QLop.pro --- a/QLop.pro +++ b/QLop.pro @@ -14,6 +14,8 @@ DESTDIR =./bin TARGET = QLop TEMPLATE = app +LIBS+=-lfftw3 + INCLUDEPATH += src/QCustomPlot \ src src/Cassini \ src/Core src/Core/Widgets \ diff --git a/src/Cassini/cassinitools.cpp b/src/Cassini/cassinitools.cpp --- a/src/Cassini/cassinitools.cpp +++ b/src/Cassini/cassinitools.cpp @@ -2,12 +2,14 @@ #include #include #include +#include CassiniTools* CassiniTools::_self=NULL; QDockWidget* CassiniTools::m_gui=NULL; CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; CassiniDataFile* CassiniTools::m_dataFile=NULL; int CassiniTools::m_defaultPlot=-1; +int CassiniTools::m_fftPlot=-1; Qt::GlobalColor QLopColours[]= {Qt::black, Qt::red, @@ -48,6 +50,7 @@ CassiniTools::~CassiniTools() void CassiniTools::makePlot() { m_defaultPlot = QLopPlots::addPlot(); + m_fftPlot = QLopPlots::addPlot(); SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); if(plot) { @@ -58,6 +61,9 @@ void CassiniTools::makePlot() SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); plot->addAction(action); QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); + action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self); + plot->addAction(action); + QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int))); } } @@ -83,19 +89,19 @@ void CassiniTools::decodeFGMData(const Q void CassiniTools::plotFile(const QString &File) { - if(!m_dataFile->isRunning()) + if(!m_dataFile->isRunning()) { - m_dataFile->parseFile(File); - // TODO fixme - SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); - if(plot==NULL) - { - makePlot(); - plot = QLopPlots::getPlot(m_defaultPlot); - } - if(plot) - plot->setTitle(File); - } + m_dataFile->parseFile(File); + // TODO fixme + SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); + if(plot==NULL) + { + makePlot(); + plot = QLopPlots::getPlot(m_defaultPlot); + } + if(plot) + plot->setTitle(File); + } } void CassiniTools::plot_TAB_File(const QString &fileName) @@ -125,6 +131,76 @@ void CassiniTools::export_view(int PID) } } +void CassiniTools::compute_fft_on_view(int PID) +{ + SocExplorerPlot* plot = QLopPlots::getPlot(PID); + if(plot==NULL) + return; + { + QLopDataList vectors; + for(int i=0;igraphCount();i++) + { + QLopData* vect = new QLopData(); + vect->data = plot->getVisibleData(i); + vectors.append(vect); + } + if(vectors.count()==3) + { + QLopData* ch1V=vectors.at(0); + QLopData* ch2V=vectors.at(1); + QLopData* ch3V=vectors.at(2); + QLopData* FFTout=new QLopData(); + if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) + { + + double* in; + fftw_complex *out; + fftw_plan p; + FFTout->data = new QVector(ch1V->data->count()/2); + in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count()); + out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count()); + double av=0; + for(int i=0;idata->count();i++) + { + in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value)); + av = av+in[i]; + } + av/=ch1V->data->count(); + for(int i=0;idata->count();i++) + { + in[i]=in[i]-av; + } + p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE); + fftw_execute(p); /* repeat as needed */ + fftw_destroy_plan(p); + fftw_free(in); + for(int i=0;idata->count()/2;i++) + { +// (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count(); + (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count()); + (*FFTout->data)[i].key = i; + } + fftw_free(out); + SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot); + if(plot==NULL) + return; + plot->removeAllGraphs(); + plot->addGraph(); + plot->setXaxisLog(); + plot->setYaxisLog(); + plot->setAdaptativeSampling(0,true); + QPen pen = plot->getGraphPen(0); + pen.setColor(QLopColours[0%QLopColoursCount]); + plot->setGraphPen(0,pen); + plot->setGraphData(0,FFTout->data,false); + plot->rescaleAxis(); + plot->replot(); + + } + } + } +} + QDockWidget *CassiniTools::getGUI() { if(!m_noGui && (m_gui==NULL)) @@ -148,25 +224,25 @@ void CassiniTools::dataReady(QLopDataLis SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); if(plot==NULL) { - makePlot(); - plot = QLopPlots::getPlot(m_defaultPlot); + makePlot(); + plot = QLopPlots::getPlot(m_defaultPlot); } if(plot) { - plot->removeAllGraphs(); - for(int i=0;iaddGraph(); - plot->setAdaptativeSampling(i,true); - plot->setUseFastVector(i,true); - QPen pen = plot->getGraphPen(i); - pen.setColor(QLopColours[i%QLopColoursCount]); - plot->setGraphPen(i,pen); - plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); - plot->setGraphData(i,data.at(i)->data,false); - } - plot->rescaleAxis(); - plot->replot(); + plot->removeAllGraphs(); + for(int i=0;iaddGraph(); + plot->setAdaptativeSampling(i,true); + plot->setUseFastVector(i,true); + QPen pen = plot->getGraphPen(i); + pen.setColor(QLopColours[i%QLopColoursCount]); + plot->setGraphPen(i,pen); + plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); + plot->setGraphData(i,data.at(i)->data,false); + } + plot->rescaleAxis(); + plot->replot(); } } diff --git a/src/Cassini/cassinitools.h b/src/Cassini/cassinitools.h --- a/src/Cassini/cassinitools.h +++ b/src/Cassini/cassinitools.h @@ -17,7 +17,7 @@ private: static QDockWidget* m_gui; static CassiniToolsGUI* m_CassiniToolsGUI; static CassiniDataFile* m_dataFile; - static int m_defaultPlot; + static int m_defaultPlot,m_fftPlot; CassiniTools(bool noGUI=false, QObject *parent=0); ~CassiniTools(); static void makePlot(); @@ -32,6 +32,7 @@ public: public slots: void plot_TAB_File(const QString& fileName); void export_view(int PID); + void compute_fft_on_view(int PID); private slots: void dataReady(QLopDataList data); }; diff --git a/src/Core/Widgets/qcustomplotvect.cpp b/src/Core/Widgets/qcustomplotvect.cpp --- a/src/Core/Widgets/qcustomplotvect.cpp +++ b/src/Core/Widgets/qcustomplotvect.cpp @@ -48,7 +48,7 @@ QCPGraphVect::QCPGraphVect(QCPAxis *keyA QCPGraphVect::~QCPGraphVect() { - + delete mData; } void QCPGraphVect::setData(QVector *data) diff --git a/src/Core/qlopdata.cpp b/src/Core/qlopdata.cpp --- a/src/Core/qlopdata.cpp +++ b/src/Core/qlopdata.cpp @@ -7,6 +7,6 @@ QLopData::QLopData(QObject *parent) : QO QLopData::~QLopData() { - + delete data; } diff --git a/src/SocExplorerPlot.cpp b/src/SocExplorerPlot.cpp --- a/src/SocExplorerPlot.cpp +++ b/src/SocExplorerPlot.cpp @@ -111,13 +111,23 @@ void SocExplorerPlot::setTitle(QString t void SocExplorerPlot::setXaxisLabel(QString label) { this->m_plot->xAxis->setLabel(label); - this->repaint(); + this->repaint(); +} + +void SocExplorerPlot::setXaxisLog() +{ + this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); } void SocExplorerPlot::setYaxisLabel(QString label) { this->m_plot->yAxis->setLabel(label); - this->repaint(); + this->repaint(); +} + +void SocExplorerPlot::setYaxisLog() +{ + this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); } void SocExplorerPlot::setXaxisRange(double lower, double upper) diff --git a/src/SocExplorerPlot.h b/src/SocExplorerPlot.h --- a/src/SocExplorerPlot.h +++ b/src/SocExplorerPlot.h @@ -64,8 +64,10 @@ public: ~SocExplorerPlot(); void setTitle(QString title); void setXaxisLabel(QString label); + void setXaxisLog(); void setXaxisRange(double lower, double upper); void setYaxisLabel(QString label); + void setYaxisLog(); void setYaxisRange(double lower, double upper); void rescaleAxis(); void setLegendFont(QFont font);