HackRF Shell: FFT Averaging and Display Progress

I’m not quite sure I have all the bugs worked out yet, but I implemented simple averaging, as well and the frequency display. The latter required implementing fft-shift to move center frequency to the center. The above plot shows FM stations at 101.1, 102.5, 103.9, and 104.7 Mhz, matching local stations I know about.

These simple things took quite a while, mainly because of the busyness of other life responsibilities; but also because the process of implementation led to fixing some bugs, which led to cleaning up some code, which led to learning new things about Guile scheme and C.

In Guile scheme, I learned how to implement a procedure to auto-close unreachable ports:

(define ports-guardian #f)

(define (close-guarded-ports)
  (let f ()
    (let ((p (ports-guardian)))
      (when p (begin (close-port p) (f))))))

(define (initialize-ports-guardian)
  (when (not ports-guardian)
    (set! ports-guardian (make-guardian))
    (add-hook! after-gc-hook (lambda () (close-guarded-ports)))))


(define (register-autoclose p) (ports-guardian p) p)

register-autoclose can simply be wrapped around the port, e.g.:

(define (hackrf-cb-rx-to-file filename)
   (register-autoclose (open-output-file filename))))

This uses Guile scheme “guardian” functionality, which is an object that can return registered objects if the have become unreachable everywhere else.

git clone git://git.librehacker.com/pub/git/hackrf-rkt.git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s