The python code below generates a histogram from a .wav file, but what exactly does the histogram show? Is the x axis amplitude binned by sampling rate? Is the y axis a count of how many samples are in each amplitude bin? And how is amplitude calculated?

import numpy as np
import matplotlib.pyplot as plt
Fs, data = wavfile.read('audio file') 

plt.hist(data, bins='auto')  

It seems we have a confusion with the meaning of the term frequency in different contexts.

In signal processing we tend to use the term frequency as a measure of the rate in the a signal completes a cycle.

In statistic the frequency of an event is number of times an event occurs.

The histogram plots frequencies in the statistic sense. Each bin corresponds to an event defined as "the sample has value in the interval $b_k < x_i < b_{k+1}$", where $b_k$ corresponds to the position of the vertical edges of each bar in your histogram.

So what you are plotting in the histogram is associated with how many times the sample amplitude lied in each of those ranges.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.