我已经发布了我所看到的摘要,我只是制作了一个脉冲序列并在其上测试了一个陷波滤波器,仅作为示例。
我还有一个以 0 Hz 为中心的复杂基带信号,这个复杂的基带信号有一个仅在正频率上的复指数 - 这是我需要去除的干扰 - 因此陷波滤波器只去除正频率。我不能在这里发布这段代码,因为代码太多所以我发布了一个脉冲序列和一个陷波滤波器。
我的陷波滤波器适用于正频率和负频率。我不明白为什么在 scipy 中使用 iirfilter 和 lfilter 不能正确处理复杂信号。它将陷波应用于正频率和负频率,而不仅仅是一个。
我在这里想念什么?任何建议表示赞赏!
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
plt.close('all')
#Sampling
Fs = 40e3 # samples per second
Ts = 1/Fs
Ns = int(Fs) #if =FS then resolution = 1
t = np.arange(Ns) * Ts # time vector for carrier
fftsize = Ns #Full length FFT
resolution = Fs / fftsize
f = np.arange(-Fs/2, Fs/2,resolution)
#Pulses
pulse_span = 50
pulse_duration = pulse_span*Ts
data = np.random.randint(0,2,int(Ns/pulse_span))
data = (data - 0.5)
x = np.zeros((Ns))
for i in range(len(data)):
increment_low = i*pulse_span
increment_high = increment_low + pulse_span
x[increment_low:increment_high] = data[i]
#Filter Function
def Implement_Notch_Filter(time, band, freq, ripple, order, filter_type, data):
from scipy.signal import iirfilter
fs = 1/time
nyq = fs/2.0
low = freq - band/2.0
high = freq + band/2.0
low = low/nyq
high = high/nyq
b, a = signal.iirfilter(order, [low, high], rp=ripple, btype='bandstop',
analog=False, ftype=filter_type)
filtered_data = signal.lfilter(b, a, data)
return filtered_data
x = Implement_Notch_Filter(1/Fs,50,200,0.5,2,'butter',x)
#Spectrum
X = np.fft.fft(x,fftsize)/fftsize
X = np.fft.fftshift(X)
X = abs(X)
X_PSD = 10*np.log10( abs((X)) **2)
fig = plt.figure(2)
ax = fig.add_subplot(111)
ax.title.set_text('Frequency: Spectrum dB ')
ax.plot(f,X_PSD)
plt.ylabel('Power (dBW/' + str(int(resolution)) + ' Hz)')
plt.xlabel('Frequency')
plt.ylim([-80, -20 ])


