2
$\begingroup$

I an new to signal processing, working on a UWB radar data this data has a shape of frames for which every frame (list) has 164 values, I want to apply a bandpass filter with cutoff frequency of 1hz and 5hz to filter the noisy data. My filter is not giving the good results as I expected (the filtered data is the reason behind), so I was wondering how can I debug this:

Fs = 50
fp = np.array([1, 5])
Ap = 0.025
filter_order = 2
wc = (2 * pi * fp) / Fs

print('wc is ', wc)

sos = signal.cheby1(filter_order,
                    Ap,
                    wc,
                    'bandpass',
                    analog=True,
                    output='sos')

filt_data_UWB1 = signal.sosfilt(sos, data_UWB1_before)

How can I plot the impulse response, Frequency response and the data before and after being filtered (every sample of data is a frame that contains 164 point how i am supposed to plot this )?

$\endgroup$
1
  • $\begingroup$ sory that was a mistake bexause I changed the code I used sosfilt in that case $\endgroup$
    – oubo21
    Commented Apr 8, 2022 at 19:00

1 Answer 1

2
$\begingroup$

An easy way to accomplish getting the impulse and frequency response for the filter given as a cascade of two second order filters (sos) is to first combine the two filters by convolving the numerator and denominator coefficients:

$$H(s) = H_1(s) \circledast H_2(s)$$

The frequency response is then plotted by setting $s=j\omega$ and plotting the magnitude and phase vs $\omega$.

The impulse response is found from the inverse Laplace Transform of $H(s)$.

This can all be done directly in python:

To convolve the two filters use the numpy.convolve command.

To plot the frequency response use the scipy.signal.freqs command.

To plot the impulse response use the scipy.signal.impulse command.

This is demonstrated below, refer to the help documentation for the above commands for more details:

Frequency Response:

b = np.convolve(sos[0][:3], sos[1][:3])
a = np.convolve(sos[0][3:], sos[1][3:]) 
w, h = signal.freqs(b, a)
plt.subplot(2,1,1)
plt.semilogx(w, 20*np.log10(h))
plt.subplot(2,1,2)
plt.semilogx(w, np.unwrap(np.angle(h)))

Frequency Response

Impulse Response:

t, y = signal.impulse((b,a), T=np.linspace(0, 150, 2**14))
plt.plot(t, y)

Impulse Rsponse

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.