9 changed files with 249 additions and 28 deletions
-
4README.md
-
9src/main/java/a8k/appbean/OptScanDirection.java
-
49src/main/java/a8k/canbus/A8kCanBusService.java
-
10src/main/java/a8k/canbus/A8kModParamInitializer.java
-
1src/main/java/a8k/canbus/protocol/A8kEcode.java
-
15src/main/java/a8k/canbus/protocol/CmdId.java
-
77src/main/java/a8k/opt_algo/A8kOptAlgo.java
-
112src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java
-
BINzhaohe_app.db
@ -0,0 +1,9 @@ |
|||
package a8k.appbean; |
|||
|
|||
public enum OptScanDirection { |
|||
POSITIVE, NEGATIVE; |
|||
|
|||
public Integer getInteger() { |
|||
return this == POSITIVE ? 1 : -1; |
|||
} |
|||
} |
@ -0,0 +1,77 @@ |
|||
package a8k.opt_algo; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
public class A8kOptAlgo { |
|||
|
|||
static private List<Double> createDoubleList(int size) { |
|||
List<Double> list = new ArrayList<>(size); |
|||
for (int i = 0; i < size; i++) { |
|||
list.add(0.0); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
static private List<Double> integerToDouble(List<Integer> input) { |
|||
List<Double> output = new ArrayList<>(input.size()); |
|||
for (Integer i : input) { |
|||
output.add(i.doubleValue()); |
|||
} |
|||
return output; |
|||
} |
|||
|
|||
static private List<Integer> doubleToInteger(List<Double> input) { |
|||
List<Integer> output = new ArrayList<>(input.size()); |
|||
for (Double i : input) { |
|||
output.add(i.intValue()); |
|||
} |
|||
return output; |
|||
} |
|||
|
|||
static public List<Integer> preProcessOptData(List<Integer> input) { |
|||
List<Double> inputRaw = integerToDouble(input); |
|||
List<Double> upSamplingRaw = superSampling(inputRaw, 24); |
|||
List<Double> subSamplingRaw = subSampling(upSamplingRaw, 5); |
|||
return doubleToInteger(subSamplingRaw); |
|||
} |
|||
|
|||
|
|||
static public List<Double> superSampling(List<Double> input, Integer factor) { |
|||
int outputLength = input.size() * factor; |
|||
List<Double> upSamplingRaw = createDoubleList(outputLength); |
|||
|
|||
for (int si = 0, di = 0; si < input.size() - 1; di++) { |
|||
Double a = upSamplingRaw.set(di * factor, input.get(si)); |
|||
Double b = upSamplingRaw.set((di + 1) * factor, input.get(++si)); |
|||
|
|||
Double slope = (b - a) / factor; |
|||
|
|||
for (int i = 0; i < factor - 1; i++) { |
|||
int baseIndex = (di * factor) + i; |
|||
upSamplingRaw.set(baseIndex + 1, upSamplingRaw.get(baseIndex) + slope); |
|||
} |
|||
} |
|||
return upSamplingRaw; |
|||
} |
|||
|
|||
static public List<Double> subSampling(List<Double> inputRaw, Integer nSubSampleRate) { |
|||
int nSum = 0; |
|||
double fAvg = 0.0; |
|||
int subIndex = 0; |
|||
int nOutputLength = inputRaw.size() / nSubSampleRate; |
|||
|
|||
List<Double> subSampledRaw = createDoubleList(nOutputLength); |
|||
|
|||
for (int index = 0; index < inputRaw.size(); index++) { |
|||
if (index % nSubSampleRate == 0 && index > 0) { |
|||
fAvg = (double) nSum / nSubSampleRate; |
|||
subSampledRaw.set(subIndex++, fAvg); |
|||
nSum = 0; |
|||
} |
|||
nSum += inputRaw.get(index); |
|||
} |
|||
subSampledRaw.set(nOutputLength - 1, subSampledRaw.get(nOutputLength - 2)); |
|||
return subSampledRaw; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue