This library is designed to analyze wav files generated by the diagnosis device to help interpret, visualize, and diagnose the respiratory state of a patient. As of 8/10/2022, the sound analysis portion of the project is composed of python code that completes filtering and spectral analysis of wav files. There is also some code written for the Teensy 4.1 (found under teensy_code), which currently reads and prints the value of a force sensitive resistor to the serial output, and also writes that data to a .txt file on an attached microSD card.
The main tool, stored in sound_analayis.py is designed to be used from the commandline for developer usage, but is ultimately designed to be written such that the analysis and graphing packages can be imported to other python scripts for machine-learning & other algorithmic analysis.
This function takes in a mono (or stereo, but it will be converted to mono) .wav file, and performs analysis of the file, with the command line output being an amplitude graph & spectrogram plot, as shown above. The green dots represent the spectral peaks at each spectrogram time period, or the first N (in this case, N=4) most intense frequencies at any given time.
foo@bar:~$ python3 sound_analysis.py filename.wav starting_time ending_time minimum_frequency maximum_frequency- filename.wav: Filename or file path of wav file to be analyzed.
- starting_time: Starting time (float, in s) to graph (i.e. minimum x-axis value).
- ending_time: Ending time (float, in s) to graph (i.e. maximum x-axis value). If ending time == "None", the program will default to the audio file's duration.
- minimum_frequency: Lowest frequency (int, Hz) to show on graph (i.e. minimum y-axis value).
- maximum_frequency: Highest frequency (int, Hz) to show on graph (i.e. maximum y-axis value).
Both min & max frequency also apply butterworth bandpass filtering according to the passed in frequencies. Using the script as a collection of imported functions allows more granularity (i.e. choosing exactly what to graph, how to filter, etc.).
respiration_phase.py takes in the Arduino readings from a force sensitive resistor(FSR), and classifies the respiration phase based off of the force exerted onto the FSR. After running, the proogram will output a graph of the raw, cleaned, and calculated data, showing visual classification of each respiratory cycle.
foo@bar:~$ python3 respiration_phase.py '~/your_breathing_data.txt' time_start time_end- '~/your_breathing_data.txt': The path & filename of a text file with integer values representing the force applied by a patient's chest measured via a force sesntive resistor.
- time_start: The first time to display on the graph (x min, in seconds).
- time_end: The last time to display on the graph (x max, in seconds).
- main: Implements spectral analysis through the scipy.signal.spectrogram function. Almost the enture development time of the project has been spent in this branch, and the other branches are there
- librosa: Implements spectral analysis through the the librosa spectral analysis package.
- specgram-test: Uses the prebuilt matplotlib specgram function instead of calling plt.pcolormesh as in main.
- numpy-fft: A mostly unchanged branch with the intent to implement spectral analysis manually through numpy. In the future, it may allow more granularity.