Guest User

Untitled

a guest
Jun 30th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. /*
  2. Blind Source Separation (BSS) unit test
  3. ported from sep_demo.m by Andreas Ziehe
  4. */
  5. void bss_unittest()
  6. {
  7. // ica data
  8. int FS = 4000;
  9. EVector t(FS+1, true);
  10. t.setLinSpaced(FS+1,0,1);
  11.  
  12. // source signals
  13. EMatrix s(2,FS+1);
  14. for(int i = 0; i < FS+1; i++)
  15. {
  16. s(0,i) = sin(2*3.14*55*t[i]);
  17. s(1,i) = cos(2*3.14*100*t[i]);
  18. }
  19.  
  20. // mixing matrix
  21. EMatrix A(2,2);
  22. A(0,0) = 1; A(0,1) = 0.85;
  23. A(1,0) = 0.55; A(1,1) = 1;
  24.  
  25. SGMatrix<float64_t> X(2,FS+1);
  26. Eigen::Map<EMatrix> EX(X.matrix,2,FS+1);
  27. EX = A * s;
  28.  
  29. // begin
  30. SGVector<float64_t> sep(3); sep[0]=0; sep[1]=1; sep[2]=2; sep[3]=3;
  31. SGMatrix<float64_t> C = tdsep(X,sep);
  32.  
  33. // Unmix
  34. //Eigen::Map<EMatrix> EC(C.matrix,2,2);
  35. //EMatrix unmix = EC.inverse() * EX;
  36.  
  37. // Normalize estimated mixing matrix
  38. //for(int t = 0; t < EC.cols(); t++)
  39. // EC.col(t) /= EC.col(t).maxCoeff();
  40.  
  41. return;
  42. }
  43.  
  44. SGMatrix<float64_t> tdsep(SGMatrix<float64_t> &x, SGVector<float64_t> &sel)
  45. {
  46. int n = x.num_rows;
  47. int m = x.num_cols;
  48.  
  49. SGMatrix<float64_t>::display_matrix(x.matrix,n,m);
  50.  
  51. Eigen::Map<EMatrix> Ex(x.matrix,n,m);
  52.  
  53. std::cout << Ex << std::endl; // crashes
  54.  
  55. // ...
Advertisement
Add Comment
Please, Sign In to add comment