› Forums › Foundations of speech › Signal processing › Understanding the term “bin”
- This topic has 9 replies, 2 voices, and was last updated 3 years, 10 months ago by Simon.
-
AuthorPosts
-
-
October 12, 2020 at 20:50 #12360
In the jupyter notebooks about signal processing, sometimes there is the term “bin”. We have talked about it in our last tutorial session, and I have tried to understand what bins are but I still struggle a bit, so any comments would be very helpful!
Let’s assume we have an impulse train with 64 samples, a sampling rate of 64 Hz and we would like to have an impulse every 4 samples (like in sp-m2-1-impulse-as-source.ipynb).
Then this means that each sample must have a duration of 1/64 s because we have 64 samples per second. The sample duration & the fact that there is an impulse every 4 samples gives me the fundamental period T_0 of 1/64 s * 4 = 1/16 s. This means the impuls train has a fundamental frequency of 16 Hz.
If I understand it correctly, bins are then the discrete frequencies of the basis functions (which is part of the DFT output) that are used to reconstruct the impuls train. So one bin would be 16 Hz and the next one is 32 Hz according to the plot in the jupyter notebook.
The first thing that I don’t understand is: I thought the lowest frequency is determined by the duration of the signal which is 1 s in this case. The simplest possible basis function with 1 Hz (a sine wave) can fit into 1 s which gives me a frequency of 1 cycle per second = 1 Hz.
Is the lowest frequency in a magnitude spectrum rather determined by the fundamental frequency than the duration of the signal or what do I understand wrong?In a different scenario, we have an impulse train with 64 samples, a sampling rate of 64 Hz and we would like to have an impulse every 5 samples. Doing similar computations as above, I get to a fundamental frequency of 12.8 Hz. As is not possible to have a pure sine wave with 12.8 cycles per second, there is no exact frequency of a basis function (i.e. there is no exact bin) which can be used to reconstruct this signal. This is why we see leakage in the magnitude spectrum which means that all bins that are close to 12.8 have a positive magnitude. Is this correct?
The second point that isn’t clear to me is: when looking at the magnitude spectrum of a single impulse in Exercise 1.1 of sp-m2-1-impulse-as-source.ipynb, there is a comment which says “## You should see that magnitudes for all the bins is one”. The magnitude at each frequency is one but why are we talking about bins here? Does this mean a single impulse can be reconstructed by using all basis functions with frequencies from 1 to 32 Hz even if a single impulse doesn’t have a fundamental frequency?
-
October 13, 2020 at 17:02 #12421
You are correct: “bins are then the discrete frequencies of the basis functions” – they are indexed by k in the DFT equation in the notebooks.
The DFT bins are determined only by the duration of the analysis frame and the sampling rate. They do not and cannot depend on the signal (e.g., on its fundamental frequency), because the DFT works for any signal and gives the same frequency resolution in all cases (for a particular sampling rate and analysis frame duration).
You correctly state that, for a 1 s analysis frame duration, the lowest frequency bin will be at 1 Hz. (We don’t even need to know the sampling rate to work this out.)
You are also correct in stating that when analysing a signal with energy at an “awkward” frequency (i.e., not an exact bin frequency), we will get leakage across several adjacent bins around that frequency.
Your final point is also correct: to construct a single impulse, we need to sum together all basis functions with equal amplitudes. The spectrum is flat, and there are no harmonics (because the single impulse is not a periodic signal).
Overall, your understanding looks pretty good!
-
October 13, 2020 at 17:49 #12427
I’m glad to hear that, thank you!
But then in the example/exercise in notebook sp-m2-1-impulse-as-source.ipynb, where there is an impulse train with 64 samples (see impulse-train.png attached) – why is then the lowest frequency in the magnitude spectrum at 1 Hz and not at 0 Hz (see magnitude-spectrum.png)?
The other frequencies that have a positive magnitude make sense to me in this plot, but I can not get the first one.Attachments:
You must be logged in to view attached files. -
October 13, 2020 at 18:27 #12433
In your plot, make sure you know the difference between bins (all the red points) and the energy in the signal (in this case, the harmonics) which are only the red points with non-zero magnitude.
Earlier, we agreed that the lowest frequency basis function is the one with a single cycle in the analysis frame (e.g., 1 Hz for a 1 s analysis frame).
Your plot is consistent with that, except that there is also a bin at 0 Hz. We often disregard this because it doesn’t tell us about the frequency content of the signal, but about something else.
To understand why there is some energy at 0 Hz, and what that means, can you first describe what that 0 Hz basis function looks like?
-
October 13, 2020 at 18:42 #12435
This means the plot shows me all possible basis functions that could be used to reconstruct the original signal, but only the bins that have a magnitude > 0 are relevant? So DFT will just output 0 dB for the first possible basis function and every other basis function that is not a component of the original signal?
A 0 Hz basis function has no cycles per second, but as it is a basis function it still has to be a sinusoid. So it’s difficult for me to imagine that.
Maybe it is a flat line on the x-axis or it doesn’t exist?
-
October 13, 2020 at 18:54 #12437
Yes, that’s correct – we always plot all the bins, even if their magnitude is zero. Normally we just join them up with a line for easy visualisation, but the notebooks plot them as distinct points to help you understand the process.
Your last sentence gets it: the 0 Hz basis function is a horizontal line. It’s not at 0 because that wouldn’t be much use when weighted and summed to make the signal being analysed, so it’s at an amplitude of 1.
We need this 0 Hz component to account for any offset (bias) in the signal: is it on average above zero, below zero, or centred on zero?
-
October 13, 2020 at 19:19 #12438
I would say the 0 Hz component is on average centered on zero, just because all the speech signals that we’ve looked at so far were centered on zero in the time domain.
What does then a magnitude > 0 dB mean in the magnitude spectrum?
Or how does the energy at 0 Hz relate to a bias? -
October 13, 2020 at 19:59 #12439
Is the waveform of an impulse train centred on zero?
-
October 13, 2020 at 20:17 #12440
I would say it is centred above zero because it has no values with a negative amplitude?
-
October 13, 2020 at 21:30 #12441
Yes, that’s why there is a non-zero magnitude in the 0 Hz DFT bin.
-
-
AuthorPosts
- You must be logged in to reply to this topic.