Back to Challenge Set 22

Code Challenge: Sample Rate

Difficulty  

Extra CreditOptional. It earns extra credit and does not count toward the five.

divider

The Brief

What they asked for
How often do we actually need to measure? Every reading costs
storage and I do not want to pay for readings that tell me
nothing new. Show me the trade.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Wave(t) from Activity 2.16 stands in for the real world. Do not change it; it represents something you do not control.
  • For each rate, count the samples, then measure how wrong the rebuilt signal is. Rebuild a value for every whole second from 0 to 40 using only your samples, and add up the gaps.
  • How you rebuild the missing values is your decision. Repeating the last sample is the simplest; guessing on a straight line between two samples is better. Say which you chose. A gap below zero still counts: make it positive before adding it.
  • The output has to show the trade, not just two columns. More samples, less error: the client wants to know where to stop.
  • In your requirements list, name the rate you would recommend and what you gave up to pick it.

Sample Output

Sample Output
every 20: 3 samples, total error 883.2
every 10: 5 samples, total error 313.4
every 5: 9 samples, total error 82.2
every 2: 21 samples, total error 10.3
every 1: 41 samples, total error 0.0

These numbers come from the straight-line guess. Look at what each halving of the step buys: the first one cuts the error by about two thirds, and the last one removes the final 10. Where it stops paying is the actual challenge.


Submit

Your requirements list and your program file, named cc-sample-rate.

Commence Challenge