0
$\begingroup$

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:

enter image description here enter image description here

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?

enter image description here

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

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes this is a classical 'probability of false alarm" vs "probability of detection" problem. Ultimately you balance the two, moving the threshold lower improves the probability of detection but increases the probability of false alarm as you will inevitably have noise cross that threshold. You can balance the predicted false alarm and detection rates by knowing the statistics of the noise (as a Rayleigh distribution if only given the magnitudes) and the statistics of the standard deviation of the signal plus noise (which would likely be a Rician distribution for the same reason). You could track the two using a leaky average of the rms values when signal is and isn’t present and set your threshold between the mean of the two based on your desired preference of alarm/detection rates. If the signal to noise ratio is high as received in the monitor, then setting a threshold half way between the two would likely be more than sufficient.

Also not sure if you have local access to the transmitter, but if so, you could consider monitoring the transmit power supply current directly, which will most likely increase during transmission especially if the supply current is dominated by the transmit power amplifier.

$\endgroup$
4
  • $\begingroup$ That is definitely what I am looking for. But how can I calculate the average of the rms values. Ich have an array with IQ values. I tried calculate it by (Q^2+I^2)^1/2 add all values up and compare the sending and not sending state. I did the same while split all data in 6 parts. No usable results. Now I have access to the transmitter, its like a garage door opener. But later on I want to transfer this to the frequency of 2.4 Ghz and then I will not have access. The garage door opener is easier for try and error. $\endgroup$ Feb 16, 2022 at 19:18
  • $\begingroup$ You would compute the standard deviation of the waveform but only over the memory depth in which the process can assumed to be stationary (that’s why I mentioned a “leaky average”). I am guessing your SNR is strong enough that you can make initial guesses as to what on and off is and set the threshold mid way, and from that mask each to compute the standard deviation in each interval and then from that optimize your threshold. I doubt you can set and forget but would be something that is adaptively updating depending on how fast things change - that you can measure and determine. $\endgroup$ Feb 16, 2022 at 21:59
  • $\begingroup$ Do you know how to calculate this from the IQ values? Or know a website / book where I can find a mathematical explanation? The IQ values I get from my device are already switched from time to frequency domain with a fast fourier transformation. $\endgroup$ Feb 17, 2022 at 18:44
  • $\begingroup$ Yes: assuming you can't work with complex numbers directly as I+jQ, then you can compute the variance of each, add them to get the total variance and square root of that to get the standard deviation. std(z) = sqrt(std(I)^2 + std(Q)^2). $\endgroup$ Feb 17, 2022 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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