Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private double[] data;
- private boolean[] neg;
- //private double[] tmpData = null;
- int quantitation, frequenzy;
- public SpectrumAnalysis(int Quantitation, int Frequenzy, int accuracyMS, float distancePercent, double[] Data , byte toleranceFactor){
- System.out.println(" length: " + Data.length);
- assert(distancePercent > 0 && distancePercent < 100);
- frequenzy = Frequenzy; quantitation = Quantitation;
- data = new double[Data.length];
- neg = new boolean[Data.length];
- double distanceAbs = ((1 << Quantitation) / (100 / distancePercent));
- System.out.println(distanceAbs);
- float frequenzyMS = Frequenzy/1000f;
- //int length = data.length / frequenzyMS;
- //wipe out negative values before analyzing
- //safing the negatives to revert this when give back to user
- for(int i = 0; i < data.length;i++){
- if(Data[i] < 0) {
- data[i] = (byte)-Data[i];
- neg[i] = true;
- } else{
- data[i] = Data[i];
- neg[i] = false;
- }
- }
- int spectresize = (int)(accuracyMS*frequenzyMS);
- double[] tmp = new double[spectresize];
- boolean isChanging = true;
- double currentDistance = 0, pointchanging = 0, avgVal = 0;
- byte toleranceFacCtr = 0;
- for(int i = 0, j = 0; i <= data.length;i++,j++){
- //lastDistance = currentDistance;
- if(j < spectresize && i < data.length) tmp[j] = data[i];
- else {
- currentDistance = avgVal;
- avgVal = avg(tmp);
- currentDistance = abs(avgVal - currentDistance);
- if(currentDistance <= distanceAbs) {
- toleranceFacCtr = toleranceFacCtr < toleranceFactor ? ++toleranceFacCtr : toleranceFactor;
- System.out.println(toleranceFacCtr);
- if(toleranceFacCtr == toleranceFactor) {
- if (isChanging) pointchanging = i;
- System.out.println(" distance: " + currentDistance);
- System.out.println(" avgval: " + avgVal);
- System.out.println(" was not changing at: " + i);
- isChanging = false;
- }
- }
- else {
- toleranceFacCtr = 0;
- }
- j = 0;
- }
- }
- }
- private double abs(double i){return i < 0 ? -i : i;}
- private double avg(double[] data){
- int tmp = 0;
- for(int i = 0; i < data.length;i++){
- tmp += data[i];
- }
- return tmp / data.length;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement