function example_fft(a,~,N)

% subfunction for rectangular pulses
function [x] = pulse(a,b,N)
    x = zeros(N,1);
    
    for i = (N-1)/2-fix(a/b):(N-1)/2+fix(a/b)
    % for i = (N-1)/2-a*b:b:(N-1)/2+a*b
        x(i) = 1;
    end
end

% Fourier coefficients
for b = 1:3
    subplot(4,3,b);
    % create the pulse
    x = pulse(a,b,N);
    % plot the pulse (time domain)
    stem(x); axis([0 N 0 1]);
    
    subplot(4,3,b+3);
    % take fft
    y = fft(x,N);
    % compute the magnitude of fft
    z = abs(y);
    % plot the coefficients (frequency domain)
    plot(z); axis([0 N 0 5]);
    
    % normalize the frequency scale to [0 1-1/N]
    subplot(4,3,b+6);
    ff = (0:(N-1))/N;
    plot(ff,z);
    
    % let fs be the sampling frequency (at least twice the highest freq.) 
    %then its better to plot instead from 0 to fs, the spectrum -fs/2 to fs/2
    subplot(4,3,b+9);
    % amplitude scaling
    zs = fftshift(z);
    ff2 = (-N/2:N/2-1)/N;
    plot(ff2,zs);
end

end
