# Frequency bin of the positive and negative frequency

I am using this MATLAB tutorial for Frequency-Domain Linear Regression. There is one part of code they provide, where it is necessary to determine the "frequency bin of the positive and negative frequency", for fft and ifft:

freqbin = 72/12;
freqbins = [freqbin 72-freqbin]+1;
tsfit = zeros(72,1);
tsfit(freqbins) = tsdft(freqbins);
tsfit = ifft(tsfit);
mu = mean(ts);
tsfit = mu+tsfit;


Length of time series is $72$, and $12$ months is considered as one cycle.

• How can there be only one frequency bin for positive frequency?
• How do we know that it is exactly $72/12 + 1$ ($+1$ is because first bin is for zero frequency)? Is this some formula or what?

## 1 Answer

In the tutorial it is stated that

Because the frequencies are spaced at 1/72 and the first bin corresponds to 0 frequency, the correct bin is 72/12+1. This is the frequency bin of the positive frequency. You must also include the frequency bin corresponding to the negative frequency: -1 cycle/12 months. With MATLAB indexing, the frequency bin of the negative frequency is 72-72/12+1.

So, regarding your questions:

• It's not that there is only one bin for positive frequencies. The thing is that you are looking for a linear regression model, so you check what frequency is the most significant and then you create what would be the resulting vector if a DFT was made to a discrete sinusoid of that frequency only. That is your model.
• The bin number is not any weird formula or anything. You have data for every month, but in the tutorial they are looking for cycles per year. You have 6 years. So $72/12 =6$ and that's where it comes from. (As you said, the $+1$ comes from the fact that there is a bin corresponding to the mean value.)
• Thank you, but what if frequency bin is decimal number? And later I need to choose indexes in Fourier transformed time series with frequency bin (like in Matlab tutorial)? – nick_name Jan 1 '17 at 14:48
• What do you mean by frequency bin being decimal number? – Tendero Jan 1 '17 at 14:52
• Well, in my case, I am using this tutorial to do things in my time series. It is time seies with the same frequency, because it is with monthly values, but I have 91 terms. With same cycle of 12 months, I get frequency bin 91/12+1? I need to use that number in choosing vector component with same index like frequnecy bin. – nick_name Jan 1 '17 at 15:02
• I understand from what you're saying that you don't have information for some months, so I don't know how accurate would be to use cycles of years instead of months. However, for the missing information you could fill the vector with zeros to get full years. – Tendero Jan 1 '17 at 15:04
• In this tutorial is written that positive frequency bin is 72/12+1. On the other side there is formula k=fs/N, where N is number of terms in time series, fs is sampling frequency. In case with 72 terms sampling frequency is 1/12, when I put these articles in formula I get k=1/(91*12), that is not equal to upper (72/12), what did I miss? – nick_name Jan 9 '17 at 13:59