public ButterworthFusedYoVariable(String name, YoVariableRegistry yoVariableRegistry, DoubleYoVariable alphaVariable, DoubleYoVariable slowSignal, DoubleYoVariable fastSignal) { super(name, yoVariableRegistry); lowPassFilteredSlowVariable = new ButterworthFilteredYoVariable(name + "lowPass", yoVariableRegistry, alphaVariable, slowSignal, ButterworthFilterType.LOW_PASS); highPassFilteredFastVariable = new ButterworthFilteredYoVariable(name + "highPass", yoVariableRegistry, alphaVariable, fastSignal, ButterworthFilterType.HIGH_PASS); }
private static double[][] getFilteredCurve(double[][] input, ButterworthFilteredYoVariable butterworthFilteredYoVariable) { double[][] filteredCurve = new double[2][input[0].length]; butterworthFilteredYoVariable.reset(); for (int i = 0; i < input[0].length; i++) { butterworthFilteredYoVariable.update(input[1][i]); filteredCurve[0][i] = input[0][i]; filteredCurve[1][i] = butterworthFilteredYoVariable.getDoubleValue(); } return filteredCurve; }
private static double getMagnitudeInDecibels(double[][] input, double[][] output) { double inputAmp = getMaximumPeaktoPeakAmplitude(input); double outputAmp = getMaximumPeaktoPeakAmplitude(output); double attenuation = outputAmp / inputAmp; // System.out.println("attenuation=" + attenuation); double dB = 20.0 * Math.log10(attenuation); return dB; }
public void update() { lowPassFilteredSlowVariable.update(); highPassFilteredFastVariable.update(); set(lowPassFilteredSlowVariable.getDoubleValue() + highPassFilteredFastVariable.getDoubleValue()); }
private static double plotBodeForAlpha(double alpha, double deltaT) { YoVariableRegistry registry = new YoVariableRegistry("Test"); ButterworthFilteredYoVariable butterworthFilteredYoVariable = new ButterworthFilteredYoVariable("test", registry, alpha, ButterworthFilterType.LOW_PASS); double startFreq = 1e-2; double endFreq = 0.25 * (1.0 / deltaT); int numberOfTestPoints = 100; double deltaFreq = (endFreq - startFreq) / (numberOfTestPoints - 1); ArrayList<Double> testFrequencies = new ArrayList<Double>(); ArrayList<Double> attenuations = new ArrayList<Double>(); for (double freq = startFreq; freq <= endFreq; freq = freq + deltaFreq) { int numberOfCycles = 3; double endTime = (numberOfCycles) / freq; double[][] inputCurve = generateInputCurve(endTime, freq, deltaT); double[][] outputCurve = getFilteredCurve(inputCurve, butterworthFilteredYoVariable); double dB = getMagnitudeInDecibels(inputCurve, outputCurve); testFrequencies.add(freq); attenuations.add(dB); } @SuppressWarnings("unused") ArrayList<Double> testFrequenciesLog = convertToLog(testFrequencies); double breakFreq = getBreakFreq(testFrequencies, attenuations); return breakFreq; }
public static void testButterWorth() { YoVariableRegistry registry = new YoVariableRegistry("Test"); double alpha = .99; ButterworthFilteredYoVariable butterworthFilteredYoVariable = new ButterworthFilteredYoVariable("test", registry, alpha, ButterworthFilterType.LOW_PASS); double freq; int numberOfCycles; double endTime; @SuppressWarnings("unused") int numberOfElements; freq = 1.0; numberOfCycles = 3; endTime = (numberOfCycles) / freq; double deltaT = 0.002; numberOfElements = (int) Math.ceil(endTime / deltaT) + 1; ArrayList<double[][]> listOfXYCurves = new ArrayList<double[][]>(); double[][] inputCurve; double[][] outputCurve; inputCurve = generateInputCurve(endTime, freq, deltaT); outputCurve = getFilteredCurve(inputCurve, butterworthFilteredYoVariable); double dB = getMagnitudeInDecibels(inputCurve, outputCurve); System.out.println("dB= " + dB); listOfXYCurves.add(inputCurve); listOfXYCurves.add(outputCurve); }
public static void main(String[] args) { // testButterWorth(); ArrayList<Double> alphas = new ArrayList<Double>(); ArrayList<Double> breakFreqs = new ArrayList<Double>(); ArrayList<Double> alphasCalculated = new ArrayList<Double>(); double deltaT = 0.002; for (double alpha = 0.1; alpha <= 0.9; alpha = alpha + 0.1) { double breakFreq = plotBodeForAlpha(alpha, deltaT); alphas.add(alpha); breakFreqs.add(breakFreq); double alphaCalculated = computeAlphaGivenBreakFrequency(breakFreq, deltaT); alphasCalculated.add(alphaCalculated); System.out.println("alpha= " + alpha + " , breakFreq= " + breakFreq + ", calculated alpha = " + alphaCalculated); } double[][] alphaActual = new double[2][alphas.size()]; double[][] alphaPredicted = new double[2][alphasCalculated.size()]; for (int i = 0; i < alphas.size(); i++) { alphaActual[0][i] = breakFreqs.get(i); alphaActual[1][i] = alphas.get(i); alphaPredicted[0][i] = breakFreqs.get(i); alphaPredicted[1][i] = alphasCalculated.get(i); } ArrayList<double[][]> listOfXYCurves = new ArrayList<double[][]>(); listOfXYCurves.add(alphaActual); listOfXYCurves.add(alphaPredicted); }
set(0.0); set(currentInput); set(alphaToUse * getDoubleValue() + 0.5 * (1.0 - alphaToUse) * (currentInput + previousInput.getDoubleValue())); set(alphaToUse * getDoubleValue() + 0.5 * (1.0 + alphaToUse) * (currentInput - previousInput.getDoubleValue()));
private static double plotBodeForAlpha(double alpha, double deltaT) { YoVariableRegistry registry = new YoVariableRegistry("Test"); ButterworthFilteredYoVariable butterworthFilteredYoVariable = new ButterworthFilteredYoVariable("test", registry, alpha, ButterworthFilterType.LOW_PASS); double startFreq = 1e-2; double endFreq = 0.25 * (1.0 / deltaT); int numberOfTestPoints = 100; double deltaFreq = (endFreq - startFreq) / (numberOfTestPoints - 1); ArrayList<Double> testFrequencies = new ArrayList<Double>(); ArrayList<Double> attenuations = new ArrayList<Double>(); for (double freq = startFreq; freq <= endFreq; freq = freq + deltaFreq) { int numberOfCycles = 3; double endTime = (numberOfCycles) / freq; double[][] inputCurve = generateInputCurve(endTime, freq, deltaT); double[][] outputCurve = getFilteredCurve(inputCurve, butterworthFilteredYoVariable); double dB = getMagnitudeInDecibels(inputCurve, outputCurve); testFrequencies.add(freq); attenuations.add(dB); } @SuppressWarnings("unused") ArrayList<Double> testFrequenciesLog = convertToLog(testFrequencies); double breakFreq = getBreakFreq(testFrequencies, attenuations); return breakFreq; }
public static void testButterWorth() { YoVariableRegistry registry = new YoVariableRegistry("Test"); double alpha = .99; ButterworthFilteredYoVariable butterworthFilteredYoVariable = new ButterworthFilteredYoVariable("test", registry, alpha, ButterworthFilterType.LOW_PASS); double freq; int numberOfCycles; double endTime; @SuppressWarnings("unused") int numberOfElements; freq = 1.0; numberOfCycles = 3; endTime = (numberOfCycles) / freq; double deltaT = 0.002; numberOfElements = (int) Math.ceil(endTime / deltaT) + 1; ArrayList<double[][]> listOfXYCurves = new ArrayList<double[][]>(); double[][] inputCurve; double[][] outputCurve; inputCurve = generateInputCurve(endTime, freq, deltaT); outputCurve = getFilteredCurve(inputCurve, butterworthFilteredYoVariable); double dB = getMagnitudeInDecibels(inputCurve, outputCurve); System.out.println("dB= " + dB); listOfXYCurves.add(inputCurve); listOfXYCurves.add(outputCurve); }
public void update() { lowPassFilteredSlowVariable.update(); highPassFilteredFastVariable.update(); set(lowPassFilteredSlowVariable.getDoubleValue() + highPassFilteredFastVariable.getDoubleValue()); }
public static void main(String[] args) { // testButterWorth(); ArrayList<Double> alphas = new ArrayList<Double>(); ArrayList<Double> breakFreqs = new ArrayList<Double>(); ArrayList<Double> alphasCalculated = new ArrayList<Double>(); double deltaT = 0.002; for (double alpha = 0.1; alpha <= 0.9; alpha = alpha + 0.1) { double breakFreq = plotBodeForAlpha(alpha, deltaT); alphas.add(alpha); breakFreqs.add(breakFreq); double alphaCalculated = computeAlphaGivenBreakFrequency(breakFreq, deltaT); alphasCalculated.add(alphaCalculated); System.out.println("alpha= " + alpha + " , breakFreq= " + breakFreq + ", calculated alpha = " + alphaCalculated); } double[][] alphaActual = new double[2][alphas.size()]; double[][] alphaPredicted = new double[2][alphasCalculated.size()]; for (int i = 0; i < alphas.size(); i++) { alphaActual[0][i] = breakFreqs.get(i); alphaActual[1][i] = alphas.get(i); alphaPredicted[0][i] = breakFreqs.get(i); alphaPredicted[1][i] = alphasCalculated.get(i); } ArrayList<double[][]> listOfXYCurves = new ArrayList<double[][]>(); listOfXYCurves.add(alphaActual); listOfXYCurves.add(alphaPredicted); }
set(0.0); set(currentInput); set(alphaToUse * getDoubleValue() + 0.5 * (1.0 - alphaToUse) * (currentInput + previousInput.getDoubleValue())); set(alphaToUse * getDoubleValue() + 0.5 * (1.0 + alphaToUse) * (currentInput - previousInput.getDoubleValue()));
private static double[][] getFilteredCurve(double[][] input, ButterworthFilteredYoVariable butterworthFilteredYoVariable) { double[][] filteredCurve = new double[2][input[0].length]; butterworthFilteredYoVariable.reset(); for (int i = 0; i < input[0].length; i++) { butterworthFilteredYoVariable.update(input[1][i]); filteredCurve[0][i] = input[0][i]; filteredCurve[1][i] = butterworthFilteredYoVariable.getDoubleValue(); } return filteredCurve; }
public void update(double slowSignalVal, double fastSignalVal) { lowPassFilteredSlowVariable.update(slowSignalVal); highPassFilteredFastVariable.update(fastSignalVal); set(lowPassFilteredSlowVariable.getDoubleValue() + highPassFilteredFastVariable.getDoubleValue()); } }
public ButterworthFusedYoVariable(String name, YoVariableRegistry yoVariableRegistry, YoDouble alphaVariable, YoDouble slowSignal, YoDouble fastSignal) { super(name, yoVariableRegistry); lowPassFilteredSlowVariable = new ButterworthFilteredYoVariable(name + "lowPass", yoVariableRegistry, alphaVariable, slowSignal, ButterworthFilterType.LOW_PASS); highPassFilteredFastVariable = new ButterworthFilteredYoVariable(name + "highPass", yoVariableRegistry, alphaVariable, fastSignal, ButterworthFilterType.HIGH_PASS); }
private static double getMagnitudeInDecibels(double[][] input, double[][] output) { double inputAmp = getMaximumPeaktoPeakAmplitude(input); double outputAmp = getMaximumPeaktoPeakAmplitude(output); double attenuation = outputAmp / inputAmp; // System.out.println("attenuation=" + attenuation); double dB = 20.0 * Math.log10(attenuation); return dB; }
public void update(double slowSignalVal, double fastSignalVal) { lowPassFilteredSlowVariable.update(slowSignalVal); highPassFilteredFastVariable.update(fastSignalVal); set(lowPassFilteredSlowVariable.getDoubleValue() + highPassFilteredFastVariable.getDoubleValue()); } }
public ButterworthFusedYoVariable(String name, YoVariableRegistry yoVariableRegistry, double alpha) { super(name, yoVariableRegistry); lowPassFilteredSlowVariable = new ButterworthFilteredYoVariable(name + "lowPass", yoVariableRegistry, alpha, ButterworthFilterType.LOW_PASS); highPassFilteredFastVariable = new ButterworthFilteredYoVariable(name + "highPass", yoVariableRegistry, alpha, ButterworthFilterType.HIGH_PASS); }
public ButterworthFusedYoVariable(String name, YoVariableRegistry yoVariableRegistry, double alpha) { super(name, yoVariableRegistry); lowPassFilteredSlowVariable = new ButterworthFilteredYoVariable(name + "lowPass", yoVariableRegistry, alpha, ButterworthFilterType.LOW_PASS); highPassFilteredFastVariable = new ButterworthFilteredYoVariable(name + "highPass", yoVariableRegistry, alpha, ButterworthFilterType.HIGH_PASS); }