Normalization issue in Java - Android Studio -
i gathering 10 acceleration values on-board accelerometer on mobile device. attempting normalize these values between range of -1,1. unable figure out why isn't working correctly.
here normalization code:
class normutil { private double datahigh; private double datalow; private double normalizedhigh; private double normalizedlow; public normutil(double datahigh, double datalow) { this(datahigh, datalow, 1, -1); } public normutil(double datahigh, double datalow, double normalizedhigh, double normalizedlow) { this.datahigh = datahigh; this.datalow = datalow; this.normalizedhigh = normalizedhigh; this.normalizedlow = normalizedlow; } public double normalize(double e) { return ((e - datalow) / (datahigh - datalow)) * (normalizedhigh - normalizedlow) + normalizedlow; }
on button press, highest/lowest acceleration values found in code:
= enrolacc.get(0); b = enrolacc.get(0); (float i: enrolacc) { if(i < a) = i; if(i > b) b = i; }
once highest/lowest values found normutil instance created , instance used normalize array of acceleration values , add normalized values new array:
normutil norm = new normutil(b,a,1,-1); for(int j = 0; j < enrolacc.size(); j++) { double start = enrolacc.get(j); double x = norm.normalize(start); nacc[j] = x; }
this nacc array put string array , single string display in text view. issue text view initialized original non-normalized acceleration values, here code use that:
string normd[] = new string[10]; (int = 0; < 10; i++) { normd[i] = string.valueof(nacc[i]); } stringbuilder strbuilder2 = new stringbuilder(); (int = 0; i<normd.length; i++) { strbuilder2.append(normd[i] + ","); } normdata = strbuilder.tostring(); textnorm.settext("normalised: " + normdata);
so question is, going wrong adding normalized values normalized array , normalization method correct trying achieve? in advance.
Comments
Post a Comment