首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法解析符号“Lowpassfilter”

无法解析符号“Lowpassfilter”
EN

Stack Overflow用户
提问于 2017-02-10 14:14:47
回答 1查看 342关注 0票数 1

我一直在使用http://www.ssaurel.com/blog/learn-how-to-make-a-compass-application-for-android/网站上的指南针代码。实际上,我是一个新开发的指南针应用程序,我得到了一个错误,无法解析符号'LowPassFilter‘。我已经导入了所有可能的文件,但仍然存在相同的错误

代码语言:javascript
复制
@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
}
EN

回答 1

Stack Overflow用户

发布于 2017-02-10 14:25:07

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

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42152668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档