Interpreting the output of fft() operation in Matlab
It might be interesting to interpret the output of the fft() function in Matlab. Consider the following simple examples.
fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency
N = 128; % fft size
% generating the time domain signal
x1T = exp(j*2*pi*fcMHz*[0:N-1]/fsMHz);
x1F = fft(xt,N); % 128 pt FFT
figure;
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel(’frequency, MHz’)
ylabel(’amplitude’)
title(’frequency response of complex sinusoidal signal’);
With anpoint fft() and sampling frequency of
, the observable spectrum from
is split to
sub-carriers.
Additionally, the signal at the output of fft() is from . As the frequencies from
get aliased to
, the operator fftshift() is used when plotting the spectrum.
In the example above, with a sampling frequency of 20MHz, the spectrum from [-10MHz, +10MHz) is divided into 128 sub-carriers with spaced apart by 20MHz/128 = 156.25kHz. The generated signal x1T of frequency 1.5625MHz corresponds to the information on the 10th sub-carrier, which can also be generated in the frequency domain.
% generating the frequency domain signal with subcarrier indices [-N/2:-1 dc 1:N/2-1]
x2F = [zeros(1,N/2) 0 zeros(1,9) 1 zeros(1,N/2-10-1)]; % valid frequency on 10th subcarrier, rest all zeros
x2T = N*ifft(fftshift(x2F)); % time domain signal using ifft()
% comparing the signals
diff = x2T - x1T;
err = diff*diff’/length(diff)
Plotting the frequency response of a filter
Consider a filter with the a sinc() shaped impulse response. The Matlab code for plotting the frequency response is as follows:
% impulse response of a sinc() filter
hT = sinc([-20:20]/3); % consider sample at 30MHz sampling;
hF = fft(hT,1024); % 128 pt FFT
figure;
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel(’frequency, MHz’)
ylabel(’amplitude’)
title(’frequency response of sinc filter’);
Hopefully, the post provides some insights on the query raised in the comp.dsp thread.
Please click here to SUBSCRIBE to newsletter and download the FREE e-Book on probability of error in AWGN. Thanks for visiting! Happy learning.
If you liked this post, you may leave a comment below, or subscribe to the RSS feed.






























I want to do program of radix4 ( loop) pls help me