The answersDownload the PDF
Worksheet

A7.8 Sound and MIDI

Data representation · A level · AQA 7517 4.5.6.7, Eduqas A500QS 2.3 · about 30 min

BugBotLab
NameClassDate

What this lesson is about

Sample rate, sample resolution, the Nyquist theorem and aliasing, and MIDI events played on the robot's piezo.

Questions 6 marks in all

  1. [1 mark]How many bytes does a 30 second mono recording take at a sampling rate of 8,000 Hz and a sample resolution of 8 bits?

  2. [1 mark]A recording must keep frequencies up to 5,000 Hz. What is the lowest sampling rate, in Hz, the Nyquist theorem allows?

  3. [1 mark]A 440 Hz tone is sampled at 600 Hz. What happens?

    1. AIt is recorded as a lower, wrong frequency: aliasing
    2. BIt is recorded correctly
    3. CIt is recorded as silence
    4. DIt is recorded at twice the frequency
  4. [1 mark]Which of these are MIDI event messages or data carried in them?

    Tick every answer that is true.

    1. ANote on
    2. BNote off
    3. CVelocity
    4. DThe sampled sound wave
  5. [1 mark]Which is a disadvantage of MIDI compared with sampled sound?

    1. AIt cannot store speech or singing
    2. BIts files are larger
    3. CIt is hard to change the tempo
    4. DIt cannot change instrument
  6. [1 mark]What does this program print?

    for note in [57, 69, 81]:
        print(note, round(440 * 2 ** ((note - 69) / 12)))

The task: play the MIDI events

events is a list of (note, seconds) pairs: note is a MIDI note number (0 to 127) and seconds is how long to play it. 1. Write frequency(note), which returns 440 × 2^((note - 69) / 12) rounded to the nearest whole number with round, as an int. 2. For each event in order, print note <note> = <frequency> Hz and play it on the piezo with tone(frequency, seconds). 3. After the last note, print minimum sample rate: <n> Hz, where n is twice the highest frequency you played: the Nyquist rate for recording those notes' fundamental frequencies. Calculate every frequency; do not type them in.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

events = [(60, 0.25), (64, 0.25), (67, 0.25), (72, 0.5)]

def frequency(note):
    return 440

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/a7-8-sound-and-midi/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add a velocity to each event and print it next to the note. Why can the piezo not show it?
  2. How many bytes would the four notes take as 8-bit mono samples at 8,000 Hz? Compare that with a few bytes per MIDI event.
  3. At what sampling rate would note 108, the top of a piano, alias?