I'm new to DSP and I have a wav file with a number of different frequencies playing at different volumes. I'd like to plot the power of the 350Hz frequency signal at each point in time. The source is rotating so should see the power rising and falling periodically. To start with I broke the signal up into windows and then implemented Geortzel's algorithm (from Wikipedia). This seems to work: https://www.dropbox.com/s/aq1aigdx8dq306q/Screenshot%202015-03-18%2017.38.20.png?dl=0 but for different window length and window overlaps I get different plots.
I'd love some guidance on what the correct way to choose the window length and the amount by which each window overlap is?
window_skip in the code.
Also should the windows be processed (i.e. convolved with a window function like Hanning) I've read about this but I'm not clear on what this would do to the output, nor how to choose the length of the window function?
Here's the audio file: https://www.dropbox.com/s/knvwqwg7s3mcz56/example.wav?dl=0
Here's my code, comments welcome:
import pylab import scipy.io.wavfile import numpy as np import math def goetrzel(data, target_frequency): s_prev = 0 s_prev2 = 0 normalized_frequency = 2.0 * np.pi * target_frequency / len(data) coeff = 2.0 * np.cos(normalized_frequency) for sample in data: s = sample + coeff * s_prev - s_prev2 s_prev2 = s_prev s_prev = s power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev * s_prev2 return power def sliding_window(data, length, skip=None): if skip is None: skip = length n = len(data) for i in range(0, n - int(length), int(skip)): yield data[i:i+length] detect_frequency = 350.0 #detect_frequency = 485.0 #detect_frequency = 633.0 #detect_frequency = 796.0 rate, data = scipy.io.wavfile.read('example.wav') window_length = 2 * detect_frequency # How should I pick this? window_skip = window_length # How should I pick this? power = [goetrzel(window, detect_frequency) for window in sliding_window(data, window_length, window_skip)] pylab.figure() pylab.plot(power) pylab.show()