Error[8]: Undefined offset: 1, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波. 我想避免的是手动比较数组中的每个值并做出决定. 我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波. 正如评论员@NeilForrester所指出的那样, FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用O 我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波.

我想避免的是手动比较数组中的每个值并做出决定.

我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波.

解决方法 正如评论员@NeilForrester所指出的那样,FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用Objective-C,Accelerate框架的 vDSP routines提供了一种直接的方法 – 由于使用了UnsafePointer和UnsafeMutablePointer参数,因此在Swift中并不那么简单.这是一个使用FFT的简单Swift示例.

import Foundationimport Acceleratepublic struct GFFT {    let size: Int    let halfSize: Int    let log2n: vDSP_Length    let twoOverSize: [float]    var weights: FFTSetup    init?(size: Int) {        self.size = size        self.log2n = vDSP_Length(log2(float(size)))        guard let weights = vDSP_create_fftsetup(log2n,FFTradix(kFFTradix2)) else {            print("Aargh in GFFT.fft - weights Failed")            return nil        }        self.halfSize = size / 2        self.twoOverSize = [2 / float(size)]        self.weights = weights    }    public func forward(realArray: [float]) -> (magnitude: [float],phase: [float]) {        assert(realArray.count == self.size,"Aargh in GFFT.forward - size mismatch")        var real = realArray // copy into var        var imag = GFFT.zeros(size)        var magnitudesSquared = GFFT.zeros(self.halfSize)        var magnitudes = GFFT.zeros(self.halfSize)        var normalizedMagnitudes = GFFT.zeros(self.halfSize)        var phases = GFFT.zeros(self.halfSize)        var splitComplex = DSPSplitComplex(realp: &real,imagp: &imag)        vDSP_fft_zip(self.weights,&splitComplex,1,self.log2n,FFTDirection(FFT_FORWARD))        vDSP_zvmags(&splitComplex,&magnitudesSquared,vDSP_Length(self.halfSize))        vvsqrtf(&magnitudes,[Int32(self.halfSize)])        vDSP_zvphas(&splitComplex,&phases,vDSP_Length(self.halfSize))        vDSP_vsmul(&magnitudes,self.twoOverSize,&normalizedMagnitudes,vDSP_Length(self.halfSize))        // you may choose to return magnitudesSquared,for the power        // magnitudes for the scaled amplitudes or         // normalizedMagnitudes for,well,normalised magnitude.        return (normalizedMagnitudes,phases)    }    private static func zeros(_ n: Int) -> [float] { return [float](repeating: 0,count: n) }}let testinput = (0 ..< 512).map {    return sin(float([+++]))}if let fft = GFFT(size: testinput.count) {    let (freq,phase) = fft.forward(realArray: testinput)    freq.map({[+++]})}

游乐场输出:

至于你测试什么,它将取决于你得到的实际输出,所以我会试验实际数据给你的东西,但你的测试应该是这样的:

>找到振幅的平均值>找到最大振幅>检查两者的比率(最大值/平均值)是否高>检查最大值的索引是否接近零(或者它可能是直流信号)>检查任何其他局部最大值(并且会有一些)远小于全局最大值.

总结

以上是内存溢出为你收集整理的数组 – 如何知道数组是否代表正弦波?全部内容,希望文章能够帮你解决数组 – 如何知道数组是否代表正弦波?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波. 我想避免的是手动比较数组中的每个值并做出决定. 我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波. 正如评论员@NeilForrester所指出的那样, FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用O 我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波.

我想避免的是手动比较数组中的每个值并做出决定.

我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波.

解决方法 正如评论员@NeilForrester所指出的那样,FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用Objective-C,Accelerate框架的 vDSP routines提供了一种直接的方法 – 由于使用了UnsafePointer和UnsafeMutablePointer参数,因此在Swift中并不那么简单.这是一个使用FFT的简单Swift示例.

import Foundationimport Acceleratepublic struct GFFT {    let size: Int    let halfSize: Int    let log2n: vDSP_Length    let twoOverSize: [float]    var weights: FFTSetup    init?(size: Int) {        self.size = size        self.log2n = vDSP_Length(log2(float(size)))        guard let weights = vDSP_create_fftsetup(log2n,FFTradix(kFFTradix2)) else {            print("Aargh in GFFT.fft - weights Failed")            return nil        }        self.halfSize = size / 2        self.twoOverSize = [2 / float(size)]        self.weights = weights    }    public func forward(realArray: [float]) -> (magnitude: [float],phase: [float]) {        assert(realArray.count == self.size,"Aargh in GFFT.forward - size mismatch")        var real = realArray // copy into var        var imag = GFFT.zeros(size)        var magnitudesSquared = GFFT.zeros(self.halfSize)        var magnitudes = GFFT.zeros(self.halfSize)        var normalizedMagnitudes = GFFT.zeros(self.halfSize)        var phases = GFFT.zeros(self.halfSize)        var splitComplex = DSPSplitComplex(realp: &real,imagp: &imag)        vDSP_fft_zip(self.weights,&splitComplex,1,self.log2n,FFTDirection(FFT_FORWARD))        vDSP_zvmags(&splitComplex,&magnitudesSquared,vDSP_Length(self.halfSize))        vvsqrtf(&magnitudes,[Int32(self.halfSize)])        vDSP_zvphas(&splitComplex,&phases,vDSP_Length(self.halfSize))        vDSP_vsmul(&magnitudes,self.twoOverSize,&normalizedMagnitudes,vDSP_Length(self.halfSize))        // you may choose to return magnitudesSquared,for the power        // magnitudes for the scaled amplitudes or         // normalizedMagnitudes for,well,normalised magnitude.        return (normalizedMagnitudes,phases)    }    private static func zeros(_ n: Int) -> [float] { return [float](repeating: 0,count: n) }}let testinput = (0 ..< 512).map {    return sin(float())}if let fft = GFFT(size: testinput.count) {    let (freq,phase) = fft.forward(realArray: testinput)    freq.map({[+++]})}

游乐场输出:

至于你测试什么,它将取决于你得到的实际输出,所以我会试验实际数据给你的东西,但你的测试应该是这样的:

>找到振幅的平均值>找到最大振幅>检查两者的比率(最大值/平均值)是否高>检查最大值的索引是否接近零(或者它可能是直流信号)>检查任何其他局部最大值(并且会有一些)远小于全局最大值.

总结

以上是内存溢出为你收集整理的数组 – 如何知道数组是否代表正弦波?全部内容,希望文章能够帮你解决数组 – 如何知道数组是否代表正弦波?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
数组 – 如何知道数组是否代表正弦波?_app_内存溢出

数组 – 如何知道数组是否代表正弦波?

数组 – 如何知道数组是否代表正弦波?,第1张

概述我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波. 我想避免的是手动比较数组中的每个值并做出决定. 我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波. 正如评论员@NeilForrester所指出的那样, FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用O 我正在使用加速度计并在过去的几秒钟内收集数据.我想要检测的运动可以用运动传感器得到的值表示为正弦波.所以为了确保,我想要一种方法来检查从传感器返回的数据是否代表正弦波.

我想避免的是手动比较数组中的每个值并做出决定.

我想知道是否有一种有效的方法可以判断我的数组是否代表正弦波.

解决方法 正如评论员@NeilForrester所指出的那样,FFTs就是这样做的.编写自己的高效FFT并不容易,但是如果使用Objective-C,Accelerate框架的 vDSP routines提供了一种直接的方法 – 由于使用了UnsafePointer和UnsafeMutablePointer参数,因此在Swift中并不那么简单.这是一个使用FFT的简单Swift示例.

import Foundationimport Acceleratepublic struct GFFT {    let size: Int    let halfSize: Int    let log2n: vDSP_Length    let twoOverSize: [float]    var weights: FFTSetup    init?(size: Int) {        self.size = size        self.log2n = vDSP_Length(log2(float(size)))        guard let weights = vDSP_create_fftsetup(log2n,FFTradix(kFFTradix2)) else {            print("Aargh in GFFT.fft - weights Failed")            return nil        }        self.halfSize = size / 2        self.twoOverSize = [2 / float(size)]        self.weights = weights    }    public func forward(realArray: [float]) -> (magnitude: [float],phase: [float]) {        assert(realArray.count == self.size,"Aargh in GFFT.forward - size mismatch")        var real = realArray // copy into var        var imag = GFFT.zeros(size)        var magnitudesSquared = GFFT.zeros(self.halfSize)        var magnitudes = GFFT.zeros(self.halfSize)        var normalizedMagnitudes = GFFT.zeros(self.halfSize)        var phases = GFFT.zeros(self.halfSize)        var splitComplex = DSPSplitComplex(realp: &real,imagp: &imag)        vDSP_fft_zip(self.weights,&splitComplex,1,self.log2n,FFTDirection(FFT_FORWARD))        vDSP_zvmags(&splitComplex,&magnitudesSquared,vDSP_Length(self.halfSize))        vvsqrtf(&magnitudes,[Int32(self.halfSize)])        vDSP_zvphas(&splitComplex,&phases,vDSP_Length(self.halfSize))        vDSP_vsmul(&magnitudes,self.twoOverSize,&normalizedMagnitudes,vDSP_Length(self.halfSize))        // you may choose to return magnitudesSquared,for the power        // magnitudes for the scaled amplitudes or         // normalizedMagnitudes for,well,normalised magnitude.        return (normalizedMagnitudes,phases)    }    private static func zeros(_ n: Int) -> [float] { return [float](repeating: 0,count: n) }}let testinput = (0 ..< 512).map {    return sin(float())}if let fft = GFFT(size: testinput.count) {    let (freq,phase) = fft.forward(realArray: testinput)    freq.map({})}

游乐场输出:

至于你测试什么,它将取决于你得到的实际输出,所以我会试验实际数据给你的东西,但你的测试应该是这样的:

>找到振幅的平均值>找到最大振幅>检查两者的比率(最大值/平均值)是否高>检查最大值的索引是否接近零(或者它可能是直流信号)>检查任何其他局部最大值(并且会有一些)远小于全局最大值.

总结

以上是内存溢出为你收集整理的数组 – 如何知道数组是否代表正弦波?全部内容,希望文章能够帮你解决数组 – 如何知道数组是否代表正弦波?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1009458.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存