Class: STFTSpectrogram::Spectrogram
- Inherits:
-
Object
- Object
- STFTSpectrogram::Spectrogram
- Defined in:
- lib/stft/spectrogram.rb
Overview
Represents time-frequency spectrogram
Instance Attribute Summary collapse
-
#windows ⇒ Object
readonly
Returns the value of attribute windows.
Instance Method Summary collapse
-
#filter(low, high) ⇒ Object
Sets low and high frequency filters.
-
#freqs ⇒ Object
Returns an array with all frequencies.
-
#initialize(audio, window_size, window_overlap) ⇒ Spectrogram
constructor
A new instance of Spectrogram.
-
#max_freq ⇒ Object
Gets the highest frequency.
-
#transform! ⇒ Object
Performs FFT on all timed data windows.
-
#transformed? ⇒ Boolean
Returns true if FFT was already performed.
Constructor Details
#initialize(audio, window_size, window_overlap) ⇒ Spectrogram
Returns a new instance of Spectrogram.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/stft/spectrogram.rb', line 9 def initialize(audio, window_size, window_overlap) if window_size <= window_overlap raise ArgumentError, 'Window size cannot be <= window overlap!' end @windows = [] @transformed = false audio.window_size = window_size audio.window_overlap = window_overlap split_to_windows(audio) audio.reset end |
Instance Attribute Details
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
7 8 9 |
# File 'lib/stft/spectrogram.rb', line 7 def windows @windows end |
Instance Method Details
#filter(low, high) ⇒ Object
Sets low and high frequency filters
47 48 49 50 51 52 |
# File 'lib/stft/spectrogram.rb', line 47 def filter(low, high) @windows.each do |w| w.low = low w.high = high end end |
#freqs ⇒ Object
Returns an array with all frequencies
41 42 43 44 |
# File 'lib/stft/spectrogram.rb', line 41 def freqs return [] unless transformed? @windows[0].freqs end |
#max_freq ⇒ Object
Gets the highest frequency
35 36 37 38 |
# File 'lib/stft/spectrogram.rb', line 35 def max_freq return 0 unless transformed? @windows[0].max_freq end |
#transform! ⇒ Object
Performs FFT on all timed data windows
29 30 31 32 |
# File 'lib/stft/spectrogram.rb', line 29 def transform! @windows.each(&:do_fft!) @transformed = true end |
#transformed? ⇒ Boolean
Returns true if FFT was already performed
55 56 57 |
# File 'lib/stft/spectrogram.rb', line 55 def transformed? @transformed end |