python idls_Python numpy.inv方法代码示例

本文展示了如何使用numpy.linalg.inv方法来计算最小二乘滤波器的系数。通过创建参考信号的时间移位副本矩阵并解决线性方程组,实现了自适应滤波器的功能,用于消除监控通道中的噪声。
摘要由CSDN通过智能技术生成

# 需要导入模块: import numpy [as 别名]

# 或者: from numpy import inv [as 别名]

def LS_Filter(refChannel, srvChannel, filterLen, reg=1.0, peek=10,

return_filter=False):

'''Block least squares adaptive filter. Computes filter taps using the

direct matrix inversion method.

Parameters:

refChannel: Array containing the reference channel signal

srvChannel: Array containing the surveillance channel signal

filterLen: Length of the least squares filter (in samples)

reg: L2 regularization parameter for the matrix inversion

(default 1.0)

peek: Number of noncausal filter taps. Set to zero for a

causal filter. If nonzero, clutter estimates can depend

on future values of the reference signal (this helps

sometimes)

return_filter: Boolean indicating whether to return the filter taps

Returns:

srvChannelFiltered: Surveillance channel signal with clutter removed

filterTaps: (optional) least squares filter taps

'''

if refChannel.shape != srvChannel.shape:

raise ValueError('Input vectors must have the same length')

lags = np.arange(-1*peek, filterLen)

# Create a matrix of time-shited copies of the reference channel signal

A = np.zeros((refChannel.shape[0], filterLen+peek), dtype=np.complex64)

for k in range(lags.shape[0]):

A[:, k] = np.roll(refChannel, lags[k])

# compute the autocorrelation matrix of ref

ATA = A.conj().T @ A

# create the Tikhonov regularization matrix

K = np.eye(ATA.shape[0], dtype=np.complex64)

# solve the least squares problem

filterTaps = np.linalg.solve(ATA + K*reg, A.conj().T @ srvChannel)

# direct but slightly slower implementation:

# filterTaps = np.inv(ATA + K*reg) @ A.conj().T @ srvChannel

# Apply the least squares filter to the surveillance channel

srvChannelFiltered = srvChannel - A @ filterTaps

if return_filter:

return srvChannelFiltered, filterTaps

else:

return srvChannelFiltered

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值