frequency bin of the positive and negative frequency

109 views (last 30 days)
I am using matlab tutorial Frequency-Domain Linear Regression for Frequency-Domain Linear Regression. There is one part of code, where is necessary to determine "frequency bin of the positive and negative frequency", for fft and ifft, this part of code:
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 there is 12 months is one cycle. How there can be only one frequency bin for positive frequency, how do we know that is exactly 72/12+1 (+1 is because first bin is for zero frequency), is that some formula or what?

Answers (1)

Star Strider
Star Strider on 30 Dec 2016
The documentation in that example is less than clear with respect to ‘negative frequencies’. The ‘negative frequencies’ derive from the way the two-sided Fourier transform (as computed by fft) is characteristically depicted.
The fft function returns a vector that appears to begin at the zero frequency and extends to the sampling frequency. In reality, the fft can only represent frequencies up to the Nyquist frequency (half the sampling frequency, see the Wikipedia article on the Nyquist–Shannon sampling theorem for details), so what are the Fourier transform amplitudes ‘frequencies’ (actually, ‘frequency bins’, not actual frequencies) above the Nyquist frequency doing there?
The reason is that the Fourier transform is symmetric about the y-axis, because the Fourier transform is mathematically defined on the interval (-Inf,Inf). The actual Fourier transform therefore has negative frequencies. (These are actual frequencies.) Shifting the fft output (using the fftshift function) illustrates this.
Because of the symmetry, the amplitudes at both the positive and negative frequencies are necessary to correctly calculate the inverse Fourier transform (using the ifft function).
The Plot
The Code
figure(1)
subplot(2,1,1)
plot(abs(tsdft))
hold on
plot([freqbins(1) freqbins(1)], ylim, '-r')
plot([freqbins(2) freqbins(2)], ylim, '-r')
hold off
xlabel('Frequency Bin')
ylabel('Amplitude')
title('Original Fourier Transform')
q = [-36:35];
subplot(2,1,2)
plot([-36:35], fftshift(abs(tsdft)))
hold on
plot(1-[freqbins(1) freqbins(1)], ylim, '-r')
plot(73-[freqbins(2) freqbins(2)], ylim, '-r')
hold off
xlabel('Frequency Bin')
ylabel('Amplitude')
title('Shifted Fourier Transform Showing ‘Negative Frequencies’')

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!