justus-tobias commited on
Commit
3d0b5bf
·
1 Parent(s): 4bc22ca

improved conversion

Browse files
Files changed (1) hide show
  1. utils.py +6 -3
utils.py CHANGED
@@ -515,10 +515,13 @@ def segment_analysis(segment, sr, s1s2:list):
515
  # RMS Energy
516
  rms_energy = np.sqrt(np.mean(segment**2))
517
 
518
- # Calculate actual mean frequency
519
- fft = np.fft.rfft(segment)
520
  freqs = np.fft.rfftfreq(len(segment), d=1/sr)
521
- mean_frequency = np.mean(freqs)
 
 
 
522
 
523
  s1_to_s2_duration = []
524
  s2_to_s1_duration = []
 
515
  # RMS Energy
516
  rms_energy = np.sqrt(np.mean(segment**2))
517
 
518
+ # Calculate frequency spectrum and find dominant frequencies
519
+ fft = np.abs(np.fft.rfft(segment))
520
  freqs = np.fft.rfftfreq(len(segment), d=1/sr)
521
+ # Focus on frequency range typical for heart sounds (20-200 Hz)
522
+ mask = (freqs >= 20) & (freqs <= 200)
523
+ dominant_freq_idx = np.argmax(fft[mask])
524
+ mean_frequency = freqs[mask][dominant_freq_idx]
525
 
526
  s1_to_s2_duration = []
527
  s2_to_s1_duration = []