1

I want to know what the sample rate of I and Q samples generated for transmission, in the function below from https://github.com/lyusupov/ADSB-Out/blob/master/ADSB_Encoder.py samples are generated for transmission by a SDR (HackRF) so they are aligned to 256k buffer (HackRF requirement) and then SDR (HackRF) commanded to send samples at the rate of 2 Ms/s. So without any hardware how can I save a stream of I and Q samples at a 2 Ms/s rate to be decoded by programs like dump1090.

def hackrf_raw_IQ_format(ppm):
       signal = []
        bits = numpy.unpackbits(numpy.asarray(ppm, dtype=numpy.uint8))
        for bit in bits:
            if bit == 1:
                I = 127
                Q = 127
            else:
                I = 0
                Q = 0
            signal.append(I)
            signal.append(Q)
    return bytearray(signal)

I want to save these samples at 2 Ms/s and later play by dump1090.

Mas
  • 11
  • 1
  • btw, this is an incredibly inefficient way of generating the samples, pushing back each sample to a python list (signal = [] makes a list), twice, and then making a bytearray out of it; numpy can do all of this for you, much much much faster: the whole hackrf_raw_IQ_format function could have four lines: bits = numpy.unpackbits(numpy.asarray(ppm, dtype=numpy.uint8)), signal = numpy.zeros((len(bits), 2), dtype=numpy.uint8), signal[bits == 1, :] = 127, return bytes(signal.flatten()) – Marcus Müller Feb 13 '23 at 17:52

1 Answers1

3

You just safe the samples as they come out of your software (that bytearray) – the software itself cannot care about the actual rate of the hardware – it just calculates a sequence of numbers (the samples).

Marcus Müller
  • 30,525
  • 4
  • 34
  • 58
  • Thanks, any idea then how can i test these I Q samples generated with any adsb decoder application? – Mas Feb 13 '23 at 18:01
  • Same thing the other way around: read the samples from a file, instead of from an SDR device. – Marcus Müller Feb 13 '23 at 18:17
  • if i feed the samples to dump1090 for adsb decoding then there is no output. dump1090 is assuming it to be at 2 Ms/s but these are just output of software with no sample rate – Mas Feb 13 '23 at 18:20
  • 1
    You are misinterpreting what sampling rate says about a digital signal. the samples are just numbers, they don't have a sampling rate. They are calculated, however, for a device running at 2 MS/s, so they are indeed the right signal; they would be the exact same values that would be sent to a hackrf, or that would be coming from a (theoretically noiseless, perfectly synchronized) hackrf as receiver. I don't know dump1090, so I can't tell you what goes wrong on that end. – Marcus Müller Feb 13 '23 at 18:26
  • 1
    @Mas 2 Ms/s means it will read 2 million samples and it will think they are 1 second worth of data. That's all it means. So if you want to have 10 seconds of fake data then you want to have 20 million samples. – user253751 Feb 13 '23 at 21:15
  • This also means you can calculate the wave "length". If you want a 0.1MHz wave at 2 Ms/s then each wave is 20 samples long. You need to know the sample rate to know whether a 20-sample wave is 0.1MHz at 2Ms/s, or 1MHz at 20Ms/s, since there's no other difference. – user253751 Feb 15 '23 at 13:25
  • Thanks all for the explanation – Mas Feb 23 '23 at 14:31