|
@@ -1,21 +1,52 @@
|
|
#include "./generator-rf.h"
|
|
#include "./generator-rf.h"
|
|
#include <random>
|
|
#include <random>
|
|
|
|
+#include <cmath>
|
|
#include <stdexcept>
|
|
#include <stdexcept>
|
|
namespace mri {
|
|
namespace mri {
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
|
|
+ void GeneratorRF::EvaluateSignal(std::vector<double> &signal_rf) {
|
|
|
|
+ signal_rf.resize(total_samples_);
|
|
|
|
+ for (long i = 0; i < total_samples_; ++i) {
|
|
|
|
+ signal_rf[i] = 0.0;
|
|
|
|
+ double time = timesteps_[i];
|
|
|
|
+ for (unsigned int voxel = 0; voxel < voxel_num_; ++voxel) {
|
|
|
|
+ signal_rf[i] +=
|
|
|
|
+ amplitudes_[voxel]
|
|
|
|
+ * std::sin(
|
|
|
|
+ omega_*time + phases_[voxel]
|
|
|
|
+ )
|
|
|
|
+ * std::exp(-time/
|
|
|
|
+ (T2s_decays_norm_[voxel]*T2s_scale_
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ // ) + ( 0.0
|
|
|
|
+ // + np.random.rand()/noise_ratio
|
|
|
|
+
|
|
|
|
+ ;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
void GeneratorRF::RandomizeVoxels(){
|
|
void GeneratorRF::RandomizeVoxels(){
|
|
std::random_device rd;
|
|
std::random_device rd;
|
|
- std::mt19937_64 gn;
|
|
|
|
- gn.seed(rd());
|
|
|
|
|
|
+ std::mt19937_64 om;
|
|
|
|
+ om.seed(rd());
|
|
double lbound = 0.0, ubound = 1.0;
|
|
double lbound = 0.0, ubound = 1.0;
|
|
std::uniform_real_distribution<double> rand(lbound, ubound);
|
|
std::uniform_real_distribution<double> rand(lbound, ubound);
|
|
- for (int i = 0; i < 10; ++i;){
|
|
|
|
- std::cout<< rand(gn) <<" ";
|
|
|
|
|
|
+ amplitudes_.clear();
|
|
|
|
+ T2s_decays_norm_.clear();
|
|
|
|
+ amplitudes_.resize(voxel_num_);
|
|
|
|
+ T2s_decays_norm_.resize(voxel_num_);
|
|
|
|
+ for (double &:amplitudes_){
|
|
|
|
+ amp = rand(om);
|
|
|
|
+ }
|
|
|
|
+ for (double &decay:T2s_decays_norm_){
|
|
|
|
+ decay = rand(om);
|
|
}
|
|
}
|
|
- std::cout<<std::endl;
|
|
|
|
-
|
|
|
|
};
|
|
};
|
|
|
|
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
@@ -29,8 +60,8 @@ namespace mri {
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
- void GeneratorRF::SetT2sDecays(std::vector<double> T2s_decays){
|
|
|
|
- T2s_decays_ = T2s_decays;
|
|
|
|
|
|
+ void GeneratorRF::SetT2sDecaysNorm(std::vector<double> T2s_decays_norm){
|
|
|
|
+ T2s_decays_norm_ = T2s_decays_norm;
|
|
};
|
|
};
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
@@ -42,10 +73,10 @@ namespace mri {
|
|
period_ms_ = period_ms;
|
|
period_ms_ = period_ms;
|
|
samples_per_period_ = samples_per_period;
|
|
samples_per_period_ = samples_per_period;
|
|
omega_ = 2.0*PI_/period_ms_;
|
|
omega_ = 2.0*PI_/period_ms_;
|
|
- long total_samples = total_periods * samples_per_period;
|
|
|
|
- timesteps_.resize(total_samples);
|
|
|
|
|
|
+ total_samples_ = total_periods * samples_per_period;
|
|
|
|
+ timesteps_.resize(total_samples_);
|
|
double a_timestep = period_ms/samples_per_period;
|
|
double a_timestep = period_ms/samples_per_period;
|
|
- for (long i = 0; i < total_samples; ++i) {
|
|
|
|
|
|
+ for (long i = 0; i < total_samples_; ++i) {
|
|
timesteps_[i] = i*a_timestep;
|
|
timesteps_[i] = i*a_timestep;
|
|
}
|
|
}
|
|
// for (double step: timesteps_) std::cout << step<<' ';
|
|
// for (double step: timesteps_) std::cout << step<<' ';
|
|
@@ -56,10 +87,18 @@ namespace mri {
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
void GeneratorRF::SetVoxels(double voxel_num, double phase_init,
|
|
void GeneratorRF::SetVoxels(double voxel_num, double phase_init,
|
|
- double phase_range) {
|
|
|
|
|
|
+ double phase_range, double T2s_scale) {
|
|
|
|
+ T2s_scale_ = T2s_scale;
|
|
|
|
+ if (voxel_num < 2)
|
|
|
|
+ throw std::invalid_argument("We need at least two voxels for phase gradient");
|
|
voxel_num_ = voxel_num;
|
|
voxel_num_ = voxel_num;
|
|
phase_init_ = phase_init;
|
|
phase_init_ = phase_init;
|
|
phase_range_ = phase_range;
|
|
phase_range_ = phase_range;
|
|
|
|
+ double phase_step = phase_range_/(voxel_num_ - 1);
|
|
|
|
+ phases_.resize(voxel_num);
|
|
|
|
+ for (unsigned int i =0; i< voxel_num_; ++i) {
|
|
|
|
+ phases_[i] = phase_init_ + i*phase_step;
|
|
|
|
+ }
|
|
};
|
|
};
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|