private void calcspectralDifference() {

		float[] spectrum = this.nextSpectrum();
		float[] lastSpectrum = new float[spectrum.length];
		// System.out.println("Spectrum length = " + spectrum.length);

		// while there are samples to read, we calculate the flux for each
		// window
		do {

			float flux = 0;
			for (int i = 0; i < spectrum.length; i++) {
				float value = (spectrum[i] - lastSpectrum[i]);
				// the negative values don't have interest
				if(!useSquare) {
					flux += value < 0 ? 0 : value;
				} else {
					flux += value < 0 ? 0 : value * value;
				}				
			}

			spectralDifference.add(flux);

			// the lastSpectrum in the following iteration is the
			// currentSpectrum of this iteration
			System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);

		} while ((spectrum = this.nextSpectrum()) != null);
	}