/* 
This program will perform Mallat's algorithm in V_3
which is isomorphic to R^8
Here an orthonormal basis is used.  Mallat's algorithm
does not use a orthonormal basis in R^8, we thus
multiply the coeficients by various constants.
*/

#include <iostream>   
#include <string>
#include <cmath>

using namespace std;

void Mallat(double x[], double y[]);

int main()
{
  int count;
  double input_signal[8];
  double filtered[8];

  cout << "Please enter the eight coefficients from the original signal separated by spaces: " << endl;

  for(count = 0; count <= 7; count++){
  cin >> input_signal[count];
  }
  Mallat(input_signal, filtered);

  cout << "Your wavelet coeficients are:\n"
       << "[ ";
  for(count = 0; count <= 7; count++){
  cout << filtered[count]
       << " ";
  }
  cout << " ]\n";

  return 0;
}

/*
To normalize, 
multiply the V_0 and V_0^perp coeficients by 2sqrt(2)
multiply the V_1^perp coeficients by 2
multiply the V_2^perp coeficients by sqrt(2)
*/

void Mallat(double x[], double y[])
{
  y[0]=2.0*sqrt(2.0)*(x[0]+x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7])*(1.0/8.0);
  y[1]=2.0*sqrt(2.0)*(x[0]+x[1]+x[2]+x[3]-x[4]-x[5]-x[6]-x[7])*(1.0/8.0);  
  y[2]=2.0*(x[0]+x[1]-x[2]-x[3])*(1.0/4.0);
  y[3]=2.0*(x[4]+x[5]-x[6]-x[7])*(1.0/4.0);
  y[4]=sqrt(2.0)*(x[0]-x[1])*(1.0/2.0);
  y[5]=sqrt(2.0)*(x[2]-x[3])*(1.0/2.0);
  y[6]=sqrt(2.0)*(x[4]-x[5])*(1.0/2.0);
  y[7]=sqrt(2.0)*(x[6]-x[7])*(1.0/2.0);

}
