From 11933b6fdc5c5a7746caa348268b23c647b404a2 Mon Sep 17 00:00:00 2001
From: Tim Behrens <behrens@fmrib.ox.ac.uk>
Date: Thu, 26 Aug 2004 16:20:46 +0000
Subject: [PATCH] *** empty log message ***

---
 miscmaths.cc | 19 +++++++++++++++++++
 miscmaths.h  |  3 ++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/miscmaths.cc b/miscmaths.cc
index 3988cbb..a02259b 100644
--- a/miscmaths.cc
+++ b/miscmaths.cc
@@ -1549,6 +1549,25 @@ void powerspectrum(const Matrix &Mat1, Matrix &Result, bool useLog)
 }
 
 
+void element_mod_n(Matrix& Mat,double n)
+{
+ //represent each element in modulo n (useful for wrapping phases (n=2*M_PI))
+
+  double tmp;
+  for( int j=1;j<=Mat.Ncols();j++){
+    for( int i=1;j<=Mat.Nrows();i++){
+
+      if( !( (Mat(i,j)>0) && (Mat(i,j)<n) ) ){ 
+	tmp = ( Mat(i,j) - MISCMATHS::round(Mat(i,j)/n)*n );
+	Mat(i,j)= tmp > 0 ? tmp : tmp + n;
+      }    
+      
+    }
+    
+  }
+  
+}
+
 int nextpow2(int n)
 {
   return (int)pow(2,ceil(log(float(n))/log(float(2))));
diff --git a/miscmaths.h b/miscmaths.h
index 5ea0705..382d2e6 100644
--- a/miscmaths.h
+++ b/miscmaths.h
@@ -196,7 +196,8 @@ namespace MISCMATHS {
   ReturnMatrix corrcoef(const Matrix& mat, const int norm = 0);
   void symm_orth(Matrix &Mat);
   void powerspectrum(const Matrix &Mat1, Matrix &Result, bool useLog);
-  
+  void element_mod_n(Matrix& Mat,double n); //represent each element in modulo n (useful for wrapping phases (n=2*M_PI))
+
   // ols
   // data is t x v
   // des is t x ev (design matrix)
-- 
GitLab