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:


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?
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 &gt; 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()
You should use the 'full' parameter for the convolution. Then, naturally with the convolution, your peak that you use for decimation occurs at the end of each symbol. At this point, the transmit and receive filter line up and you get the maximum overlap and hence best SNR.
The decimate function applies a low-pass filter before the decimation. This is due to the sampling theorem: When you reduce the sampling rate, you need to remove higher frequencies to prevent aliasing. However, in your case, you have already convolved with your filter, so the simple version of taking only every n-th sample is perfectly correct.