Well, first, thank you for offering. I'm sitting here trying to think exactly how to set this up in an open forum and provide enough information for the case to make sense. It is a small section of a rather lengthy body of code. I'll give it a shot.
I read data passed to me from another system which has captured signals arriving at two antennas, which I refer to as inputs. I may have two such systems, which I refer to as manifolds. The data is passed to me as a 48,000 complex datapoint stream, 24,000 for input 1 followed by 24,000 for input 2. I calculate power, which is where we begin this discussion. The power matrix is pwr[manifolds, inputs, datapoints/input]. That happens to be [1,2,24000] in the simplest test case.
I want to find the rising edge of the first pulse in each input dataset. I have already reduced the datapoints from 24,000 to 4096. I know the first pulse lies somewhere within that 4096 slice. I know that the pulse width is 2048. Once I have it, I take an FFT of the pulse. That part is already written and tested. The portion I am currently writing is the section finding that rising edge. For this test, I have visually verified that the pulse actually starts at datapoint 1025. That is why you will see print statement looking at points around that figure.
This is what I have currently.
Code: Select all
# This section finds the pulse in the input data stream
# In the test case 'Example #2' that means 2048 of 4096 datapoints
#
# Calculate Power
pwr=np.add(np.square(data.real),np.square(data.imag))
print("'pwr' matrix is",pwr.shape)
print(pwr[:,:,1015:1040])
N0=np.mean(pwr)
print ("N0 is average power",N0)
print("---------------------------------------------------------------")
# With the average power, find the pulse
# Here we use a gross detection, then fine tune it (to save computing time)
# First, redefine 'pwr' as a boolean matrix 1=exceeds threshold, 0=doesn't
pwr=np.where(pwr>N0/2,np.int(1),np.int(0))
# change pwr matrix to boolean based on threshold
print("pwr as 1s and 0s is",pwr.shape)
print(pwr[:,:,1015:1040])
# examine pwr for the beginning of the first pulse in each input
pwr=pwr.resize(manifolds,inputs,np.int(indat/10),10)
print("pwr ready for summing is",pwr.shape)
print(pwr[:,:,0-6,:])
pwrsum=np.sum(pwr,axis=3)
print("pwrsum is",pwrsum.shape)
print(pwrsum[:,:,0:40])
The last section doesn't work as is. I am trying to resize the power matrix to include a new dimension with each ten datapoints. (Thus, I abandon the rolling sum.) I will sum that dimension, which I believe will retract the matrix back to three dimensions (at least it will if np.sum works like np.average in that respect) giving me a new matrix 'pwrsum.' Then, I will find the ten-point section that has the rising edge and write more code (which I haven't started) to find the exact datapoint (in 'pwr') where it rises. That is my idea to speed it up.
Code: Select all
The current code, in the last section, gives me a scalar for pwrsum.
'pwr' matrix is (1, 2, 4096)
[[[2.59167454e-05 6.22989088e-06 1.86896511e-05 2.61999725e-05
2.01763086e-05 1.54260481e-05 2.14214460e-06 5.43702520e-06
1.12911418e-05 1.45992022e-03 1.16419753e-03 3.66901296e-03
1.47404067e-03 4.23945951e-03 8.81071269e-03 7.73278334e-03
4.84947192e-04 1.24258423e-03 2.37445083e-03 2.31586487e-03
3.59474264e-03 1.21379329e-03 5.22641165e-03 9.74239688e-04
3.29744981e-03]
[1.28948850e-05 4.23178476e-06 3.61211223e-05 1.19399182e-05
1.71741414e-05 1.00669951e-07 6.56602973e-06 1.00561338e-05
7.75410970e-06 2.02694631e-04 2.13421632e-03 6.29514901e-04
5.82015401e-03 6.08337756e-05 6.53554687e-03 8.22032727e-03
6.05838853e-03 9.52441538e-05 2.24991930e-03 8.19040495e-04
4.25328955e-03 3.20162519e-03 1.81849150e-04 6.46625573e-03
5.93614369e-04]]]
N0 is average power 0.0015424418591345873
---------------------------------------------------------------
pwr as 1s and 0s is (1, 2, 4096)
[[[0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1]
[0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 0 1 0]]]
Traceback (most recent call last):
File "scat005.py", line 112, in <module>
print("pwr ready for summing is",pwr.shape)
AttributeError: 'NoneType' object has no attribute 'shape'
This may not be enough information to actually help, but this is about as much as I can provide. Thanks for taking a look.