Exemple #1
1
void gmskframegen_write_tail(gmskframegen    _q,
                             float complex * _y)
{
    unsigned char bit = rand() % 2;
    gmskmod_modulate(_q->mod, bit, _y);

    // apply ramping window to last 'm' symbols
    if (_q->symbol_counter >= _q->m) {
        unsigned int i;
        for (i=0; i<_q->k; i++)
            _y[i] *= hamming(_q->m*_q->k + (_q->symbol_counter-_q->m)*_q->k + i, 2*_q->m*_q->k);
    }

    _q->symbol_counter++;

    if (_q->symbol_counter == _q->tail_len) {
        _q->symbol_counter = 0;
        _q->frame_complete = 1;
    }
}
double * C_FIR_filter::bp_FIR(int len, int hilbert, double f1, double f2)
{
    double *fir;
    double t, h, x;

    fir = new double[len];

    for (int i = 0; i < len; i++) {
        t = i - (len - 1.0) / 2.0;
        h = i * (1.0 / (len - 1.0));

        if (!hilbert) {
            x = (2 * f2 * sinc(2 * f2 * t) -
                 2 * f1 * sinc(2 * f1 * t)) * hamming(h);
        } else {
            x = (2 * f2 * cosc(2 * f2 * t) -
                 2 * f1 * cosc(2 * f1 * t)) * hamming(h);
// The actual filter code assumes the impulse response
// is in time reversed order. This will be anti-
// symmetric so the minus sign handles that for us.
            x = -x;
        }

        fir[i] = x;
    }

    return fir;
}
// create a matrix with hamming value
arma::mat makeHamming(int size)
{
	arma::mat hamming(1, size);
	for (int i = 0; i < size; i++)
		hamming(0, i) = 0.54 - 0.46 * cos(2 * Pi * i / size);
	return hamming;
}
// Help function to keep code base small
//  _kf     :   modulation factor
//  _type   :   demodulation type {LIQUID_FREQDEM_DELAYCONJ, LIQUID_FREQDEM_PLL}
void freqmodem_test(float               _kf,
                    liquid_freqdem_type _type)
{
    // options
    unsigned int num_samples = 1024;
    //float tol = 1e-2f;

    unsigned int i;

    // create mod/demod objects
    freqmod mod = freqmod_create(_kf);          // modulator
    freqdem dem = freqdem_create(_kf,_type);    // demodulator

    // allocate arrays
    float         m[num_samples];   // message signal
    float complex r[num_samples];   // received signal (complex baseband)
    float         y[num_samples];   // demodulator output

    // generate message signal (single-frequency sine)
    for (i=0; i<num_samples; i++)
        m[i] = 0.7f*cosf(2*M_PI*0.013f*i + 0.0f);

    // modulate/demodulate signal
    for (i=0; i<num_samples; i++) {
        // modulate
        freqmod_modulate(mod, m[i], &r[i]);

        // demodulate
        freqdem_demodulate(dem, r[i], &y[i]);
    }

    // delete modem objects
    freqmod_destroy(mod);
    freqdem_destroy(dem);

#if 0
    // compute power spectral densities and compare
    float complex mcf[num_samples];
    float complex ycf[num_samples];
    float complex M[num_samples];
    float complex Y[num_samples];
    for (i=0; i<num_samples; i++) {
        mcf[i] = m[i] * hamming(i,num_samples);
        ycf[i] = y[i] * hamming(i,num_samples);
    }
    fft_run(num_samples, mcf, M, LIQUID_FFT_FORWARD, 0);
    fft_run(num_samples, ycf, Y, LIQUID_FFT_FORWARD, 0);

    // run test: compare spectral magnitude
    for (i=0; i<num_samples; i++)
        CONTEND_DELTA( cabsf(Y[i]), cabsf(M[i]), tol );
#endif
}
Exemple #5
0
void crossmatch_hamming_count (const uint8 * dbs, int n, int ht, int ncodes, size_t * nptr)
{
  switch (ncodes) {
    case 4:  crossmatch_hamming_count_32 ((const uint32 *) dbs, n, ht, nptr);  return;
    case 8:  crossmatch_hamming_count_64 ((const uint64 *) dbs, n, ht, nptr);  return;
    case 16: crossmatch_hamming_count_128 ((const uint64 *) dbs, n, ht, nptr); return;
    default: fprintf (stderr, "# Warning: non-optimized version of crossmatch_hamming_count\n");
  }
  
  size_t i, j, posm = 0;
  const uint8 * bs1 = dbs;
  for (i = 0 ; i < n ; i++) {
    const uint8 * bs2 = bs1 + ncodes;
    
    for (j = i + 1 ; j < n ; j++) {
      /* collect the match only if this satisfies the threshold */
      if (hamming (bs1, bs2, ncodes) <= ht) 
        posm++;
      bs2 += ncodes;
    }
    bs1  += ncodes;  /* next signature */
  }
  
  *nptr = posm;
}
Exemple #6
0
void range_doppler_plot(vector<valarray<complex<double> > > &y,
		vector<double> &range, int Lfft, string filename )
{
//	int My = y.size();
	int Ny = y[0].size();
	vector<double> w = hamming(Ny);

	vector<valarray<complex<double> > > yp;
	vector< vector<double> > YdB;
	doppler_process(y, yp, w, Lfft);
	int M = yp.size();
	int N = yp[0].size();
	cout << yp.size() << " " << yp[0].size() << endl;

	double maxdb = 0.0;

	for(int i = 0; i < M; i++)
	{
		vector<double> YdBi;

		for(int j = 0; j < N; j++)
		{
			double val = db(yp[i][j], "power");
			if(val > maxdb)
				maxdb = val;
			YdBi.push_back(val);
		}
		YdB.push_back(YdBi);
	}

	cout << filename << ":  " << maxdb << endl;
	write_3d_data_plot(YdB, range, filename, false);
}
Exemple #7
0
/* That's the net channel capacity */
void write_payloadbit(unsigned char bit)
{
	static unsigned long accu=1;
	static unsigned long hamming_symbol;

	accu<<=1;
	accu|=bit&1;
	if (accu&(1UL<<FEC_SMALLBITS)){
		/* Full payload */
		int shift;

		/* Expands from FEC_SMALLBITS bits to FEC_LARGEBITS */
#if FEC_ORDER == 1
		accu=golay(accu);
#else
		accu=hamming(accu);
#endif /* FEC_ORDER */

		if (hamming_symbol>=FEC_SYMS){
			/* We couldn't write into the page, we need to make
			 * another one */
			new_file();
			hamming_symbol=0;
		}

		/* Write the symbol into the page */
		for (shift=FEC_LARGEBITS-1;shift>=0;shift--)
			write_channelbit(accu>>shift
				, hamming_symbol+(FEC_LARGEBITS-1-shift)
				*FEC_SYMS);
		accu=1;
		hamming_symbol++;
	}
Exemple #8
0
size_t crossmatch_hamming_prealloc (const uint8 * dbs, long n, int ht, 
                               int ncodes, int * idx, uint16 * hams)
{
  size_t i, j, posm = 0;
  uint16 h;
  const uint8 * bs1 = dbs;
  
  for (i = 0 ; i < n ; i++) {
    const uint8 * bs2 = bs1 + ncodes;
    
    for (j = i + 1 ; j < n ; j++) {
      /* Here perform the real work of computing the distance */
      h = hamming (bs1, bs2, ncodes);
      
      /* collect the match only if this satisfies the threshold */
      if (h <= ht) {
        /* Enough space to store another match ? */
        *idx = i; idx++;
        *idx = j; idx++;
        
        *hams = h;
        hams++;
        posm++;
      }
      bs2 += ncodes;
    }
    bs1 += ncodes;  /* next signature */
  }
  return posm;
}
Exemple #9
0
Fichier : fft.c Projet : Red54/WaoN
/* prepare window for FFT
 * INPUT
 *  n : # of samples for FFT
 *  flag_window : 0 : no-window (default -- that is, other than 1 ~ 6)
 *                1 : parzen window
 *                2 : welch window
 *                3 : hanning window
 *                4 : hamming window
 *                5 : blackman window
 *                6 : steeper 30-dB/octave rolloff window
 * OUTPUT
 *  density factor as RETURN VALUE
 */
double
init_den (int n, char flag_window)
{
  double den;
  int i;

  den = 0.0;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
	{
	case 1: // parzen window
	  den += parzen (i, n) * parzen (i, n);
	  break;

	case 2: // welch window
	  den += welch (i, n) * welch (i, n);
	  break;

	case 3: // hanning window
	  den += hanning (i, n) * hanning (i, n);
	  break;

	case 4: // hamming window
	  den += hamming (i, n) * hamming (i, n);
	  break;

	case 5: // blackman window
	  den += blackman (i, n) * blackman (i, n);
	  break;

	case 6: // steeper 30-dB/octave rolloff window
	  den += steeper (i, n) * steeper (i, n);
	  break;

	default:
	  fprintf (stderr, "invalid flag_window\n");
	case 0: // square (no window)
	  den += 1.0;
	  break;
	}
    }

  den *= (double)n;

  return den;
}
Exemple #10
0
// Generate polyphase coefficients for channeliser
float *generatePolyphaseCoefficients(unsigned nchans, unsigned ntaps, FirWindow windowType)
{
    unsigned n = nchans * ntaps;

    double* window = new double[n];

    switch (windowType) {
        case HAMMING:
        {
            hamming(n, window);
            break;
        }
        case BLACKMAN:
        {
            blackman(n, window);
            break;
        }
        case GAUSSIAN:
        {
            double alpha = 3.5;
            gaussian(n, alpha, window);
            break;
        }
        case KAISER:
        {
            double beta = 9.0695;
            kaiser(n, beta, window);
            break;
        }
        default:
        {
            fprintf(stderr, "Invalid PFB window type. Exiting\n");
            exit(-1);
        }
    }

    double* result = new double[n];
    generateFirFilter(n - 1, 1.0 / nchans, window, result);

    delete[] window;
    
    float *coeff = (float *) malloc(nchans * ntaps * sizeof(float));

    for(unsigned t = 0; t < ntaps; ++t) {
        for(unsigned c = 0; c < nchans; ++c) {
            unsigned index = t * nchans + c;
            coeff[index] = result[index] / nchans;
            if (c % 2 == 0)
                coeff[index] = result[index] / nchans;
            else
                coeff[index] = -result[index] / nchans;
        }
    }

    delete[] result;

    return coeff;

}
Exemple #11
0
SEXP R_match_hm(SEXP x, SEXP table, SEXP nomatch, SEXP matchNA, SEXP maxDistance){
  PROTECT(x);
  PROTECT(table);
  PROTECT(nomatch);
  PROTECT(matchNA);
  PROTECT(maxDistance);

  int nx = length(x), ntable = length(table);
  int no_match = INTEGER(nomatch)[0];
  int match_na = INTEGER(matchNA)[0];
  int max_dist = INTEGER(maxDistance)[0];


  // output vector
  SEXP yy;
  PROTECT(yy = allocVector(INTSXP, nx));
  int *y = INTEGER(yy);
  int *X, *T;


  double d = R_PosInf, d1 = R_PosInf;
  int nchar, index, xNA, tNA;

  for ( int i=0; i<nx; i++){
    index = no_match;
    nchar = length(VECTOR_ELT(x,i));

    X = INTEGER(VECTOR_ELT(x,i));
    xNA = (X[0] == NA_INTEGER);

    for ( int j=0; j<ntable; j++){
      if ( nchar != length(VECTOR_ELT(table,j)) ) continue;

      T = INTEGER(VECTOR_ELT(table,j));
      tNA = (T[0] == NA_INTEGER);

      if ( !xNA && !tNA ){        // both are char (usual case)
        d = (double) hamming(
          (unsigned int *) X,
          (unsigned int *) T,
          nchar,
          max_dist
        );
        if ( d > -1 && d < d1){ 
          index = j + 1;
          if ( d == 0.0 ) break;
          d1 = d;
        }
      } else if ( xNA && tNA ) {  // both are NA
        index = match_na ? j + 1 : no_match;
        break;
      }
    }
    
    y[i] = index;
  }  
  UNPROTECT(6);
  return(yy);
}
void ofdmoqamframe64sync_execute_plcplong1(ofdmoqamframe64sync _q, float complex _x)
{
    // cross-correlator
    float complex rxy;
    firfilt_cccf_push(_q->crosscorr, _x);
    firfilt_cccf_execute(_q->crosscorr, &rxy);

    rxy *= _q->g;

#if DEBUG_OFDMOQAMFRAME64SYNC
    windowcf_push(_q->debug_rxy, rxy);
#endif

    _q->timer++;
    if (_q->timer < _q->num_subcarriers-8) {
        return;
    } else if (_q->timer > _q->num_subcarriers+8) {
#if DEBUG_OFDMOQAMFRAME64SYNC_PRINT
        printf("warning: ofdmoqamframe64sync could not find second PLCP long sequence; resetting synchronizer\n");
#endif
        ofdmoqamframe64sync_reset(_q);
        return;
    }

    if (cabsf(rxy) > 0.7f*(_q->rxy_thresh)*(_q->num_subcarriers)) {
#if DEBUG_OFDMOQAMFRAME64SYNC_PRINT
        printf("rxy[1] : %12.8f at input[%3u]\n", cabsf(rxy), _q->num_samples);
#endif

        // 
        float complex * rc;
        windowcf_read(_q->input_buffer, &rc);
        memmove(_q->S1b, rc, 64*sizeof(float complex));

        // estimate frequency offset
        float complex rxy_hat=0.0f;
        unsigned int j;
        for (j=0; j<64; j++) {
            rxy_hat += _q->S1a[j] * conjf(_q->S1b[j]) * hamming(j,64);
        }
        float nu_hat1 = -cargf(rxy_hat);
        if (nu_hat1 >  M_PI) nu_hat1 -= 2.0f*M_PI;
        if (nu_hat1 < -M_PI) nu_hat1 += 2.0f*M_PI;
        nu_hat1 /= 64.0f;
#if DEBUG_OFDMOQAMFRAME64SYNC_PRINT
        printf("nu_hat[0] = %12.8f\n", _q->nu_hat);
        printf("nu_hat[1] = %12.8f\n", nu_hat1);
#endif
        nco_crcf_adjust_frequency(_q->nco_rx, nu_hat1);

        /*
        printf("exiting prematurely\n");
        ofdmoqamframe64sync_destroy(_q);
        exit(1);
        */
        _q->state = OFDMOQAMFRAME64SYNC_STATE_RXSYMBOLS;
    }

}
Exemple #13
0
 void print()
 {
     std::cout << toString();
     std::cout << "Dimension "<< dimension()<< '\n';
     std::cout << "is Goal "<< isGoal() << '\n';
     std::cout << "hamming "<< hamming() << '\n';
     std::cout << "manhattan " << manhattan() << '\n';
 }
Exemple #14
0
void print_frame() {
    int i;
    int nib = 0;
    int frid = -1;

    manchester1(frame_rawbits, frame_bits);

    deinterleave(frame_bits+CONF,  7, hamming_conf);
    deinterleave(frame_bits+DAT1, 13, hamming_dat1);
    deinterleave(frame_bits+DAT2, 13, hamming_dat2);

    hamming(hamming_conf,  7, block_conf);
    hamming(hamming_dat1, 13, block_dat1);
    hamming(hamming_dat2, 13, block_dat2);

    if (option_raw == 1) {

        for (i = 0; i < 7; i++) {
            nib = bits2val(block_conf+S*i, S);
            printf("%01X", nib & 0xFF);
        }
        printf("  ");
        for (i = 0; i < 13; i++) {
            nib = bits2val(block_dat1+S*i, S);
            printf("%01X", nib & 0xFF);
        }
        printf("  ");
        for (i = 0; i < 13; i++) {
            nib = bits2val(block_dat2+S*i, S);
            printf("%01X", nib & 0xFF);
        }
        printf("\n");

    }
    else {

        conf_out(block_conf);
        frid = dat_out(block_dat1);
        if (frid == 8) print_gpx();
        frid = dat_out(block_dat2);
        if (frid == 8) print_gpx();

    }

}
int main() {
    unsigned int m=5;           // filter semi-length
    float fc=0.2f;              // input tone frequency
    unsigned int N=128;         // number of input samples
    float As=60.0f;             // stop-band attenuation [dB]

    // create/print the half-band resampler, centered on
    // tone frequency with a specified stop-band attenuation
    resamp2_cccf f = resamp2_cccf_create(m,fc,As);
    resamp2_cccf_print(f);

    // open output file
    FILE*fid = fopen(OUTPUT_FILENAME,"w");
    fprintf(fid,"%% %s: auto-generated file\n",OUTPUT_FILENAME);
    fprintf(fid,"clear all;\nclose all;\n\n");
    fprintf(fid,"h_len=%u;\n", 4*m+1);
    fprintf(fid,"N=%u;\n", N);

    unsigned int i;
    float theta=0.0f, dtheta=2*M_PI*fc;
    float complex x, y[2];
    for (i=0; i<N; i++) {
        // generate input : complex sinusoid
        x = cexpf(_Complex_I*theta) * (i<N/2 ? 2.0f*1.8534f*hamming(i,N/2) : 0.0f);
        theta += dtheta;

        // run the interpolator
        resamp2_cccf_interp_execute(f, x, y);

        // save results to output file
        fprintf(fid,"x(%3u) = %12.4e + j*%12.4e;\n", i+1,   crealf(x),    cimagf(x));
        fprintf(fid,"y(%3u) = %12.4e + j*%12.4e;\n", 2*i+1, crealf(y[0]), cimagf(y[0]));
        fprintf(fid,"y(%3u) = %12.4e + j*%12.4e;\n", 2*i+2, crealf(y[1]), cimagf(y[1]));

        printf("y(%3u) = %8.4f + j*%8.4f;\n", 2*i+1, crealf(y[0]), cimagf(y[0]));
        printf("y(%3u) = %8.4f + j*%8.4f;\n", 2*i+2, crealf(y[1]), cimagf(y[1]));
    }

    fprintf(fid,"nfft=512;\n");
    fprintf(fid,"X=20*log10(abs(fftshift(fft(x/N,    nfft))));\n");
    fprintf(fid,"Y=20*log10(abs(fftshift(fft(y/(2*N),nfft))));\n");
    fprintf(fid,"f=[0:(nfft-1)]/nfft-0.5;\n");
    fprintf(fid,"figure; plot(f/2,X,'Color',[0.5 0.5 0.5],f,Y,'LineWidth',2);\n");
    fprintf(fid,"grid on;\n");
    fprintf(fid,"xlabel('normalized frequency');\n");
    fprintf(fid,"ylabel('PSD [dB]');\n");
    fprintf(fid,"legend('original','interpolated',1);");
    fprintf(fid,"axis([-0.5 0.5 -100 10]);\n");

    fclose(fid);
    printf("results written to %s\n",OUTPUT_FILENAME);

    // clean up allocated objects
    resamp2_cccf_destroy(f);
    printf("done.\n");
    return 0;
}
Exemple #16
0
/* Design FIR filter using the Window method

n     filter length must be odd for HP and BS filters
w     buffer for the filter taps (must be n long)
fc    cutoff frequencies (1 for LP and HP, 2 for BP and BS)
0 < fc < 1 where 1 <=> Fs/2
flags window and filter type as defined in filter.h
variables are ored together: i.e. LP|HAMMING will give a
low pass filter designed using a hamming window
opt   beta constant used only when designing using kaiser windows

returns 0 if OK, -1 if fail
*/
float* design_fir(unsigned int *n, float* fc, float opt)
{
    unsigned int  o   = *n & 1;              // Indicator for odd filter length
    unsigned int  end = ((*n + 1) >> 1) - o; // Loop end
    unsigned int  i;                         // Loop index

    float k1 = 2 * float(M_PI);              // 2*pi*fc1
    float k2 = 0.5f * (float)(1 - o);        // Constant used if the filter has even length
    float g  = 0.0f;                         // Gain
    float t1;                                // Temporary variables
    float fc1;                               // Cutoff frequencies

    // Sanity check
    if (*n==0) return nullptr;
    MathUtil::Clamp(&fc[0],float(0.001),float(1));

    float *w=(float*)calloc(sizeof(float),*n);

    // Get window coefficients
    hamming(*n,w);

    fc1=*fc;
    // Cutoff frequency must be < 0.5 where 0.5 <=> Fs/2
    fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25f;
    k1 *= fc1;

    // Low pass filter

    // If the filter length is odd, there is one point which is exactly
    // in the middle. The value at this point is 2*fCutoff*sin(x)/x,
    // where x is zero. To make sure nothing strange happens, we set this
    // value separately.
    if (o)
    {
        w[end] = fc1 * w[end] * 2.0f;
        g=w[end];
    }

    // Create filter
    for (i=0 ; i<end ; i++)
    {
        t1 = (float)(i+1) - k2;
        w[end-i-1] = w[*n-end+i] = float(w[end-i-1] * sin(k1 * t1)/(M_PI * t1)); // Sinc
        g += 2*w[end-i-1]; // Total gain in filter
    }


    // Normalize gain
    g=1/g;
    for (i=0; i<*n; i++)
        w[i] *= g;

    return w;
}
Exemple #17
0
void compute_hamming_thread (uint16 * dis, const uint8 * a, const uint8 * b, 
                             int na, int nb, int ncodes)
{
  size_t i, j;
#pragma omp parallel shared (dis, a, b, na, nb) private (i, j)
    {
#pragma omp for 
      for (j = 0 ; j < nb ; j++)
	      for (i = 0 ; i < na ; i++)
	        dis[j * na + i] = hamming (a + i * ncodes, b + j * ncodes, ncodes);
    }
}
Exemple #18
0
int main(int argc, char *argv[]) {
	if (argc != 3) { printf("HAMM <seq_1> <seq_2>\n"); exit(EXIT_FAILURE); }
	int ham = 0;

	char *seq1 = argv[1];
	char *seq2 = argv[2];

	ham = hamming(seq1, seq2);
	printf("%i\n", ham);

	return EXIT_SUCCESS;
}
Exemple #19
0
// arm-thumb
static void push_t1(uint16_t inst) {
	uint8_t register_list = inst & 0xff;
	bool M = (inst >> 8) & 0x1;

	uint16_t registers = register_list | (M << 14);

	if (hamming(registers) < 1)
		CORE_ERR_unpredictable("push_t1 case\n");

	OP_DECOMPILE("PUSH<c> <registers>", registers);
	return push(registers);
}
double
structure_based(cv::Mat *m, cv::Mat *n, BoundingBox *a, BoundingBox *b)
{
	const static double DIFF_PATTERN = 64;
	const static double DISTRO_RADIUS = 5;
	const static int NUM_POINTS = 1024;

	static int *bpa = (int*) calloc ((NUM_POINTS / (sizeof(int) * 8) + 1), sizeof(int));
	static int *bpb = (int*) calloc ((NUM_POINTS / (sizeof(int) * 8) + 1), sizeof(int));

	static std::vector<std::pair<int, int> > distribution = generate_distro(DISTRO_RADIUS, NUM_POINTS);

	double num_similar_pixels = 0;
	double num_total_pixels = 0;

	int dax = a->x2_ - a->x1_;
	int dbx = b->x2_ - b->x1_;
	int dx = (dax < dbx) ? dax : dbx;

	int day = a->y2_ - a->y1_;
	int dby = b->y2_ - b->y1_;
	int dy = (day < dby) ? day : dby;

	double dist_total = 0;

	for (int i = 0; i < dy; i++)
	{
		for (int j = 0; j < dx; j++)
		{
			int my = a->y1_ + i;
			int mx = a->x1_ + j;

			int ny = b->y1_ + i;
			int nx = b->x1_ + j;

			build_bit_pattern(m, mx, my, &distribution, bpa);
			build_bit_pattern(n, nx, ny, &distribution, bpb);

			int dist = hamming(bpa, bpb, NUM_POINTS);

			dist_total += dist;

			if (dist < DIFF_PATTERN)
				num_similar_pixels++;

			num_total_pixels++;
		}
	}

	//return num_similar_pixels / num_total_pixels;
	return dist_total / (double) num_total_pixels;
}
Exemple #21
0
 std::vector<SampleType> Window::get(std::size_t size, std::size_t type) {
     switch(type) {
         case HAMMING:
             return hamming(size);
         case BLACKMAN_HARRIS:
             return blackmanHarris(size);
         case HANN:
             return hann(size);
         case NONE:
         default:
             return none(size);
     }
 }
Exemple #22
0
int main() {
	/* Initialization */
	calc_shelving_coef();
	calc_hamming_coef();
	calc_bank_gain();
	twidfftrad2_fr32(twiddle_table, WINDOW_LENGTH);
	calc_dct_coef();
	/* /Initialization */

	int index;
	for (index = 0; index < TOTAL_LENGTH; index++) {
		input_fr[index] = float_to_fr32(test_input[index]);
	}

	pre_emphasis(input_fr, TOTAL_LENGTH);
	// printf("pre emphasis done\n");

	int frame_offset = 0;
	fract32 frame_data[WINDOW_LENGTH];
	int obs_length = 0;

	int frame_num;
	for (frame_num = 0; frame_num < FRAME_NUM; frame_num++) {
		for (index = 0; index < WINDOW_LENGTH; index++) {
			frame_data[index] = input_fr[index+frame_offset];
		}

		hamming(frame_data);

		float energy = calc_energy(frame_data, WINDOW_LENGTH);

		if (energy > 0.1) {
			float mfcc[FEAT_NUM] = {0.0};
			calc_mfcc(frame_data, mfcc_matrix[obs_length]);
			obs_length++;
		}
		frame_offset += WINDOW_LENGTH/2;
	}

	int feat_num;
	for (frame_num = 0; frame_num < obs_length; frame_num++) {
		for (feat_num = 0; feat_num < FEAT_NUM; feat_num++) {
			printf("%f\t", mfcc_matrix[frame_num][feat_num]);
		}
		printf("\n");
	}

	return 0;
}
Exemple #23
0
/*
 * Hamming window
 */
static VectorObject *
py_hamming(PyObject *self, PyObject *args)
{
    int N;
    VectorObject *out;

    if (!PyArg_ParseTuple(args, "i", &N) || N < 1) {
        PyErr_SetString(PyExc_ValueError, "argument must be a positive Integer");
        return NULL;
    }

    out = vector_new(N);
    hamming(N, out->data);

    return out;
}
Exemple #24
0
void pop(uint16_t registers) {
	uint32_t address = CORE_reg_read(SP_REG);

	int i;
	for (i = 0; i <= 14; i++) {
		if (registers & (1 << i)) {
			CORE_reg_write(i, read_word(address));
			address += 4;
		}
	}

	if (registers & (1 << 15)) {
		LoadWritePC(read_word(address));
	}

	CORE_reg_write(SP_REG, CORE_reg_read(SP_REG) + 4 * hamming(registers));
}
Exemple #25
0
void match_hamming_thres (const uint8 * bs1, const uint8 * bs2, 
                          int n1, int n2, int ht, int ncodes, size_t bufsize, 
                          hammatch_t ** hmptr, size_t * nptr)
{
  switch (ncodes) {
    case 4:  match_hamming_thres_32 ((const uint32 *) bs1, (const uint32 *) bs2, n1, n2, ht, bufsize, hmptr, nptr);  return;
    case 8:  match_hamming_thres_64 ((const uint64 *) bs1, (const uint64 *) bs2, n1, n2, ht, bufsize, hmptr, nptr);  return;
    case 16: match_hamming_thres_128 ((const uint64 *) bs1, (const uint64 *) bs2, n1, n2, ht, bufsize, hmptr, nptr); return;
    default: fprintf (stderr, "# Warning: non-optimized version of match_hamming_thres\n");
  }
  
  size_t i, j, posm = 0;
  uint16 h;
  *hmptr = hammatch_new (bufsize);
  hammatch_t * hm = *hmptr;
  const uint8 * bs2_ = bs2;
  
  for (i = 0 ; i < n1 ; i++) {
    bs2 = bs2_;
    for (j = 0 ; j < n2 ; j++) {
      /* Here perform the real work of computing the distance */
      h = hamming (bs1, bs2, ncodes);
    
      /* collect the match only if this satisfies the threshold */
      if (h <= ht) {
        /* Enough space to store another match ? */
        if (posm >= bufsize) {
          bufsize = HAMMATCH_REALLOC_NEWSIZE (bufsize);
          *hmptr = hammatch_realloc (*hmptr, bufsize);
          assert (*hmptr != NULL);
          hm = (*hmptr) + posm;
        }
        hm->qid = i;
        hm->bid = j;
        hm->score = h;
        hm++;
        posm++;
      }
      bs2 += ncodes;  /* next signature */
    }
    bs1 += ncodes;
  }
  
  *nptr = posm;
}
void liquid_doc_compute_psdcf(float complex * _x,
                              unsigned int _n,
                              float complex * _X,
                              unsigned int _nfft,
                              liquid_doc_psdwindow _wtype,
                              int _normalize)
{
    unsigned int i;

    // compute window and norm
    float w[_n];
    float wnorm=0.0f;
    for (i=0; i<_n; i++) {
        switch (_wtype) {
        case LIQUID_DOC_PSDWINDOW_NONE:     w[i] = 1.0f;            break;
        case LIQUID_DOC_PSDWINDOW_HANN:     w[i] = hann(i,_n);      break;
        case LIQUID_DOC_PSDWINDOW_HAMMING:  w[i] = hamming(i,_n);   break;
            break;
        default:
            fprintf(stderr,"error: liquid_doc_compute_psd(), invalid window type\n");
            exit(1);
        }
        wnorm += w[i];
    }
    wnorm /= (float)(_n);

    float complex x[_nfft];
    fftplan fft = fft_create_plan(_nfft,x,_X,FFT_FORWARD,0);
    for (i=0; i<_nfft; i++) {
        x[i] = i < _n ? _x[i] * w[i] / wnorm : 0.0f;

    }
    fft_execute(fft);
    fft_destroy_plan(fft);

    // normalize spectrum by maximum
    if (_normalize) {
        float X_max = 0.0f;
        for (i=0; i<_nfft; i++)
            X_max = cabsf(_X[i]) > X_max ? cabsf(_X[i]) : X_max;

        for (i=0; i<_nfft; i++)
            _X[i] /= X_max;
    }
}
Exemple #27
0
int main() {
    // options
    unsigned int nfft        =   64;    // transform size
    unsigned int num_frames  =  200;    // total number of frames
    unsigned int msdelay     =   50;    // delay between transforms [ms]
    float        noise_floor = -40.0f;  // noise floor

    // initialize objects
    asgramf q = asgramf_create(nfft);
    asgramf_set_scale(q, noise_floor+15.0f, 5.0f);

    unsigned int i;
    unsigned int n;
    float theta  = 0.0f;    // current instantaneous phase
    float dtheta = 0.0f;    // current instantaneous frequency
    float phi    = 0.0f;    // phase of sinusoidal frequency drift
    float dphi   = 0.003f;  // frequency of sinusoidal frequency drift

    float nstd = powf(10.0f,noise_floor/20.0f);  // noise standard deviation
    for (n=0; n<num_frames; n++) {
        // generate a frame of data samples
        for (i=0; i<nfft; i++) {
            // cosine wave of time-varying frequency with noise
            float x = cosf(theta) + nstd*randnf();

            // push sample into spectrogram object
            asgramf_push(q, x);

            // adjust frequency and phase
            theta  += dtheta;
            dtheta =  0.5f*M_PI + 0.4f*M_PI*sinf(phi) * hamming(n, num_frames);
            phi    += dphi;
        }

        // print the spectrogram to stdout
        asgramf_print(q);

        // sleep for some time before generating the next frame
        usleep(msdelay*1000);
    }

    asgramf_destroy(q);
    printf("done.\n");
    return 0;
}
//-----------------------------------------------------------------------------
// name: init()
// desc: ...
//-----------------------------------------------------------------------------
t_CKBOOL AudicleFaceVMSpace::init( )
{
    if( !AudicleFace::init() )
        return FALSE;

    // set the buffer_size
    g_buffer_size = Digitalio::m_buffer_size;
    // set the channels
    g_num_channels = Digitalio::m_num_channels_out;
    // allocate buffers
    g_out_buffer = new SAMPLE[g_buffer_size*g_num_channels];
    g_in_buffer = new SAMPLE[g_buffer_size*g_num_channels];
    g_buffer = new SAMPLE[g_buffer_size*g_num_channels];
    g_window = NULL;
    // set the buffer
    Digitalio::set_extern( g_in_buffer, g_out_buffer );
    g_rect = new SAMPLE[g_buffer_size];
    g_hamm = new SAMPLE[g_buffer_size];
    g_hann = new SAMPLE[g_buffer_size];
    // blackmann
    blackman( g_rect, g_buffer_size );
    // hanning
    hanning( g_hann, g_buffer_size );
    // hamming window
    hamming( g_hamm, g_buffer_size );
    g_window = g_hamm;

	g_spectrums = new Pt2D *[g_depth];
	for( int i = 0; i < g_depth; i++ )
	{
		g_spectrums[i] = new Pt2D[g_buffer_size];
		memset( g_spectrums[i], 0, sizeof(Pt2D)*g_buffer_size );
	}
	g_draw = new GLboolean[g_depth];
	memset( g_draw, 0, sizeof(GLboolean)*g_depth );
    
    m_name = "VM-Space";
    m_bg_speed = .2;
    
    g_id = IDManager::instance()->getPickID();
    g_id2 = IDManager::instance()->getPickID();

    return TRUE;
}
Exemple #29
0
double *xtract_init_window(const int N, const int type)
{
    double *window;

    window = malloc(N * sizeof(double));

    switch (type)
    {
    case XTRACT_GAUSS:
        gauss(window, N, 0.4);
        break;
    case XTRACT_HAMMING:
        hamming(window, N);
        break;
    case XTRACT_HANN:
        hann(window, N);
        break;
    case XTRACT_BARTLETT:
        bartlett(window, N);
        break;
    case XTRACT_TRIANGULAR:
        triangular(window, N);
        break;
    case XTRACT_BARTLETT_HANN:
        bartlett_hann(window, N);
        break;
    case XTRACT_BLACKMAN:
        blackman(window, N);
        break;
    case XTRACT_KAISER:
        kaiser(window, N, 3 * PI);
        break;
    case XTRACT_BLACKMAN_HARRIS:
        blackman_harris(window, N);
        break;
    default:
        hann(window, N);
        break;
    }

    return window;
}
Exemple #30
0
Fichier : fft.c Projet : Red54/WaoN
/* apply window function to data[]
 * INPUT
 *  flag_window : 0 : no-window (default -- that is, other than 1 ~ 6)
 *                1 : parzen window
 *                2 : welch window
 *                3 : hanning window
 *                4 : hamming window
 *                5 : blackman window
 *                6 : steeper 30-dB/octave rolloff window
 */
void
windowing (int n, const double *data, int flag_window, double scale,
	   double *out)
{
  int i;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
	{
	case 1: // parzen window
	  out [i] = data [i] * parzen (i, n) / scale;
	  break;

	case 2: // welch window
	  out [i] = data [i] * welch (i, n) / scale;
	  break;

	case 3: // hanning window
	  out [i] = data [i] * hanning (i, n) / scale;
	  break;

	case 4: // hamming window
	  out [i] = data [i] * hamming (i, n) / scale;
	  break;

	case 5: // blackman window
	  out [i] = data [i] * blackman (i, n) / scale;
	  break;

	case 6: // steeper 30-dB/octave rolloff window
	  out [i] = data [i] * steeper (i, n) / scale;
	  break;

	default:
	  fprintf (stderr, "invalid flag_window\n");
	case 0: // square (no window)
	  out [i] = data [i] / scale;
	  break;
	}
    }
}