matlab里面的specgram,需要解释specgram函数如何在python中工作(matplotlib MATLAB兼容函数)...

我正在把我的代码从python转换成objective c。

内部plotgram.matmlab绘图函数I在fft前看到3个重要函数:result = stride_windows(x, NFFT, noverlap, axis=0)

result = detrend(result, detrend_func, axis=0)

result, windowVals = apply_window(result, window, axis=0,

return_window=True)

result = np.fft.fft(result, n=pad_to, axis=0)[:numFreqs, :]

我试着调试以了解每一个的目的。例如,我有一个输入数组:

^{pr2}$

第一次功能后,跨步窗(这是为了防止漏水?),如果NFFT=4,noverlap=2,则:x = [ [1,3,5,7,9],

[2,4,6,8,10],

[3,5,7,9,11],

[4,6,8,10,12]

]

detrend之后没有任何变化(我理解fft之前的detrend)

在应用窗口内(我不明白这一步):xshape = list(x.shape)

xshapetarg = xshape.pop(axis) // =4

windowVals = window(np.ones(xshapetarg, dtype=x.dtype))

//result of 4 elements [0.0, 0.75, 0.75, 0.0]

xshapeother = xshape.pop() // =5

otheraxis = (axis+1) % 2 // =1

windowValsRep = stride_repeat(windowVals, xshapeother, axis=otheraxis)

// result windowValsRep = [

[ 0. ,0. ,0. ,0. ,0. ,],

[0.75, 0.75, 0.75, 0.75,

[0.75, 0.75, 0.75, 0.75,

[ 0. ,0. ,0. ,0. ,0. ,]

]

然后乘以xwindowValsRep * x

现在x = [

[ 0. , 0. , 0. , 0. , 0. ],

[ 1.5 , 3 , 4.5 , 6. , 7.5 ],

[ 2.25, 3.75 , 5.25 , 6.75 , 8.25 ],

[ 0. , 0. , 0. , 0. , 0. ]

]

最后一个是fft,我知道fft只需要一个数组,但这里它处理的是二维数组。为什么?在result = np.fft.fft(x, n=pad_to, axis=0)[:numFreqs, :]

有谁能一步一步地给我解释一下为什么数据需要在fft之前进行这样的处理?在

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值