MATLAB:解包函数 [英] MATLAB: unwrap function

查看:349
本文介绍了MATLAB:解包函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Mathworks的某人讨论: unwrap 函数,其中包含一个"bug",以实现π以外的跳转容限,并希望获得其他一些观点:

I'm in a discussion with someone from Mathworks re: the unwrap function which has a "bug" in it for jump tolerances other than π, and would like to get some other perspectives:

说明

Q = unwrap(P)通过将± 2π的倍数相加来校正矢量P中的弧度相位角.当P的连续元素之间的绝对跳变大于或等于默认跳变公差π时.弧度.如果P是矩阵,则展开操作将按列进行.如果P是多维数组,则展开将在第一个非单维度上进行.

Q = unwrap(P) corrects the radian phase angles in a vector P by adding multiples of ±2π when absolute jumps between consecutive elements of P are greater than or equal to the default jump tolerance of π radians. If P is a matrix, unwrap operates columnwise. If P is a multidimensional array, unwrap operates on the first nonsingleton dimension.

Q = unwrap(P,tol)使用跳动公差tol代替默认值π.

Q = unwrap(P,tol)uses a jump tolerance tol instead of the default value, π.

该文档有两种可能的解释:

There are two possible interpretations of the documentation:

  1. Q = unwrap(P,tol)通过将± 2π的倍数相加来校正矢量P中的弧度相位角.当P的连续元素之间的绝对跳变大于或等于tol弧度时.如果P是矩阵,则展开操作将按列进行.如果P是多维数组,则展开将在第一个非单维度上进行.

  1. Q = unwrap(P,tol) corrects the radian phase angles in a vector P by adding multiples of ±2π when absolute jumps between consecutive elements of P are greater than or equal to tol radians. If P is a matrix, unwrap operates columnwise. If P is a multidimensional array, unwrap operates on the first nonsingleton dimension.

示例:

>> x = mod(0:20:200,100); unwrap(x, 50)
ans =
    0 20.0000 40.0000 60.0000 80.0000 81.6814 101.6814 121.6814 141.6814 161.6814 163.3628

  • Q = unwrap(P,tol)当P的连续元素之间的绝对跳变大于或等于tol时,通过加上± 2 * tol的倍数来校正向量P中的元素.如果P是矩阵,则展开操作将按列进行.如果P是多维数组,则展开将在第一个非单维度上进行.

  • Q = unwrap(P,tol) corrects the elements in a vector P by adding multiples of ±2*tol when absolute jumps between consecutive elements of P are greater than or equal to tol. If P is a matrix, unwrap operates columnwise. If P is a multidimensional array, unwrap operates on the first nonsingleton dimension.

    示例:

    >> x = mod(0:20:200,100); unwrap(x, 50)  
    ans =  
        0    20    40    60    80   100   120   140   160   180   200
    

  • unwrap()在MATLAB中的实际行为(至少达到R2010a)为#1.我对unwrap()的解释是它应该是#2,因此行为上有错误.如果unwrap()的行为与#2相匹配,则对于缓慢变化的输入,可以将unwrap用作mod的反函数,即对于连续元素变化小于tol = T/2的向量x,unwrap(mod(x,T),T/2) = x.

    The actual behavior of unwrap() in MATLAB (at least up to R2010a) is #1. My interpretation of unwrap() is that it's supposed to be #2, and therefore there is a bug in the behavior. If unwrap()'s behavior matched #2, then unwrap could be used as an inverse for mod for slowly-varying inputs, i.e. unwrap(mod(x,T),T/2) = x for vectors x where successive elements vary by less than tol=T/2.

    请注意,这种第二种解释比角度更笼统,并且可以解开任何具有环绕期T的东西.(对于弧度,默认值T = 2π对于度数,默认值为360;对于8位数字,默认值为256;对于16,值为65536)位数字等)

    Note that this 2nd interpretation is more general than angles, and can unwrap anything with a wraparound period T. (whether a default of T=2π for radians, 360 for degrees, 256 for 8-bit numbers, 65536 for 16-bit numbers, etc.)

    所以我的问题是:

    行为1是否有可能使用?哪种解释更有意义?

    推荐答案

    解释#1是我阅读文档的方式,我认为这很有意义.我可以想象用它来重建车轮编码器的驱动距离.对于低速,公差并不重要,但对于高速(足够高以违反采样定理,即,每个车轮旋转少于两个样本),公差可以帮助您获得正确的重构(如果您知道方向).

    Interpretation #1 is how I read the documentation and I think it makes sense. I could imagine to use it for reconstructing the driven distance from a wheel encoder. For slow speeds the tolerance doesn't matter, but for high speeds (high enough to violate the sampling theorem, i.e. you have less than two samples per wheel rotation), the tolerance helps you to get the right reconstruction if you know the direction.

    #1更具意义的另一个原因可能是普通的拆包可以轻松地扩展为通用的拆包,因此不需要直接将period作为参数.

    Another reason why #1 makes more sense is probably that the ordinary unwrap can be extended easily to a generic one and therefore there's no direct need for the period to be a parameter.

    % example for 16 bit integers
    >> x1 = [10 5 0 65535 65525];
    T = 65536;
    x2 = T * unwrap(x1 * 2 * pi / T) / (2 * pi)
    x2 =
         10.0000    5.0000         0   -1.0000  -11.0000
    

    或者只做自己的功能:

    function ret = generic_unwrap(x, T)
      ret = T * unwrap(x * 2 * pi / T) / (2 * pi);
    end
    

    这篇关于MATLAB:解包函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆