nmrpulse.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef nmrpulseH
15 #define nmrpulseH
16 //---------------------------------------------------------------------------
17 #include <vector>
18 #include "secondarydriver.h"
19 #include "dso.h"
20 #include "pulserdriver.h"
21 #include <complex>
22 //---------------------------------------------------------------------------
23 #include "nmrspectrumsolver.h"
24 #include "xwavengraph.h"
25 
26 class Ui_FrmNMRPulse;
28 
30 public:
31  XNMRPulseAnalyzer(const char *name, bool runtime,
32  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
33  virtual ~XNMRPulseAnalyzer();
34 
35  //! Shows all forms belonging to driver
36  virtual void showForms() override;
37 protected:
38 
39  //! This function is called when a connected driver emit a signal
40  virtual void analyze(Transaction &tr, const Snapshot &shot_emitter,
41  const Snapshot &shot_others,
42  XDriver *emitter) throw (XRecordError&) override;
43  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
44  //! This might be called even if the record is invalid (time() == false).
45  virtual void visualize(const Snapshot &shot) override;
46  //! Checks if the connected drivers have valid time stamps.
47  //! \return true if dependency is resolved.
48  //! This function must be reentrant unlike analyze().
49  virtual bool checkDependency(const Snapshot &shot_this,
50  const Snapshot &shot_emitter, const Snapshot &shot_others,
51  XDriver *emitter) const override;
52 
53 public:
54  //! driver specific part below
56  //! Time-domain Wave.
57  const std::vector<std::complex<double> > &wave() const {return m_wave;}
58  //! Power spectrum of the noise estimated from the background. [V^2/Hz].
59  const std::vector<double> &darkPSD() const {return m_darkPSD;}
60  //! freq. resolution [Hz]
61  double dFreq() const {return m_dFreq;}
62  //! time resolution [sec.]
63  double interval() const {return m_interval;}
64  //! time diff. of the first point from trigger [sec.]
65  double startTime() const {return m_startTime;}
66  //! Length of the wave().
67  int waveWidth() const {return m_waveWidth;}
68  //! Position of the origin of FT.
69  int waveFTPos() const {return m_waveFTPos;}
70  //! Length of FT.
71  int ftWidth() const {return m_ftWave.size();}
72  private:
73  friend class XNMRPulseAnalyzer;
74  std::vector<std::complex<double> > m_wave;
75  std::vector<double> m_darkPSD;
76  /// FFT Wave
77  const std::vector<std::complex<double> > &ftWave() const {return m_ftWave;}
78  double m_ftWavePSDCoeff;
79  std::vector<std::complex<double> > m_ftWave;
80  std::vector<std::complex<double> > m_dsoWave;
81  int m_dsoWaveStartPos, m_waveFTPos, m_waveWidth;
82  double m_dFreq; ///< Hz per point
83  //! # of summations.
84  int m_avcount;
85  //! Stored Waves for avg.
86  std::vector<std::complex<double> > m_waveSum;
87  std::vector<double> m_darkPSDSum;
88  //! time resolution
89  double m_interval;
90  //! time diff. of the first point from trigger
91  double m_startTime;
92 
93  //for FFT/MEM.
94  shared_ptr<FFT> m_ftDark;
95 
96  XTime m_timeClearRequested;
97  };
98 
99  //! Entry storing the power of the strogest peak.
100  const shared_ptr<XScalarEntry> &entryPeakAbs() const {return m_entryPeakAbs;}
101  //! Entry storing the freq. of the strongest peak.
102  const shared_ptr<XScalarEntry> &entryPeakFreq() const {return m_entryPeakFreq;}
103 
104  const shared_ptr<XItemNode<XDriverList, XDSO> > &dso() const {return m_dso;}
105  const shared_ptr<XItemNode<XDriverList, XPulser> > &pulser() const {return m_pulser;}
106 
107  void acquire();
108 
109  //! Origin from trigger [ms]
110  const shared_ptr<XDoubleNode> &fromTrig() const {return m_fromTrig;}
111  //! length of data points [ms]
112  const shared_ptr<XDoubleNode> &width() const {return m_width;}
113 
114  const shared_ptr<XDoubleNode> &phaseAdv() const {return m_phaseAdv;} ///< [deg]
115  /// Periodic-Noise Reduction
116  const shared_ptr<XBoolNode> &usePNR() const {return m_usePNR;}
117  /// Select spectrum solver.
118  const shared_ptr<XComboNode> &pnrSolverList() const {return m_pnrSolverList;}
119  /// Select spectrum solver. FFT/AR/MEM.
120  const shared_ptr<XComboNode> &solverList() const {return m_solverList;}
121  /// Position from trigger, for background subtraction or PNR [ms]
122  const shared_ptr<XDoubleNode> &bgPos() const {return m_bgPos;}
123  /// length for background subtraction or PNR [ms]
124  const shared_ptr<XDoubleNode> &bgWidth() const {return m_bgWidth;}
125  /// Phase 0 deg. position of FT component from trigger [ms]
126  const shared_ptr<XDoubleNode> &fftPos() const {return m_fftPos;}
127  /// If exceeding Width, do zerofilling
128  const shared_ptr<XUIntNode> &fftLen() const {return m_fftLen;}
129  /// FFT/AR Window Function
130  const shared_ptr<XComboNode> &windowFunc() const {return m_windowFunc;}
131  /// FFT/AR/MEM Window Length / Taps
132  const shared_ptr<XDoubleNode> &windowWidth() const {return m_windowWidth;}
133  /// Set Digital IF frequency
134  const shared_ptr<XDoubleNode> &difFreq() const {return m_difFreq;}
135 
136  /// Extra Average with infinite steps
137  const shared_ptr<XBoolNode> &exAvgIncr() const {return m_exAvgIncr;}
138  /// Extra Average Steps
139  const shared_ptr<XUIntNode> &extraAvg() const {return m_extraAvg;}
140  /// Clear averaging results
141  const shared_ptr<XTouchableNode> &avgClear() const {return m_avgClear;}
142 
143  /// # of echoes
144  const shared_ptr<XUIntNode> &numEcho() const {return m_numEcho;}
145  /// If NumEcho > 1, need periodic term of echoes [ms]
146  const shared_ptr<XDoubleNode> &echoPeriod() const {return m_echoPeriod;}
147 
148 private:
149  /// Stored Wave for display.
150  const shared_ptr<XWaveNGraph> &waveGraph() const {return m_waveGraph;}
151  /// Stored FFT Wave for display.
152  const shared_ptr<XWaveNGraph> &ftWaveGraph() const {return m_ftWaveGraph;}
153 
154  const shared_ptr<XScalarEntry> m_entryPeakAbs;
155  const shared_ptr<XScalarEntry> m_entryPeakFreq;
156 
157  const shared_ptr<XItemNode<XDriverList, XDSO> > m_dso;
158 
159  const shared_ptr<XDoubleNode> m_fromTrig;
160  const shared_ptr<XDoubleNode> m_width;
161 
162  const shared_ptr<XDoubleNode> m_phaseAdv; ///< [deg]
163  const shared_ptr<XBoolNode> m_usePNR;
164  const shared_ptr<XComboNode> m_pnrSolverList;
165  const shared_ptr<XComboNode> m_solverList;
166  const shared_ptr<XDoubleNode> m_bgPos;
167  const shared_ptr<XDoubleNode> m_bgWidth;
168  const shared_ptr<XDoubleNode> m_fftPos;
169  const shared_ptr<XUIntNode> m_fftLen;
170  const shared_ptr<XComboNode> m_windowFunc;
171  const shared_ptr<XDoubleNode> m_windowWidth;
172  const shared_ptr<XDoubleNode> m_difFreq;
173 
174  const shared_ptr<XBoolNode> m_exAvgIncr;
175  const shared_ptr<XUIntNode> m_extraAvg;
176 
177  const shared_ptr<XUIntNode> m_numEcho;
178  const shared_ptr<XDoubleNode> m_echoPeriod;
179 
180  const shared_ptr<XTouchableNode> m_spectrumShow;
181  const shared_ptr<XTouchableNode> m_avgClear;
182 
183  //! Phase Inversion Cycling
184  const shared_ptr<XBoolNode> m_picEnabled;
185  const shared_ptr<XItemNode<XDriverList, XPulser> > m_pulser;
186  atomic<int> m_isPulseInversionRequested;
187 
188  std::deque<xqcon_ptr> m_conUIs;
189 
190  shared_ptr<XListener> m_lsnOnSpectrumShow, m_lsnOnAvgClear;
191  shared_ptr<XListener> m_lsnOnCondChanged;
192 
193  const qshared_ptr<FrmNMRPulse> m_form;
194  const shared_ptr<XStatusPrinter> m_statusPrinter;
195  const qshared_ptr<FrmGraphNURL> m_spectrumForm;
196 
197  const shared_ptr<XWaveNGraph> m_waveGraph;
198  const shared_ptr<XWaveNGraph> m_ftWaveGraph;
199 
200  //for FFT/MEM.
201  shared_ptr<SpectrumSolverWrapper> m_solver;
202  shared_ptr<SpectrumSolverWrapper> m_solverPNR;
203  shared_ptr<XXYPlot> m_peakPlot;
204 
205  void onCondChanged(const Snapshot &shot, XValueNodeBase *);
206  void onSpectrumShow(const Snapshot &shot, XTouchableNode *);
207  void onAvgClear(const Snapshot &shot, XTouchableNode *);
208 
209  void backgroundSub(Transaction &tr,
210  std::vector<std::complex<double> > &wave, int pos, int length, int bgpos, int bglength);
211 
212  void rotNFFT(Transaction &tr, int ftpos, double ph,
213  std::vector<std::complex<double> > &wave, std::vector<std::complex<double> > &ftwave);
214 };
215 
216 #endif

Generated for KAME4 by  doxygen 1.8.3