【问题标题】:Efficient way for calculating power of signal in python在python中计算信号功率的有效方法
【发布时间】:2021-07-05 14:29:54
【问题描述】:

我有n_sample 脑信号,我想计算每个样本的功效。

这是我的代码:

def return_power_of_signal(input_signal):
    #The power of a signal is the sum of the absolute squares of its time-domain samples divided 
    #by the signal length, or, equivalently, the square of its RMS level.
    #my approach
    
    #input: np.array of (n_sample, time_length)
    
    n_sample = input_signal.shape[0]
    n_time = input_signal.shape[1]
    
    results_array = np.empty((n_sample, 1))
    
    for i in range(n_sample):
        sum_sample = 0
        for j in range(n_time):
            sum_sample += input_signal[i, j]*input_signal[i, j]
        sum_sample = sum_sample/n_time
        results_array[i] = sum_sample
    
    return results_array

但是,我想知道有没有更好的方法(更有效/更少的编码?)计算这个的方法?

谢谢

【问题讨论】:

  • 你能举个input_signal的例子吗?

标签: python python-3.x performance multidimensional-array signal-processing


【解决方案1】:

使用np.abs(input_signal)**2,这得到绝对值,然后平方算子得到幅度。

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 2011-03-11
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 2020-01-21
    • 2017-05-02
    • 2016-09-11
    • 1970-01-01
    相关资源
    最近更新 更多