python中numpy函数ftt_相当于MATLAB中bandpower()的Python numpy

I am using Python numpy's ftt.ftt() method to generate the fourier transform of a signal. However I want to calculate the bandpower over a range of frequencies. MATLAB has the method bandpower(x,fs,freqrange), I am trying to simulate specifically this syntax of the function. Source: https://www.mathworks.com/help/signal/ref/bandpower.html

It doesn't look like numpy has an equivalent function, but does anyone know a code snippet I can use to mimic bandpower(x,fs,freqrange)? It's not clear to me what exactly is going on behind the scenes in the function.

Note: If you know some non-Python pseudocode that would achieve the Matlab function, that would also be helpful.

解决方案

The following snippet for computing the power in the band [fmin, fmax] worked for me:

import scipy

def bandpower(x, fs, fmin, fmax):

f, Pxx = scipy.signal.periodogram(x, fs=fs)

ind_min = scipy.argmax(f > fmin) - 1

ind_max = scipy.argmax(f > fmax) - 1

return scipy.trapz(Pxx[ind_min: ind_max], f[ind_min: ind_max])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值