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 1


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.)
  • $\begingroup$ 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)? $\endgroup$
    – nick_name
    Jan 1, 2017 at 14:48
  • $\begingroup$ What do you mean by frequency bin being decimal number? $\endgroup$
    – Tendero
    Jan 1, 2017 at 14:52
  • $\begingroup$ 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. $\endgroup$
    – nick_name
    Jan 1, 2017 at 15:02
  • $\begingroup$ 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. $\endgroup$
    – Tendero
    Jan 1, 2017 at 15:04
  • $\begingroup$ 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? $\endgroup$
    – nick_name
    Jan 9, 2017 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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