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?
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()