无法解析符号'Lowpassfilter'

时间:2017-02-10 06:14:47

标签: android compass

我一直在使用网站http://www.ssaurel.com/blog/learn-how-to-make-a-compass-application-for-android/中的Compass Code。 实际上我正在新开发一个罗盘应用程序我一直在收到错误无法解析符号'LowPassFilter'。我导入了所有可能的文件仍然是同样的错误

@Override
 public void onSensorChanged(SensorEvent event) {
  boolean accelOrMagnetic = false;

// get accelerometer data
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
  // we need to use a low pass filter to make data smoothed
  smoothed = **LowPassFilter**.filter(event.values, gravity);
  gravity[0] = smoothed[0];
  gravity[1] = smoothed[1];
  gravity[2] = smoothed[2];
  accelOrMagnetic = true;

} else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
  smoothed = **LowPassFilter**.filter(event.values, geomagnetic);
  geomagnetic[0] = smoothed[0];
  geomagnetic[1] = smoothed[1];
  geomagnetic[2] = smoothed[2];
  accelOrMagnetic = true;

}

// get rotation matrix to get gravity and magnetic data
SensorManager.getRotationMatrix(rotation, null, gravity, geomagnetic);
// get bearing to target
SensorManager.getOrientation(rotation, orientation);
 // east degrees of true North
 bearing = orientation[0];
 // convert from radians to degrees
 bearing = Math.toDegrees(bearing);

 // fix difference between true North and magnetical North
 if (geomagneticField != null) {
 bearing += geomagneticField.getDeclination();
 }

 // bearing must be in 0-360
 if (bearing < 0) {
  bearing += 360;
 }

 // update compass view
 compassView.setBearing((float) bearing);

 if (accelOrMagnetic) {
  compassView.postInvalidate();
 }

updateTextDirection(bearing); // display text direction on screen function
}

1 个答案:

答案 0 :(得分:0)

我在http://www.java2s.com/Open-Source/Android_Free_Code/Sensor/compass/com_jwetherell_compass_commonLowPassFilter_java.htm找到了答案。

package com.jwetherell.compass.common;
/* w  w  w  . j  a v a  2 s  .co m*/
/**
 * This class implements a low-pass filter. A low-pass filter is an electronic
 * filter that passes low-frequency signals but attenuates (reduces the
 * amplitude of) signals with frequencies higher than the cutoff frequency. The
 * actual amount of attenuation for each frequency varies from filter to filter.
 * It is sometimes called a high-cut filter, or treble cut filter when used in
 * audio applications.
 * 
 * @author Justin Wetherell (phishman3579@gmail.com)
 */
public class LowPassFilter {

    /*
     * Time smoothing constant for low-pass filter 0 ? ? ? 1 ; a smaller value
     * basically means more smoothing See:
     * http://en.wikipedia.org/wiki/Low-pass_filter#Discrete-time_realization
     */
    private static final float ALPHA = 0.2f;

    private LowPassFilter() {
    }

    /**
     * Filter the given input against the previous values and return a low-pass
     * filtered result.
     * 
     * @param input
     *            float array to smooth.
     * @param prev
     *            float array representing the previous values.
     * @return float array smoothed with a low-pass filter.
     */
    public static float[] filter(float[] input, float[] prev) {
        if (input == null || prev == null) throw new NullPointerException("input and prev float arrays must be non-NULL");
        if (input.length != prev.length) throw new IllegalArgumentException("input and prev must be the same length");

        for (int i = 0; i < input.length; i++) {
            prev[i] = prev[i] + ALPHA * (input[i] - prev[i]);
        }
        return prev;
    }
}