Paul's Python CoursePPC

Project 8 of 9, for Caitlin

Radio Station Finder

Caitlin wants music on the roof for the last night of term, and the old Studio radio hisses from one end of the dial to the other. Smooth the dial, find the real stations, and turn it up.

About 60 minutes, in 9 steps.

Sign up free to open itLog in

Act 9 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • CaitlinIt's the last night of term so we need music, and I've brought the old Studio radio up.
  • CaitlinThe whole dial's just hiss, though. Auto-tune found one very loud crackle and then nothing.
  • NeilThat's a noisy signal, rocket telemetry looks just like that. You smooth it out before you trust it.
  • CaitlinSmooth the dial, find the real stations, and we'll have music up here.

The dial gives one signal reading for every 0.1 MHz from 88.0 to 108.0, in dial.txt. Write find_stations(readings, start=88.0, step=0.1, window=5, floor=0.5) in tuner.py:

  • smooth the readings with a moving average: each value becomes the mean of itself and up to window // 2 neighbours on each side (fewer at the ends)
  • a station is a smoothed value, not at either end, that is higher than the one before it, at least as high as the one after it, and at least floor
  • return the stations' frequencies, rounded to one decimal place, strongest first
What it prints
>>> find_stations(readings)
[96.4, 101.7]

What's in it

  1. Smoothing a noisy signal
  2. The ends of the dial
  3. Listening to the dial
  4. Finding the peaks
  5. A flat top
  6. Smoothing out the crackle
  7. The tuner
  8. Ship it