I am writing a simulation for a wireless network in python using numpy and cython, where suppose there is a number of nodes no_nodes scattered randomly on the 2d plane which send out some waveforms and their respective receivers, again scattered randomly on the 2d plane. Each transmitting node produces a waveform I call output (each one can produce an output of different length).
What I want to do is to sum these outputs from each node to one big waveform that will be the input to each receiver for demodulation etc. Now two key-points:
- the transmitters send asynchronously and therefore a
start_clockand anend_clockhas to be maintened per transmitting node so as to sum the waveforms properly - the output of the
jtransmitting node will be attenuated before being received by theinode according to a functionattenuate(i,j)
So here is the code:
#create empty 2d array (no_rx_nodes x no_samples for each waveform)
waveforms = np.zeros((no_nodes, max(end_clock)))
for i in range(no_nodes): #calculate the waveform for each receiver
for j in range(no_nodes): #sum the waveforms produced by each transmitter
waveforms[i, start_clock[j]:end_clock[j]] += output[j,:] * attenuate(i,j)
return waveforms
Some comments on the above:
output[j, :]is the output waveform of transmitter jwaveforms[i,:]is the waveform received by receiver i
I hope it is fairly clear what I am trying to accomplish here. Because the waveforms produced are very large (about 10^6 samples), I also tried turning this code into cython but without noticing any particular speedup (maybe 5-10x better but no more). I was wondering if there is anything else I can resort to so as to get a speed up because it is a real bottleneck to the whole simulation (it takes to compute almost as much time as the rest of the code, which in fact is quite more complicated than that).
no_nodesis large. Are you sure the bottleneck isn't inattenuate?attenuate = (attn_const/distances) ** attn_expon, which will yield an array the same size as distances, right?