Sampling Frequency of 44100 Hz ValueError: min() arg is an empty sequence
See original GitHub issueHi
I am running into an issue with using this module to calculate the BPM of a .wav file sampled at 44100Hz (Python 3.6)
This is the error which I get:
Traceback (most recent call last):
File "/Users/JohnDoe/Desktop/TensorFlow_Programs/Heart-Sounds-Deep-Learning/heart-rate-analysis-module/UsingHeartbeatModule.py", line 15, in <module>
measures = hb.process(data, 44100)
File "/Users/JohnDoe/Desktop/TensorFlow_Programs/Heart-Sounds-Deep-Learning/heart-rate-analysis-module/heartbeat.py", line 205, in process
fit_peaks(hrdata, rol_mean, fs)
File "/Users/JohnDoe/Desktop/TensorFlow_Programs/Heart-Sounds-Deep-Learning/heart-rate-analysis-module/heartbeat.py", line 124, in fit_peaks
working_data['best'] = min(valid_ma, key = lambda t: t[0])[1]
ValueError: min() arg is an empty sequence
I am using your heart-rate module to calculate the BPM (shown below):
import heartbeat as hb
from scipy.io import wavfile as wav
import numpy
import pandas as pd
RAW_CSV_NAME = "/Users/JohnDoe/Desktop/TensorFlow_Programs/Heart-Sounds-Deep-Learning/pls.csv"
fs, data = wav.read('/Users/JohnDoe/Desktop/output_test.wav')
df = pd.DataFrame(data)
df.columns=['hart']
df.to_csv(RAW_CSV_NAME, index=False, header="hart" )
print("Sampling frequency " + str(fs)) --> prints 44100
hrdata = hb.get_data(RAW_CSV_NAME, column_name = 'hart')
measures = hb.process(data, 44100)
print(measures['bpm']) #returns BPM value
print(measures['lf/hf']) # returns LF:HF ratio
#Alternatively, use dictionary stored in module:
print(hb.measures['bpm']) #returns BPM value
print(hb.measures['lf/hf']) # returns LF:HF ratio
Here is the code for recording with PyAudio
import pyaudio
import wave
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 30
WAVE_OUTPUT_FILENAME = "/Users/sreeharirammohan/Desktop/output_test.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
I was wondering if you could help me fix this Sampling Rate Issue. Any Guidance would be greatly appreciated!
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
python - Why do I keep getting the error "min() arg is an empty ...
Can you help me please because I keep getting the error message: min() arg is an empty sequence. (I have the numbers 15,...
Read more >Python ValueError: max() arg is an empty sequence Solution
A variation of the “ValueError: max() arg is an empty sequence” error is found when you try to pass an empty list into...
Read more >python-sounddevice - Read the Docs
latency (or the latency argument of playrec(), Stream etc.) is set to 'high'. 'default_samplerate'. The default sampling frequency of the device ...
Read more >Sequences and Difference Equations - Springer Link
CD quality means 44100 samples per second. Other sample rates are also possible, so we introduce r as the sample rate. An f...
Read more >Python sounddevice - Read the Docs
Assuming you have a NumPy array named myarray holding audio data with a sampling frequency of fs (in the most cases this will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@paulvangentcom
Sorry for late response, I’ve had a high fever for the last few days so I wasn’t able to get the recordings.
I’ve attached 5 30 second heartbeat sounds. One thing I found strange was that these recordings had more static than the previous ones. I was wondering if you could maybe filter the sound before taking the BPM?
heartbeat #1 https://drive.google.com/file/d/1wpSxodLQtFwSoY5vWB41rmyGp1FxUG7e/view?usp=sharing
heartbeat #2 https://drive.google.com/file/d/1XkhtKpBCq71mjLvJ5WsqQjmyb49uLSPV/view?usp=sharing
heartbeat #3 https://drive.google.com/file/d/1gKuvgfwf9MLriGKvi9TikDudSw3_ru8u/view?usp=sharing
heartbeat #4 https://drive.google.com/file/d/1QhyRPvV72oEIXEtBUgsWNuMkEhW29uuF/view?usp=sharing
heartbeat #5 https://drive.google.com/file/d/14sUSfIO3rQAb45ipyq_fmD-zn15pN2vL/view?usp=sharing
Let me know if you need more heartbeat recordings.
Looking forward to seeing the improvements!
Please clone the most recent commit. I’ve changed the sampling rate calculation method. Let me know if this fixes it for you. It should work now (on my windows machine mem usage peaks at 129.9mb). If it doesn’t, try changing ‘1000’ at line 81 to ‘100’ so you resample to 100Hz in stead of 1000Hz.
I’ll optimize the audio detection later in the week. Could you send me a few more recordings so I can fine tune?