From 18c9ae73f4dd170a69df03822193c3044f68f194 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 17 Sep 2019 11:52:42 +0100 Subject: [PATCH] Tidy up noise examples --- examples/noise-amps-at-freqs.py | 19 +++++++++++-------- examples/noise-profile.py | 11 ++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) mode change 100644 => 100755 examples/noise-amps-at-freqs.py mode change 100644 => 100755 examples/noise-profile.py diff --git a/examples/noise-amps-at-freqs.py b/examples/noise-amps-at-freqs.py old mode 100644 new mode 100755 index 0a8040b..8b1ddd5 --- a/examples/noise-amps-at-freqs.py +++ b/examples/noise-amps-at-freqs.py @@ -2,11 +2,15 @@ import ST7735 from PIL import Image, ImageDraw from enviroplus.noise import Noise -SAMPLERATE = 16000 +print("""noise-amps-at-freqs.py - Measure amplitude from specific frequency bins -FREQ_LOW = 100.0 -FREQ_HIGH = 2000.0 -WIDTH = 100 +This example retrieves the median amplitude from 3 user-specified frequency ranges and plots them in Blue, Green and Red on the Enviro+ display. + +As you play a continuous rising tone on your phone, you should notice peaks that correspond to the frequency entering each range. + +Press Ctrl+C to exit! + +""") noise = Noise() @@ -25,9 +29,9 @@ draw = ImageDraw.Draw(img) while True: amps = noise.get_amplitudes_at_frequency_ranges([ - (100,200), - (500,600), - (1000,1200) + (100, 200), + (500, 600), + (1000, 1200) ]) amps = [n * 32 for n in amps] img2 = img.copy() @@ -38,4 +42,3 @@ while True: draw.line((0, 0, 0, amps[2]), fill=(255, 0, 0)) disp.display(img) - diff --git a/examples/noise-profile.py b/examples/noise-profile.py old mode 100644 new mode 100755 index 70aa6ab..964dead --- a/examples/noise-profile.py +++ b/examples/noise-profile.py @@ -2,11 +2,13 @@ import ST7735 from PIL import Image, ImageDraw from enviroplus.noise import Noise -SAMPLERATE = 16000 +print("""noise-profile.py - Get a simple noise profile. -FREQ_LOW = 100.0 -FREQ_HIGH = 2000.0 -WIDTH = 100 +This example grabs a basic 3-bin noise profile of low, medium and high frequency noise, plotting the noise characteristics as coloured bars. + +Press Ctrl+C to exit! + +""") noise = Noise() @@ -36,4 +38,3 @@ while True: draw.line((0, 0, 0, amp), fill=(int(low), int(mid), int(high))) disp.display(img) - -- 2.30.2