Newer
Older
#include <iostream.h>
#include <iomanip>
#include "libvis/miscplot.h"
#include "libvis/miscpic.h"
#include <iostream>
#include "newmatap.h"
#include "newmatio.h"
#include "newimage/newimageall.h"
#include "miscmaths/miscmaths.h"
#include "miscmaths/miscprob.h"
#include <string>
#include "utils/log.h"
using namespace Utilities;
using namespace NEWIMAGE;
using namespace MISCPLOT;
using namespace MISCPIC;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Matrix calcFFT(const Matrix& Mat)
{
Matrix res;
for(int ctr=1; ctr <= Mat.Ncols(); ctr++)
{
ColumnVector tmpCol;
tmpCol=Mat.Column(ctr);
ColumnVector FtmpCol_real;
ColumnVector FtmpCol_imag;
ColumnVector tmpPow;
if(tmpCol.Nrows()%2 != 0){
Matrix empty(1,1); empty=0;
tmpCol &= empty;}
RealFFT(tmpCol,FtmpCol_real,FtmpCol_imag);
tmpPow = pow(FtmpCol_real,2)+pow(FtmpCol_imag,2);
tmpPow = tmpPow.Rows(2,tmpPow.Nrows());
//if(opts.logPower.value()) tmpPow = log(tmpPow);
if(res.Storage()==0){res= tmpPow;}else{res|=tmpPow;}
}
return res;
} //Matrix calc_FFT()
string float2str(float f, int width, int prec, int scientif)
{
ostrstream os;
int redw = int(std::abs(std::log10(std::abs(f))))+1;
if(width>0)
os.width(width);
if(scientif>0)
os.setf(ios::scientific);
os.precision(redw+std::abs(prec));
os.setf(ios::internal, ios::adjustfield);
os << f << '\0';
return os.str();
}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Matrix data;
cerr<< "Reading mixing matrix ";
data = read_ascii_matrix(string("mixmat"));
if (data.Storage()<=0) {
cerr <<" Please specify the mixing matrix correctly" << endl;
}
cerr << "done " << endl;
cerr << "Matrix size : " << data.Nrows() << " x " << data.Ncols() << endl;
//set up data
if(data.Ncols()==0){
cerr << " create new data " << M_PI <<endl;
ColumnVector X(200);
for(int i=1; i<=X.Nrows(); i++){
X(i) = (float((i-1))/(X.Nrows()-1))*M_PI;
}
RowVector Y(10);
for(int i=1; i<=Y.Ncols(); i++)
Y(i)=3*i;
data = X*Y;
for(int i=1; i<=data.Ncols(); i++)
for(int j=1; j<=data.Nrows(); j++)
data(j,i) = sin(data(j,i));
cerr << "Matrix size : " << data.Nrows() << " x " << data.Ncols() << endl;
Log mmat;
mmat.setDir(string("./res/"),string("mix.txt"));
mmat << data <<endl;
}
Log IChtml;
IChtml.setDir(string("./res/"),string("index.html"));
IChtml << "<HTML> " << endl
<< "<TITLE>MELODIC Component "
<< "</TITLE>" << endl
<< "<BODY BACKGROUND=\"file:" << getenv("FSLDIR")
<< "/doc/images/fsl-bg.jpg\">" << endl
<< "<hr><CENTER><H1>MELODIC Component "
<< "</H1>"<< endl;
float tr = 0.0;
Matrix data2;
data2 = calcFFT(data);
for (int i=1; i<=data.Ncols(); i++)
{
cerr << i << " " ;
{//plot time course
miscplot newplot;
if(tr>0.0)
newplot.timeseries(data.Column(i).t(),
string("./res/t")+num2str(i)+".png",
string("Timecourse (in seconds); TR = ")+
float2str(tr,0,2,0)+" s",
tr);
else
newplot.timeseries(data.Column(i).t(),
string("./res/t")+num2str(i)+".png",
string("Timecourse (in TRs)"));
// write_ascii_matrix(string("./res/t")+num2str(i)+".txt"),
// data.Column(i));
Log tfile;
tfile.setDir(string("./res/"),string("t")+num2str(i)+".txt");
tfile << data.Column(i) << endl;
IChtml << "<A HREF=\"" << string("t")
+num2str(i)+".txt" << "\"> ";
IChtml << "<img BORDER=0 SRC=\""
+string("t")+num2str(i)+".png\"></A><p>" << endl;
}//time series plot
{//plot frequency
miscplot newplot;
int fact = int(std::pow(10.0,int(std::log10(float(data.Nrows())))));
if(tr>0.0)
newplot.timeseries(data2.Column(i).t(),
string("./res/f")+num2str(i)+".png",
string("FFT of timecourse (in Hz / ") +num2str(fact)+")",
fact/(tr*data2.Nrows()));
else
newplot.timeseries(data2.Column(i).t(),
string("./res/f")+num2str(i)+".png",
string(string("FFT of timecourse (in cycles); ")
+"frequency(Hz)=cycles/("
+num2str(data2.Nrows())
+"* TR); period(s)=("
+num2str(data2.Nrows())
+"* TR)/cycles"));
Log ffile;
ffile.setDir(string("./res/"),string("f")+num2str(i)+".txt");
ffile << data2.Column(i) << endl;
IChtml << "<A HREF=\"" << string("f")
+num2str(i)+".txt" << "\"> ";
IChtml << "<img BORDER=0 SRC=\""
+string("f")+num2str(i)+".png\"></A><p>" << endl;
}//frequency plot
}
IChtml<< "<HR><FONT SIZE=1>This page produced automatically by "
<< "FMRIB Software Library</A>.</FONT>" << endl
<< "</BODY></HTML>" << endl;
cerr << endl;
return 0;