# scipy.signal.decimate vs array operations

The following program generates a signal with a bit of noise according to some bits. I then try to decode the signal using convolve and decimate. 2 problems I notice:

1. The whole this gets thrown out of wack depending on the 'type' parameters that I pass to convolve, is there a better way of lining up the signal?
2. The decimate function seems to mess things up - everything works better if just use array indices to access the data I want. Am I doing something wrong with decimate?

Here is a picture of the output: import matplotlib.pyplot as plt
from math import sin, pi
from numpy import ones, zeros
from numpy.random import random_sample as sample
from scipy.signal import decimate, convolve

N = 100
amplitudes = [1, 0, 0, 1, 0, 1, 1, 0, 1, 0]
pulse = ones(N)

#generate the transmit signal
tx_pulse = pulse + [0.2*sin(n) for n in range(1,N+1)]
signal = zeros(N * len(amplitudes))
for i in range(0, len(amplitudes)):
for j in range(0, N):
signal[i*N+j] = amplitudes[i] * tx_pulse[j]
signal = signal + 0.01*sample(len(signal)) #add noise

#now try to get the data back...
signal2 = convolve(signal, pulse/N, mode='valid')
signal3 = signal2 > 0.5 #bit decision

#dec = decimate(signal3, N, ftype='fir') #THIS MESSES UP THE THE FIRST SYMBOL
dec = signal3[0:N*len(amplitudes):N]

plot4 = zeros(N*len(amplitudes))
for i in range(0, len(amplitudes)):
plot4[i*N] = dec[i]

print dec

plt.plot(signal)
plt.plot(signal2)
plt.plot(signal3)
plt.plot(plot4, 'ro')
plt.show()

• Please clarify what your question is and provide more context. What are you trying to do? What are your signals? What are the different colored plots? What were you expecting to get, and what did you get instead? – MBaz Nov 17 '16 at 1:24