icatest.cpp
Go to the documentation of this file.00001 #include <iostream>
00002 #include <itpp/base/fastica.h>
00003 #include <itpp/base/mat.h>
00004 #include <itpp/base/sigfun.h>
00005 #include <string>
00006 #include <fstream>
00007 #include "UniformRNG.h"
00008 #include "TimeSeriesData.h"
00009 #include "statutils.h"
00010 using namespace std;
00011
00012 void WriteToFile(const itpp::Vec<double> &orig,const itpp::Vec<double> &in,const itpp::Vec<double> &out,const string &base)
00013 {
00014 ofstream origts((base+".orig").c_str());
00015 ofstream origspec((base+".spec.orig").c_str());
00016 ofstream ints((base+".in").c_str());
00017 ofstream inspec((base+".spec.in").c_str());
00018 ofstream outts((base+".out").c_str());
00019 ofstream outspec((base+".spec.out").c_str());
00020 const int size = in.length();
00021 itpp::Vec<double> insp = itpp::spectrum(in,2048,0);
00022 itpp::Vec<double> outsp = itpp::spectrum(out,2048,0);
00023 itpp::Vec<double> origsp = itpp::spectrum(orig,2048,0);
00024 for (int i = 0; i < size; ++i)
00025 {
00026 origts << orig(i) << endl;
00027 origspec << origsp(i) << endl;
00028 ints << in(i) << endl;
00029 inspec << insp(i) << endl;
00030 outts << out(i) << endl;
00031 outspec << outsp(i) << endl;
00032 }
00033 }
00034
00035
00036 int main()
00037 {
00038 const int nchannels = 4;
00039 const size_t tslength = 2000;
00040 itpp::mat Mix(nchannels,nchannels);
00041 UniformRNG Random;
00042
00043 for (int i = 0; i < nchannels; ++i)
00044 for (int j = 0; j < nchannels; ++j)
00045 Mix(i,j) = Random.GetNumber();
00046
00047 itpp::mat Input(nchannels,tslength);
00048 itpp::mat Sources(nchannels,tslength);
00049 for (size_t i = 0; i < tslength; ++i)
00050 {
00051
00052
00053
00054
00055 }
00056 for (size_t i = 0; i < tslength; ++i)
00057 {
00058 double number = 0.5 - Random.GetNumber();
00059 Input(0,i) = sin(i/13.678) + 0.1 * Random.GetNumber();
00060 Input(1,i) = cos(i/13.678) + 0.1 * Random.GetNumber() + 0.5 * number;
00061 Input(2,i) = 3.3 * number + 0.1 * sin(i/13.678) + 1.2 * cos(i/13.678);
00062 Input(3,i) = 0.1 * number + 0.01 * Random.GetNumber();
00063
00064
00065
00066
00067
00068
00069 }
00070
00071 itpp::Fast_ICA fastica(Input);
00072 fastica.set_nrof_independent_components(nchannels);
00073
00074
00075 fastica.separate();
00076 itpp::mat Output = fastica.get_independent_components();
00077 WriteToFile(Sources.get_row(0),Input.get_row(0),Output.get_row(0),"1");
00078 WriteToFile(Sources.get_row(1),Input.get_row(1),Output.get_row(1),"2");
00079 WriteToFile(Sources.get_row(2),Input.get_row(2),Output.get_row(2),"3");
00080 WriteToFile(Sources.get_row(3),Input.get_row(3),Output.get_row(3),"4");
00081 }