Beispiel #1
0
// the main function takes a single argument from the command line: the CSV file name
int main(int argc, char **argv) {
  char line[MAX_LINE_SIZE];
  struct vec3 data[MAX_VECTORS];
  double vert[MAX_VECTORS];
  double filtered[MAX_VECTORS];
  int data_len = 0;

  if(argc < 2) {
    puts("No file provided.");
    return -1;
  }

  int fd = open(argv[1], O_RDONLY);

  // throw away the header line
  _getline(fd, line, sizeof(line));

  // parse and load the vector data
  struct vec3 *ptr = data;
  while(_getline(fd, line, sizeof(line)) && data_len < MAX_VECTORS) {
    struct vec3 v = parse_vec3(line);
    //printf("x = %f, y = %f, z = %f\n", v.x, v.y, v.z);
    *ptr++ = v;
    data_len++;
  }
  
  printf("vectors read: %d\n", data_len);

  // calculate the gravity vector
  struct vec3 s = sum(data, data_len);
  double m = mag(s);
  //printf("mag = %f\n", m);
  struct vec3 g = scale(s, 1/m);
  printf("normalized gravity vector: %f %f %f\n", g.x, g.y, g.z);

  // reduce 3D data to 1D vertical acceleration
  for(int i = 0; i < data_len; i++) {
    vert[i] = dot(data[i], g);
    //printf("v = %f\n", vert[i]);
  }

  // bandpass filter 1-3 Hz
  filter(vert, data_len, filtered);

  //for(int i = 0; i < data_len; i++) printf("%f\n", filtered[i]);
  
  // calculate the thresholds
  double rms_val = rms(filtered, data_len);
  printf("rms: %f\n", rms_val);
  double threshold = rms_val * 0.5;

  // count the steps in the cleaned up signal
  int cnt = count_steps(filtered, data_len, threshold, -threshold);  
  printf("cnt: %d\n", cnt);

  return 0;
}
Beispiel #2
0
int sens_sens(CKTcircuit *ckt, int restart)
{
    SENS_AN	*sen_info = ((SENS_AN *) ckt->CKTcurJob);
    static int	size;
    static double	*delta_I, *delta_iI,
             *delta_I_delta_Y, *delta_iI_delta_Y;
    sgen		*sg;
    static double	freq;
    static int	nfreqs;
    static int	i;
    static SMPmatrix	*delta_Y = NULL, *Y;
    static double	step_size;
    double		*E, *iE;
    IFvalue		value, nvalue;
    double		*output_values;
    IFcomplex	*output_cvalues;
    double		delta_var;
    int		(*fn)( );
    static int	is_dc;
    int		k, j, n;
    int		num_vars, branch_eq;
    char		*sen_data;
    char		namebuf[513];
    IFuid		*output_names, freq_name;
    int		bypass;
    int		type;

#ifndef notdef
    double		*save_states[8];
#ifdef notdef
    for (sg = sgen_init(ckt, 0); sg; sgen_next(&sg)) {
        if (sg->is_instparam)
            printf("%s:%s:%s -> param %s\n",
                   DEVices[sg->dev]->DEVpublic.name,
                   sg->model->GENmodName,
                   sg->instance->GENname,
                   sg->ptable[sg->param].keyword);
        else
            printf("%s:%s:%s -> mparam %s\n",
                   DEVices[sg->dev]->DEVpublic.name,
                   sg->model->GENmodName,
                   sg->instance->GENname,
                   sg->ptable[sg->param].keyword);
    }
#endif
#ifdef ASDEBUG
    DEBUG(1)
    printf(">>> restart : %d\n", restart);
#endif

    /* get to work */

    restart = 1;
    if (restart) {

        freq = 0.0;
        is_dc = (sen_info->step_type == SENS_DC);
        nfreqs = count_steps(sen_info->step_type, sen_info->start_freq,
                             sen_info->stop_freq, sen_info->n_freq_steps,
                             &step_size);

        if (!is_dc)
            freq = sen_info->start_freq;

        error = CKTop(ckt,
                      (ckt->CKTmode & MODEUIC) | MODEDCOP | MODEINITJCT,
                      (ckt->CKTmode & MODEUIC) | MODEDCOP | MODEINITFLOAT,
                      ckt->CKTdcMaxIter);

#ifdef notdef
        ckt->CKTmode = (ckt->CKTmode & MODEUIC)
                       | MODEDCOP | MODEINITSMSIG;
#endif
        if (error)
            return error;

        size = spGetSize(ckt->CKTmatrix, 1);

        /* Create the perturbation matrix */
        /* XXX check error return, '1' is complex -- necessary?
         * only in ac */
        delta_Y = spCreate(size, !is_dc, &error);

        size += 1;

        /* Create an extra rhs */
        delta_I = NEWN(double, size);
        delta_iI = NEWN(double, size);

        delta_I_delta_Y = NEWN(double, size);
        delta_iI_delta_Y = NEWN(double, size);


        num_vars = 0;
        for (sg = sgen_init(ckt, is_dc); sg; sgen_next(&sg)) {
            num_vars += 1;
        }

        if (!num_vars)
            return OK;	/* XXXX Should be E_ something */

        k = 0;
        output_names = NEWN(IFuid, num_vars);
        for (sg = sgen_init(ckt, is_dc); sg; sgen_next(&sg)) {
            if (!sg->is_instparam) {
                sprintf(namebuf, "%s:%s",
                        sg->instance->GENname,
                        sg->ptable[sg->param].keyword);
            } else if ((sg->ptable[sg->param].dataType
                        & IF_PRINCIPAL) && sg->is_principle == 1)
            {
                sprintf(namebuf, "%s", sg->instance->GENname);
            } else {
                sprintf(namebuf, "%s_%s",
                        sg->instance->GENname,
                        sg->ptable[sg->param].keyword);
            }

            (*SPfrontEnd->IFnewUid)((GENERIC *) ckt,
                                    output_names + k, NULL,
                                    namebuf, UID_OTHER, NULL);
            k += 1;
        }

        if (is_dc) {
            type = IF_REAL;
            freq_name = NULL;
        } else {
            type = IF_COMPLEX;
            (*SPfrontEnd->IFnewUid)((GENERIC *) ckt,
                                    &freq_name, NULL,
                                    "frequency", UID_OTHER, NULL);
        }

        error = (*SPfrontEnd->OUTpBeginPlot)((GENERIC *) ckt,
                                             (GENERIC *) ckt->CKTcurJob,
                                             ckt->CKTcurJob->JOBname, freq_name, IF_REAL, num_vars,
                                             output_names, type, (GENERIC **) &sen_data);
        if (error)
            return error;

        FREE(output_names);
        if (is_dc) {
            output_values = NEWN(double, num_vars);
            output_cvalues = NULL;
        } else {
            output_values = NULL;
            output_cvalues = NEWN(IFcomplex, num_vars);
            if (sen_info->step_type != SENS_LINEAR)
                (*(SPfrontEnd->OUTattributes))((GENERIC *)sen_data,
                                               NULL, OUT_SCALE_LOG, NULL);

        }

    } else {