|
3 | 3 |
|
4 | 4 | 
|
5 | 5 |
|
6 |
| -**Quickstart:** The code below converts a WAV file to a spectrograph and saves it as an image. This code analyzed [Mozart's Piano Sonata No. 11 in A major](https://www.youtube.com/watch?v=aeEmGvm7kDk) to produce the picture above. |
| 6 | +## Quickstart |
| 7 | + |
| 8 | +### Song to Spectrogram |
| 9 | +The code below converts a WAV file to a spectrograph and saves it as an image. This code analyzed [Mozart's Piano Sonata No. 11 in A major](https://www.youtube.com/watch?v=aeEmGvm7kDk) to produce the picture above. |
7 | 10 |
|
8 | 11 | ```cs
|
9 |
| -var spec = new Spectrogram.Spectrogram(fftSize: 2048); |
10 |
| -float[] values = Spectrogram.WavFile.Read("mozart.wav"); |
11 |
| -spec.Add(values); |
12 |
| -spec.SaveImage("mozart.jpg"); |
| 12 | +// load audio and process FFT |
| 13 | +var spec = new Spectrogram.Spectrogram(sampleRate: 8000, fftSize: 2048, step: 700); |
| 14 | +float[] values = Spectrogram.Tools.ReadWav("mozart.wav"); |
| 15 | +spec.AddExtend(values); |
| 16 | + |
| 17 | +// convert FFT to an image and save it |
| 18 | +Bitmap bmp = spec.GetBitmap(intensity: 2, freqHigh: 2500); |
| 19 | +spec.SaveBitmap(bmp, "mozart.jpg"); |
13 | 20 | ```
|
14 | 21 |
|
15 |
| -## Realtime Audio Monitor |
| 22 | +### Human Voice |
| 23 | +This code analyzes audio from HAL's famous quote, "I'm sorry Dave, I'm afraid I can't do that". The output is can be rendered using different colormaps. |
16 | 24 |
|
17 |
| -A demo program is included which monitors the sound card and continuously creates spectrograms from microphone input. It runs fast enough that the entire bitmap can be recreated on each render. This means brightness and color adjustments can be applied to the whole image, not just new parts. |
| 25 | +```cs |
| 26 | +// load audio and process FFT |
| 27 | +var spec = new Spectrogram.Spectrogram(sampleRate: 15000, fftSize: 4096, step: 400); |
| 28 | +float[] values = Spectrogram.Tools.ReadMp3("cant-do-that.mp3"); |
| 29 | +spec.AddExtend(values); |
| 30 | + |
| 31 | +// convert FFT to an image and save it |
| 32 | +Bitmap bmp = spec.GetBitmap(intensity: .2, freqHigh: 1000, |
| 33 | + colormap: Spectrogram.Colormap.grayscaleInverted); |
| 34 | +spec.SaveBitmap(bmp, "cant-do-that-grayscale-inverted.jpg"); |
| 35 | +``` |
| 36 | +colormap | sample output |
| 37 | +---|--- |
| 38 | +**Grayscale Inverted** is used in many scientific publications when analyzing things like human voices and bird sounds| |
| 39 | +**Grayscale** provides highest contrast output but does not benefit from color vision| |
| 40 | +**Viridis** is the default colormap. It was specifically designed to represent 2D data in a way [ideally suited for human vision](https://www.youtube.com/watch?v=xAoljeRJ3lU).| |
| 41 | +**vdGreen** is the default colormap used for [QRSS-VD](https://github.com/swharden/QRSS-VD), a very old software project of mine. | |
18 | 42 |
|
19 |
| - |
| 43 | +### QRSS Analysis |
20 | 44 |
|
21 |
| -This demo is available as a click-to-run EXE in [/dev/compiled-demos/](/dev/compiled-demos/) |
| 45 | +Experimenters with ultra-narrowband radio transmissions often use continuous wave frequency-shifting radio transmitters to send data at very low rates over very long distances using very little power. See [_What is QRSS?_](https://www.qsl.net/m0ayf/What-is-QRSS.html) for more information. |
22 | 46 |
|
23 |
| -## QRSS Spectrograph |
| 47 | +The following code produces a QRSS spectrogram from an MP3 file. This program took less than 5 seconds to analyze 30 minutes of audio, producing the image below. |
24 | 48 |
|
25 |
| -This library may be useful for displaying QRSS signals. I added some QRSS audio to the [/data](/data) folder to practice analyzing. |
| 49 | +```cs |
| 50 | +// load audio and process FFT |
| 51 | +var spec = new Spectrogram.Spectrogram(sampleRate: 8000, fftSize: 16384, step: 8000); |
| 52 | +float[] values = Spectrogram.Tools.ReadMp3("qrss-w4hbk.mp3"); |
| 53 | +spec.AddExtend(values); |
| 54 | + |
| 55 | +// convert FFT to an image and save it |
| 56 | +Bitmap bmp = spec.GetBitmap(intensity: 1.5, freqLow: 1100, freqHigh: 1500, |
| 57 | + showTicks: true, tickSpacingHz: 50, tickSpacingSec: 60); |
| 58 | +spec.SaveBitmap(bmp, "qrss.png"); |
| 59 | +``` |
26 | 60 |
|
27 |
| - |
28 | 61 |
|
29 |
| -The image above is from 10 minutes of audio processed by the program below. The entire program took less than 2 seconds to run. |
| 62 | + |
30 | 63 |
|
31 |
| -```cs |
32 |
| -var spec = new Spectrogram.Spectrogram( |
33 |
| - fftSize: 8192, |
34 |
| - stepSize: 5000, |
35 |
| - intensity: 2, |
36 |
| - pixelLower: 1250, |
37 |
| - pixelUpper: 1500 |
38 |
| - ); |
39 |
| - |
40 |
| -float[] values = Spectrogram.WavFile.Read("qrss.wav"); |
41 |
| -spec.Add(values); |
42 |
| -spec.SaveImage("qrss.jpg"); |
43 |
| -``` |
| 64 | +## Demo Applications |
| 65 | +This project comes with a few interactive applications which serve as useful references for some of the ways this Spectrogram library can be used. |
44 | 66 |
|
45 |
| -#### New to QRSS? |
46 |
| - * [What is QRSS?](https://www.qsl.net/m0ayf/What-is-QRSS.html) |
47 |
| - * [QRSS and you](http://www.ka7oei.com/qrss1.html) |
48 |
| - * [QRSS (slow CW)](https://sites.google.com/site/qrssinfo/QRSS-Slow-CW) |
| 67 | +### Download Demo EXE Files |
| 68 | +If you want to see what this library can do without downloading source code, click-to-run (EXE) demos are available in **[SpectrogramDemo.zip](/dev/compiled-demos/SpectrogramDemo.zip)** |
49 | 69 |
|
50 |
| -## Waterfall |
51 |
| -This demo program was created to demonstrate Spectrogram and ScottPlot working together. |
| 70 | +### Audio Monitor |
52 | 71 |
|
53 |
| - |
| 72 | +A demo program is included which monitors the sound card and continuously creates spectrograms from microphone input. It runs fast enough that the entire bitmap can be recreated on each render. This means brightness and color adjustments can be applied to the whole image, not just new parts. |
54 | 73 |
|
55 |
| -## Developer Notes |
| 74 | + |
56 | 75 |
|
57 |
| - |
| 76 | +### Waterfall with Graphs |
| 77 | +This demo program was created to demonstrate Spectrogram and ScottPlot working together. |
58 | 78 |
|
59 |
| -### TODO: |
60 |
| -* ~~render horizontally or vertically~~ |
61 |
| -* ~~create bitmaps in real time from audio input~~ |
62 |
| -* ~~advanced color (LUT) options~~ |
63 |
| -* ~~advanced intensity options (nonlinear scaling)~~ |
64 |
| -* create a user control to display a spectrogram |
65 |
| -* create a user control to adjust spectrogram settings |
66 |
| -* ~~options for bitmap to scroll or to statically repeat~~ |
67 |
| -* create a way to convert between frequency and pixel position |
68 |
| -* optional display of axis labels (scales with ticks) |
| 79 | + |
| 80 | + |
| 81 | +## Resources |
69 | 82 |
|
70 | 83 | ### Similar Software
|
71 | 84 | * Argo ([website](http://digilander.libero.it/i2phd/argo/)) - closed-source QRSS viewer for Windows
|
72 | 85 | * SpectrumLab ([website](http://www.qsl.net/dl4yhf/spectra1.html)) - closed-source spectrum analyzer for Windows
|
73 | 86 | * QrssPIG ([GitLab](https://gitlab.com/hb9fxx/qrsspig)) - open-source spectrograph for Raspberry Pi (C++)
|
74 |
| -* Lopora ([website](http://www.qsl.net/pa2ohh/11lop.htm)) - open-source spectrograph (Python 3) |
| 87 | +* Lopora ([GitHub](https://github.com/swharden/Lopora)) - open-source spectrograph (Python 3) |
75 | 88 | * QRSS VD ([GitHub](https://github.com/swharden/QRSS-VD)) - open source spectrograph (Python 2)
|
76 | 89 |
|
77 |
| -### Spectrogram vs ~~Spectrograph~~ |
78 |
| -* A spectrogram is an image |
79 |
| -* A spectrograph is a machine |
80 |
| -* Stop using the word spectrograph in software! |
| 90 | +### QRSS Information |
| 91 | + * [What is QRSS?](https://www.qsl.net/m0ayf/What-is-QRSS.html) |
| 92 | + * [QRSS and you](http://www.ka7oei.com/qrss1.html) |
| 93 | + * [QRSS (slow CW)](https://sites.google.com/site/qrssinfo/QRSS-Slow-CW) |
0 commit comments