Example #1
0
void DelayDetection::putData(SFLDataFormat *inputData, int nbSamples)
{
    // Machine may already got a spkr and is waiting for mic or computing correlation
    if (nbSpkrSampleStored_ == WINDOW_SIZE)
        return;

    if ((nbSpkrSampleStored_ + nbSamples) > WINDOW_SIZE)
        nbSamples = WINDOW_SIZE - nbSpkrSampleStored_;

    if (nbSamples) {

        float tmp[nbSamples];
        float down[nbSamples];

        convertInt16ToFloat32(inputData, tmp, nbSamples);
        memcpy(spkrReference_ + nbSpkrSampleStored_, tmp, nbSamples * sizeof(float));

        downsampleData(tmp, down, nbSamples, downsamplingFactor_);
        bandpassFilter(down, nbSamples / downsamplingFactor_);
        memcpy(spkrReferenceDown_+ (nbSpkrSampleStored_ / downsamplingFactor_), down, (nbSamples / downsamplingFactor_) * sizeof(float));

        nbSpkrSampleStored_ += nbSamples;
    }

    // Update the state
    internalState_ = WaitForMic;
}
Example #2
0
/* calculate enhanced psd and return preview
* used for protocol preprocess_particles*/
PyObject *
xmipp_bandPassFilter(PyObject *obj, PyObject *args, PyObject *kwargs)
{
    PyObject *pyStrFn, *pyImage;
    double w1, w2, raised_w;
    int dim;
    FileName fn;

    if (PyArg_ParseTuple(args, "OOdddi", &pyImage, &pyStrFn, &w1, &w2, &raised_w, &dim))
    {
        FILTER_TRY()
        bandpassFilter(data, w1, w2, raised_w);
        FILTER_CATCH()
    }
Example #3
0
void shakeData::loadKNET(string filename)
{
	file=filename;
	ifstream input(ofToDataPath(file).c_str());
	string buffer;
	int lineCount=0;
	double scale;
	double averg=0;
	vector<double> val;
	while(lineCount<18){
		getline(input, buffer);
		string result;
		KNETresults rslt=getVal(buffer,result);
		switch(rslt){
			case FREQ:
				sampFreq=ofToInt(result);
				break;
			case SCALE_AMOUNT:
				scale=ofToInt(result.substr(0,result.find_first_of("(")));
				scale/=ofToInt(result.substr(result.find_last_of("/")+1));
				break;
			case MAX_ACCEL:
				break;
			default:
				break;
		}
		lineCount++;
	}
	while(!input.eof()){
		getline(input, buffer);
		for(int i=0; i<8; i++){
			if(buffer.length()>(i+1)*9){
				val.push_back(ofToInt(buffer.substr(i*9,9)));
			}
		}
	}
	input.close();
	double a1,a0;
	linearRegression(val,a1,a0);
	for(unsigned int i=0; i<val.size(); i++){
		val[i]-=a0+a1*i;
		val[i]*=scale;
	}
	bandpassFilter(val,sampFreq,3);
	for(unsigned int i=0; i<val.size(); i++){
		uData.push_back(dataPoint(val[i],1/sampFreq));
	}
	processData();
}
Example #4
0
uint16_t stepDetector(pedometer_data_t data[], uint16_t dataLen) {
	
  // Create new data object to contained normalized value
  fixed_t* normData = malloc(dataLen*sizeof(fixed_t));
  uint16_t i;
  for (i = 0; i < dataLen; i++) {

    // Norm is simply sum of squares, do not take sqrt for precision purposes and
    //  also subtract gravity
    normData[i] = sumSqrs(data[i]) - GRAVITY_OFFSET;
  }

  // Filter data with band pass filter, note modifies normData
  bandpassFilter(normData, dataLen);

  // Count and return steps
  uint16_t nSteps = countSteps(normData, dataLen);

  // Clean-up memory
  free(normData);

  return nSteps;
}