python-can-define-radio / sdr-course

Other
32 stars 9 forks source link

Possible idea: Osmocom recevier flowgraph and FM Demod flowgraph #13

Closed james-pcdr closed 5 months ago

james-pcdr commented 9 months ago

Something like this:

tb_o = osmocom_receiver()
tb_f = fm_demodulator()
while True:
  data = tb_o.get()
  tb_f.put(data)

I know this is largely re-inventing part of GNU Radio, but I think it might be helpful for Python beginners.

james-pcdr commented 9 months ago

Here's some random stuff that might be relevant:

import pcdr
import matplotlib.pyplot as plt

from pcdr.osmocom_queued_rx_flowgraph import osmocom_source_to_queue_sink
from pcdr import make_fft, configure_graceful_exit

samp_rate = 2e6
chunk_size = 2**21
tb_osmo = osmocom_source_to_queue_sink(104.3e6, samp_rate, chunk_size, "hackrf=0")
tb_fmdemod = FM_Demod(samp_rate, chunk_size)
configure_graceful_exit(tb_osmo)
configure_graceful_exit(tb_fmdemod)
tb_osmo.start()

dat_chunk = tb_osmo.queue_sink.get()
print(dat_chunk)
tb_fmdemod.queue_source.queue_put(dat_chunk)
tb_fmdemod.start()
sample_freqs, fft_mag = make_fft(dat_chunk, samp_rate)
plt.plot(sample_freqs, fft_mag)
plt.show()
class FM_Demod(gr.top_block):

    def __init__(self, samp_rate: float, chunk_size: int):
        gr.top_block.__init__(self, "Not titled yet")

        q = SimpleQueueTypeWrapped(np.ndarray, np.complex64, chunk_size)

        self.queue_source = queue_source(q, chunk_size, np.complex64)
        self.vector_to_stream = blocks.vector_to_stream(gr.sizeof_gr_complex, chunk_size)
Elijah-cyber7 commented 9 months ago

I think this could be tackled by possibly creating a class with a lot of the blocks for modulating and demodulating built in. For example a receiver will almost always have wfm_receive, re-sampler, filter, and audio sink. If the queue were to be wired in then it would be rather simple to implement methods for getting and putting data.

james-pcdr commented 9 months ago

I think that sounds good. I'll comment again here when I have some time, most likely in a few weeks or months.

james-pcdr commented 5 months ago

Update: I've decided to go for a more abstract approach, so I'm closing this issue. Thanks for giving your thoughts.

Also, FYI, I'll be migrating the pcdr-module-related code to https://github.com/python-can-define-radio/pcdr in the next month or two.