none
Class for parser of cross-correlation obtainer RRS feed

  • Вопрос

  • Class for parser of cross-correlation obtainer

    //correlation.h

    #include <stdio.h>  //cstdio.h
    #include <stdlib.h> //cstdlib.h
    //#include <iostream>
    #include <math.h> //cmath.h


    class CCFParser_tag
    {
     private:

     public:

       double getCCF ( double a,double b,  double tau  , double (*x1)(double ), double (*x2)(double ), double eps) ;
       double getCCF2 ( double a,double b,  double tau  , double (*x1)(double ), double (*x2)(double ), double eps) ;

      CCFParser_tag();
      ~CCFParser_tag();


      };


    double CCFParser_tag::getCCF (
     double a,double b, 
     double tau  , double (*x1)(double ), double (*x2)(double ),
     double eps
     )

    {
     double h1,s,s0,s1,sn, arg;
     int i,n;
     s=1;
     sn=101;
     n=4;
     arg=((a+b)/2);

    //ACF Bu(tau)=integr(-inf,+inf, u(t)*u(t-tau), d t)
    //CCF ВКФ Bf1f2(tau)=integr(-inf,+inf, f1(t)*f2(t-tau), d t)   ;
    //CCF ВКФ Bf1f2(tau)=integr(-inf,+inf, f1(t+tau)*f2(t), d t)   ;

     s0=((x1(a)*x2(a-tau) )+(x1(b)*x2(b-tau) ))/2;
     s1=x1(arg)*x2(arg-tau) ;
    // s0=((x1(a+tau)*x2(a) )+(x1(b+tau)*x2(b) ))/2;
    // s1=x1(arg+tau)*x2(arg) ;

     while (fabs(s-sn)>eps){
     sn=s;
     h1=(b-a)/n;
     for (i=0; i<n/2; i++)
    {
    arg=(a+(2*i+1)*h1);

     s1+=x1(arg)*x2(arg-tau);
    //s1+=x1(arg+tau)*x2(arg);
    }
     s=h1*(s0+s1);
     n*=2;
     }
     return s;

    }
    //Buv(tau)=Bvu(-tau)
    double CCFParser_tag::getCCF2 (
     double a,double b, 
     double tau  , double (*x1)(double ), double (*x2)(double ),
     double eps
     )

    {
     double h1,s,s0,s1,sn, arg;
     int i,n;
     s=1;
     sn=101;
     n=4;
     arg=((a+b)/2);

    //ACF Bu(tau)=integr(-inf,+inf, u(t)*u(t-tau), d t)
    //CCF ВКФ Bf1f2(tau)=integr(-inf,+inf, f1(t)*f2(t-tau), d t)   ;
    //CCF ВКФ Bf1f2(tau)=integr(-inf,+inf, f1(t+tau)*f2(t), d t)   ;

    // s0=((x1(a)*x2(a-tau) )+(x1(b)*x2(b-tau) ))/2;
    // s1=x1(arg)*x2(arg-tau) ;
      s0=((x1(a+tau)*x2(a) )+(x1(b+tau)*x2(b) ))/2;
      s1=x1(arg+tau)*x2(arg) ;

     while (fabs(s-sn)>eps){
     sn=s;
     h1=(b-a)/n;
     for (i=0; i<n/2; i++)
    {
    arg=(a+(2*i+1)*h1);

     //s1+=x1(arg)*x2(arg-tau);
     s1+=x1(arg+tau)*x2(arg);
    }
     s=h1*(s0+s1);
     n*=2;
     }
     return s;

    }

    // +1 +1 +1 -1 +1


    • Изменено USERPC01 7 августа 2016 г. 17:53 name of file
    • Перемещено Igor Leyko 6 сентября 2016 г. 17:21
    7 августа 2016 г. 17:52

Все ответы

  • //getsignal.h

    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <math.h>

    // +1 +1 +1 -1 +1  Barker 5

    double t1=0;
    double t2=5;
    double Um=1;


    double s1(double t )
    {
      
      if (t<=(0.2*(t2-t1)) ) {  return 1*Um ; }
      if ((t>(0.2*(t2-t1)) )&&(t<=(0.4*(t2-t1)))) {   return 1*Um ; }
      if ((t>(0.4*(t2-t1)) )&&(t<=(0.6*(t2-t1)))) {   return 1*Um ; }
      if ((t>(0.6*(t2-t1)) )&&(t<=(0.8*(t2-t1)))) {  return -1*Um ; }
      if ((t>(0.8*(t2-t1)) )&&(t<=(1*(t2-t1)))) {  return 1*Um ; }

     return 1;
    }

    double s2(double t )
    {
     
    if (t<=(0.2*(t2-t1)) ) {  return 1*Um ; }
    if ((t>(0.2*(t2-t1)) )&&(t<=(0.4*(t2-t1)))) {   return 1*Um ; }
    if ((t>(0.4*(t2-t1)) )&&(t<=(0.6*(t2-t1)))) {   return 1*Um ; }
    if ((t>(0.6*(t2-t1)) )&&(t<=(0.8*(t2-t1)))) {  return -1*Um ; }
    if ((t>(0.8*(t2-t1)) )&&(t<=(1*(t2-t1)))) {  return 1*Um ; }
     
     return 1;
    }

    //mainunit.cpp

    #include <stdio.h>
    #include <stdlib.h>

    #include <math.h>
    #include  "getsignal.h"
    #include  "correlation.h"

    int main()
    {
    char key;
    label1:


    CCFParser_tag  *CCF;

    double t=t1;
    double s;
    while (t<t2)
    {
    s=s1( t );
    printf("\nt=%le, s1(t)= %le ", t, s);

    t+=0.1;
    }

    printf("\n Enter 'y' to next \n");
    scanf("%s",&key);
    if(key!='y') goto label1;

    t=0;

    while (t<t2)
    {
    s=s2( t );
    printf("\nt=%le, s2(t)= %le ", t, s);

    t+=0.1;
    }

    printf("\n Enter 'y' to next \n");
    scanf("%s",&key);
    if(key!='y') goto label1;


    double tau=0.0;

    double s1(double t );
    double s2(double t );

    tau=-t2;

    while (tau<t2)
    {
     s=CCF->getCCF2(t1,t2 ,tau , s1,s2, 0.00001);
    printf("\nt=%le, B(tau)= %le ", tau, s);

    tau+=0.1;
    }


    printf("\n Enter 'y' to exit \n");
    scanf("%s",&key);
    if(key!='y') goto label1;
    return 0;
    }

    7 августа 2016 г. 17:55
  • //y(t )=integral(  t0;t1 ; x1(t)*x2(t-tau ) ;d tau)
    //func(tau,t)=x1(t)*x2(t-tau)

    //x1(t)*x2(t-tau )=f(difarg, params), difarg=tau, param=t

    class Parser1_tag

    {


    private:
           double func(  double t, double tau, double (*x1)(double ), double (*x2)(double )  );
           double getIntegral(double a,double b,double eps, double(*func) (double , double )) ;
    public:
           double GetCorrelation(double (*s1)(double ), double (*s2)(double  ));

     Parser1_tag();
    ~ Parser1_tag();

    };

    double Parser1_tag::func(  double difarg, double param, double (*x1)(double ), double (*x2)(double )  )
          {
           //difarg=tau
           //param=t
     
          return  x1(param)*x2(param-difarg);
          }

    double Parser1_tag::getIntegral(
     double a,double b, 
     double(*func) (double  , double  , double (*x1)(double ), double (*x2)(double )  ),
     double param, double eps
     )


    {
     double h1,s,s0,s1,sn, t, arg;
     int i,n;
     s=1;
     sn=101;
     n=4;
     arg=((a+b)/2);

     s0=(func(a,t,x1,x2)+func(b,t, x1,x2 ))/2;
     s1=f(arg,t, x1,x2);

     while (fabs(s-sn)>eps){
     sn=s;
     h1=(b-a)/n;
     for (i=0; i<n/2; i++)
    {
    arg=(a+(2*i+1)*h1);

     s1+=func(arg,t, x1,x2);
    }
     s=h1*(s0+s1);
     n*=2;
     }
     return s;

    }


    double Parser1_tag::GetCorrelation(double (*s1)(double ), double (*s2)(double ) , double t1, double t2, double t  )
    {
    //t1=0
    //t2=10 ms
    //tau=100 us
    //B(t )=integral(  t0;t1 ; (x1(t)*x2(t-tau )), t ;d tau)

    return getIntegral(t1,t2,, Parser1_tag::func (tau , t, s1,s2   ), t , 0.00001);

    }


    //s1(t)=
    //s2(t)=

    //GetCorrelation(s1(t), s2(t),  t1, t2  )

    How to use double(*func) (double  , double  , double (*x1)(double ), double (*x2)(double )  ) in GetIntegral to inject functions double (*x1)(double ), double (*x2)(double ) into integral in getIntegral  ?

    7 августа 2016 г. 17:57
  • How to use this->func(  double difarg, double param, double (*x1)(double ), double (*x2)(double )  ) in this program for alternative method of parsing of double CCFParser_tag::getCCF ?

    7 августа 2016 г. 18:00
  • How to create array of classes CCFParser_tag *CCF with same signal x1(t)   and array of modifyed with array of methods of another class signal x2[i](t)  , created from x2(t)    for example, using array  of FIR filters  -denoisers     ? 
    7 августа 2016 г. 18:05