Package com.nr.sp

Examples of com.nr.sp.Spectreg


   

    // Test Hann
    System.out.println("Testing Hann");

    Spectreg sp=new Spectreg(M);
    Hann hann = new Hann(N);

    for (i=0;i<K;i++) {
      // Generate a data set
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64*j/N);
      sp.adddataseg(data,hann);
    }
    spec=sp.spectrum();
    freq=sp.frequencies();
//    for (i=0;i<M+1;i++)
//      System.out.printf(freq[i] << " " << spec[i]);

    maxs=-1.0;
    for (i=0;i<M+1;i++) {
      if (spec[i] > maxs) {
        maxf=freq[i];
        maxs=spec[i];
        maxi=i;
      }
    }

    sbeps=1.e-15;
    localflag=abs(maxf-0.25) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Hann: Spectrum maximum is at wrong frequency");
     
    }

    sbeps=1.e-5;
    localflag = false;
    for (i=2;i<10;i++) {
//      System.out.printf(spec[maxi+i]/maxs << " " << spec[maxi-i]/maxs);
      localflag = localflag || (spec[maxi+i]/maxs > sbeps);
      localflag = localflag || (spec[maxi-i]/maxs > sbeps);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Hann: Channels adjacent to maximum (starting at second) should be zero for Hann window");
     
    }
   
    Spectreg sp2=new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set offset by 1/2 channel in frequency
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64.5*j/N);
      sp2.adddataseg(data,hann);
    }
    spec=sp2.spectrum();
    freq=sp2.frequencies();
//    for (i=0;i<10;i++)
//      System.out.printf(spec[maxi-i]/maxs << " " << spec[maxi+i+1]/maxs);

    // test for symmetry
    sbeps=1.e-2;
View Full Code Here


    // Test bartlett
    System.out.println("Testing bartlett");
    BartlettWin bartlett = new BartlettWin();
   

    Spectreg sp =new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64*j/N);
      sp.adddataseg(data,bartlett);
    }
    spec=sp.spectrum();
    freq=sp.frequencies();
//    for (i=0;i<M+1;i++)
//      System.out.printf(freq[i] << " " << spec[i]);

    maxs=-1.0;
    for (i=0;i<M+1;i++) {
View Full Code Here

    // Test square
    System.out.println("Testing square");

    SquareWin square = new SquareWin();
    Spectreg sp = new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64*j/N);
      sp.adddataseg(data,square);
    }
    spec=sp.spectrum();
    freq=sp.frequencies();
//    for (i=0;i<M+1;i++)
//      System.out.printf(freq[i] << " %f\n", spec[i]);

    maxs=-1.0;
    for (i=0;i<M+1;i++) {
      if (spec[i] > maxs) {
        maxf=freq[i];
        maxs=spec[i];
        maxi=i;
      }
    }

    sbeps=1.e-15;
    localflag=abs(maxf-0.25) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** square: Spectrum maximum is at wrong frequency");
     
    }

    localflag = false;
    for (i=1;i<10;i++) {
      localflag = localflag || (spec[maxi+i]/maxs > sbeps);
      localflag = localflag || (spec[maxi-i]/maxs > sbeps);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** square: Channels adjacent to maximum should be zero for square window");
     
    }
   
    Spectreg sp2 = new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set offset by 1/2 channel in frequency
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64.5*j/N);
      sp2.adddataseg(data,square);
    }
    spec=sp2.spectrum();
    freq=sp2.frequencies();
//    for (i=0;i<10;i++)
//      System.out.printf(spec[maxi-i]/maxs << " %f\n", spec[maxi+i+1]/maxs);

    // test for symmetry
    sbeps=1.e-2;
View Full Code Here

   

    // Test welch
    System.out.println("Testing welch");
    WelchWin welch = new WelchWin();
    Spectreg sp = new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64*j/N);
      sp.adddataseg(data,welch);
    }
    spec=sp.spectrum();
    freq=sp.frequencies();
//    for (i=0;i<M+1;i++)
//      System.out.printf(freq[i] << " %f\n", spec[i]);

    maxs=-1.0;
    for (i=0;i<M+1;i++) {
      if (spec[i] > maxs) {
        maxf=freq[i];
        maxs=spec[i];
        maxi=i;
      }
    }

    sbeps=1.e-15;
    localflag=abs(maxf-0.25) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** welch: Spectrum maximum is at wrong frequency");
     
    }

    // Test symmetry
    sbeps=1.e-12;
    localflag = false;
    for (i=1;i<10;i++) {
//      System.out.printf(abs(spec[maxi+i]/spec[maxi-i]-1.0));
      localflag = localflag || abs(spec[maxi+i]/spec[maxi-i]-1.0) > sbeps;
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** welch: Channels adjacent to maximum should be symmetrical");
     
    }

    // Test amplitudes
    sbeps=1.e-2;
    localflag = false;
    for (i=2;i<6;i++) {
//      System.out.printf(abs(spec[maxi+i]/spec[maxi+1]*SQR(SQR(i))-1.0));
      localflag = localflag || abs(spec[maxi+i]/spec[maxi+1]*SQR(SQR(i))-1.0) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** welch: Sidelobe amplitudes are not in the correct proportion");
       
      }
    }

    Spectreg sp2 = new Spectreg(M);

    for (i=0;i<K;i++) {
      // Generate a data set offset by 1/2 channel in frequency
      for (j=0;j<N;j++)
        data[j]=cos(2.0*pi*64.5*j/N);
      sp2.adddataseg(data,welch);
    }
    spec=sp2.spectrum();
    freq=sp2.frequencies();
//    for (i=0;i<10;i++)
//      System.out.printf(spec[maxi-i]/maxs << " %f\n", spec[maxi+i+1]/maxs);

    sbeps=5.e-3;
    localflag=false;
View Full Code Here

   

    // Test Spectreg
    System.out.println("Testing Spectreg");
    Win window = new Win();
    Spectreg sp=new Spectreg(M);
    for (i=0;i<K;i++) {
      // Generate a data set
      for (j=0;j<N;j++) {
        data[j]=10.0*exp(-1.*SQR(j-M)/SQR(N/8))*
          (cos(2.0*pi*32*j/N)+cos(2.0*pi*64*j/N));
//        System.out.printf(data[j]);
      }
      sp.adddataseg(data,window);    // Note: text should clarify this usage
    }
    spec=sp.spectrum();
    freq=sp.frequencies();
//    for (i=0;i<M+1;i++)
//      System.out.printf(freq[i] << " %f\n", spec[i]);

    maxs=-1.0;
    j=0;
View Full Code Here

TOP

Related Classes of com.nr.sp.Spectreg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.