Plotting Time - Amplitude with delaying n samples in Python

Viewed 29

I am new to the signal processing in Python. I am trying to translate this Matlab code into the Python code. I want to plot two time domain signals of hilbert transform with remez function. Even though I use scipy.signal library, I couldn't handle it. Especially the part of delaying 15 samples in Matlab makes it hard for me. Could you please help me with this?

 b = remez(30,[0.05 0.95],[1 1],'h');
 Fs = 1000;
 t = (0:1/Fs:2)';
 x = sin(2*pi*50*t);
 xh = filter(b,1,x);
 xd = [zeros(15,1); x(1:length(x)-15)]; % delay 15 samples
 figure; plot(t(1:50),xd(1:50),t(1:50),xh(1:50))

My Python Code:

order = 30
Lw = order + 1
f1 = np.array([0.025 , 0.475])
m1 = np.array([1])

b3 = sig.remez(Lw, bands = f1, desired = m1, type = 'hilbert') 
duration = 2.0
fs = 1000.0
samples = int(fs*duration)
t = np.arange(0, duration, 1/fs)
x = np.sin(2 * np.pi* 50 * t)
xh = sig.filtfilt(b3, 1, x)
h = np.zeros(15)
a = 15 
xd = [h , x[1:len(x)-15]]


plt.plot(t[0:50], xd[0:50], label ='input')
plt.plot(t[0:50], xh[0:50], label= 'output')
plt.xlabel('Time [sec]')
plt.ylabel('Amplitude')
#plt.axis([0, 1, -150, 0])

plt.grid()
plt.legend()
0 Answers
Related