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: enter image description here

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(plot4, 'ro')
  • $\begingroup$ 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? $\endgroup$ – MBaz Nov 17 '16 at 1:24
  1. 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.

  2. 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.

  • $\begingroup$ thanks! i ported your matlab code to python, it was a great help to see what is going on! $\endgroup$ – Nick Lang Nov 17 '16 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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