% MATLAB_EX_1 shows a simple example of fft in practice
%
% file:      	matlab_ex_1.m, (c) Matthew Roughan, Sat Aug  7 2004
% directory:   /home/mroughan/Classes/Transformations/2004/Matlab/
% 
%
f_s = 1000;            % sampling frequency
x = 1:1/f_s:10;        % sample points
N = length(x);

%%%%  sampled signal
f_0 = 100;             % frequency 0 in the signal
f_1 = 200;             % frequency 1 in the signal
y = sin(2*pi*f_0*x) + sin(2*pi*f_1*x);   

%%%%  FFT of data
z = fft(y);
freq = (0:N-1) * f_s/N;

%%%%  plot the data
semilogy(freq, abs(z).^2, 'linewidth', 3);

%%%% make the axes pretty and add labels
grid on
set(gca, 'ylim', 10.^[-2 9], 'ytick',  10.^[-2:2:9], 'xtick', [0:200:1000]);
set(gca, 'linewidth', 3, 'fontsize', 18);
xlabel('frequency (Hz)');

%%%% print out a copy
print('-depsc', 'Plots/matlab_ex_2.eps');
