AWeighting { public static double[] aWeightingSignal(double[] inputSignal) { int signalLength = inputSignal.length; int order = Math.max(denominator.length, numerator.length); double[] weightedSignal = new double[signalLength]; double[][] z = new double[order-1][signalLength]; for (int idT = 0; idT < signalLength; idT++){ weightedSignal[idT] = numerator[0]*inputSignal[idT] + (idT == 0 ? 0 : z[0][idT-1]); z[0][idT] = numerator[1]*inputSignal[idT] + (idT == 0 ? 0 : z[1][idT-1]) - denominator[1]*inputSignal[idT]; for (int k = 0; k<order-2; k++){ z[k][idT] = numerator[k+1]*inputSignal[idT] + (idT ==0 ? 0 : z[k+1][idT-1]) - denominator[k+1]*weightedSignal[idT]; } z[order-2][idT] = numerator[order-1]*inputSignal[idT] - denominator[order-1]*weightedSignal[idT]; } return weightedSignal; }  static double[] aWeightingSignal(double[] inputSignal); static float[] aWeightingSignal(float[] inputSignal); final static double[] denominator; final static double[] numerator; }
@Test public void testAWeighting() throws IOException, UnsupportedAudioFileException { Scanner scanExpectedData = new Scanner(new File("src/test/resources/org/orbisgis/sos/pinknoise_1s_A_weighted.txt")); List<Double> expectedData = new ArrayList(); int nbExpectedSamples = 0; while (scanExpectedData.hasNext()) { expectedData.add(Double.parseDouble(scanExpectedData.next())); nbExpectedSamples++; } scanExpectedData.close(); double[] expectedAWeightedSignal = new double[nbExpectedSamples]; for (int idT = 0; idT < nbExpectedSamples; idT++) { expectedAWeightedSignal[idT] = expectedData.get(idT).doubleValue(); } Scanner scanAudio = new Scanner(new File("src/test/resources/org/orbisgis/sos/pinknoise_1s.txt")); List<Double> audioSignal = new ArrayList(); int nbActualSamples = 0; while (scanAudio.hasNext()) { audioSignal.add(Double.parseDouble(scanAudio.next())); nbActualSamples++; } scanAudio.close(); double[] audioSignalArr = new double[nbActualSamples]; for (int idT = 0; idT < nbActualSamples; idT++) { audioSignalArr[idT] = audioSignal.get(idT); } double[] actualAWeightedSignal = AWeighting.aWeightingSignal(audioSignalArr); Assert.assertEquals(expectedAWeightedSignal.length, actualAWeightedSignal.length); Assert.assertArrayEquals(expectedAWeightedSignal, actualAWeightedSignal, 0); }