I'm searching for a function to determine if my transmitter is sending a signal or not.
My current situation: I use a Hackrf One and already get data from it using python. The output is an array with IQ values, which I can plot with matplotlib.
For generating a signal I use a small transmitter with a frequency round about 40-41 Mhz.
This is working perfectly, as you can see in the screenshot:
Now I spent two weeks in reading how to compute the spike with IQ values. Watched Michael Ossmanns playlist to the hackrf twice.
How do I can compute the spike by setting a range to react to? I am thinking about a small area to watch on and when the spike is over the green line (a value which is set in code) python call a function. Or is there a better / easier way to do it?
The code for now:
hackrf = HackRF()
hackrf.sample_rate = 20000000
hackrf.center_freq = 40000000
samples = hackrf.read_samples(1000000, 0.05)
# use matplotlib to estimate and plot the PSD
psd(samples, NFFT=1024, Fs=10.0, Fc=40.0)
xlabel('Frequency (MHz)')
ylabel('Relative power (dB)')
show()
Maybe someone did this before and have some examples. Python is not a must, any programing language is fine.
I am grateful for any help / idea / answer.
_____ solution _________________________ Edit: 2.17.22
countOfSamples = 10000 # note: not the sample rate
samples = hackrf.read_samples(countOfSamples, 0.05)
# calculate the average
midReal = 0
midImaq = 0
for i in range(countOfSamples):
midReal += samples[i].real
midImaq += samples[i].imag
midReal = midReal / countOfSamples
midImaq = midImaq / countOfSamples
# standard deviation
stdReal = 0
stdImaq = 0
for i in range(countOfSamples):
stdReal += (samples[i].real - midReal)**2
stdImaq += (samples[i].imag - midImaq)**2
result = math.sqrt(stdReal**2 + stdImaq**2)
if (result > 1):
print("found signal", result)
From this point starting to change the parameters to find the best values.
cheers