0

I am working on an android application which detect the hand shaking (through accelerometer) and it modulates the vibration frequency based on shaking intensity.

I am able to get the tremor intensity through standard deviation (code below):

public void regressionCalc() {
    //Calculating sum values
    double sumZ;
    double meanZ;
    sumZ = 0;

    final TextView accZText = (TextView) findViewById(R.id.accelText);
    accZText.setText("");

    for (int r = 0; r < recArray.length; r++) {
        sumZ = sumZ + recArray[r];
    }
    meanZ = sumZ/recArray.length;

    //Calculating standard deviation
    double sumXu2; //this represents E((x-xbar)^2)
    sumXu2 = 0;
    for (int x = 0; x < recArray.length; x++) {
        sumXu2 += ((recArray[x]-meanZ)*(recArray[x]-meanZ));
    }
    double SD;
    SD = Math.sqrt(sumXu2/(recArray.length-1));
    tremorIntensity = SD;

    accZText.setText(String.format("%.2f", tremorIntensity) + "");
    accZText.setTextSize(80);
}

but I don't know how to work with vibration. I mean, I would like the phone vibration intensity decrease or increase based on the regression value.

Could anyone address me to a correct way? Thanks in advance.

Paride Letizia
  • 330
  • 1
  • 4
  • 23
  • Possible duplicate of [How to make an Android device vibrate?](http://stackoverflow.com/questions/13950338/how-to-make-an-android-device-vibrate) – x-code Sep 04 '16 at 15:08
  • No, it is different because I am talking about modulate frequency on vibration intensity. Could you help me? – Paride Letizia Sep 05 '16 at 10:42

1 Answers1

0

The answer In my comment* shows how to make the device buzz according to a pattern:

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};
v.vibrate(pattern, -1);

Since you already have a value for shaking intensity, the rest of the problem is just using your intensity value to generate values for pattern.

On the hardware level the buzzer is just on or off, so deciding what kind of changes to pattern best simulate changing intensity is a matter of trial and error. It might be as simple as making each on value proportional to tremorIntensity:

long[] pattern = {0, tremorItensity * factor, 100}

*Here it is.

Community
  • 1
  • 1
x-code
  • 2,940
  • 1
  • 18
  • 19
  • First of all thank you for your response. The fact is that I have a single vale (2 or 5 or 12) and based on this value I have to make my phone vibrate. Imagine that hand shaking strong and then slower, the vibration has to decrease its frequency gradually with the hand shaking intensity. Does make it sense? – Paride Letizia Sep 05 '16 at 15:27
  • It makes a kind of sense but I am not going to know what pattern creates the effect desired, which is described variously as intensity or frequency in the question. So experiment with different patterns. – x-code Sep 05 '16 at 17:36
  • Exactly, I would like to know the exact pattern and I was hoping in your help – Paride Letizia Sep 06 '16 at 09:52
  • Which patterns did you experiment with? Show some work and describe a specific problem with what you have tried so far. – x-code Sep 06 '16 at 12:01