Blog

Python3でnextpow2を作る

fftに渡す信号のパディングに使用していたMatlabのnextpow2をPythonに移植しました。

nextpow2は、入力Aの絶対値以上の最小の2のべき乗の指数を計算します。

こんな感じになりました。

import numpy as np

def nextpow2(n):
    m_f = np.log2(n)
    m_i = np.ceil(m_f)
    return int(np.log2(2**m_i))

うまく狙った感じで動いてそうです。

スクリーンショット 2015-03-11 19.13.19

This Post Has 0 Comments

Leave A Reply