graphics_toolkit("qt")
d = 4; % amount to add to text sizes
set(0, "DefaultFigureColor",.94*[1 1 1]) % This coloring between subplots does not show up in the .svg output.
set(0, "DefaultAxesFontsize",12+d) % size of numeric tick labels
set(0, "DefaultTextFontsize",12+d)
T = 0.01; % seconds per sample
sam_per_sec = 1/T;
N = 128; % number of frequency samples
N2 = N/2;
Hz_per_bin = sam_per_sec/N % no semi-colon, so value is displayed in Octave command window
L = 11; % pulse_width (samples)
L2 = (L-1)/2;
s = [ones(1,L) zeros(1,N-L)]; % Zero-fill the signal so a DFT produces N frequency samples.
S = fft(circshift(s,-L2)); % Rotate s() to take advantage of symmetry. S() is therefore real-valued.
hfig = figure("position",[1 1 1000 800]);
subplot(2,1,1)
plot((-N2:N2-1)*T, circshift(s,N2-L2), "linewidth",3) % Center the pulse at 0 seconds.
xlim([-N2 N2-1]*T)
ylim([0 2])
title("Signal", "fontsize",14+d)
xlabel("Actual time (seconds)", "fontsize",12+d)
subplot(2,1,2)
plot(0:N2-1, S(1:N2)) % Plot the discrete-time Fourier transform.
hold on
plot(0:N2-1, S(1:N2), ".", "markersize",12, "color","blue") % Overlay the DTFT samples.
xlim([0 N2-1])
set(gca, "xaxislocation","origin")
set(gca, "xtick",0:10:N2-1) %, "fontsize",12) ~ optional code
title("Fourier transform samples", "fontsize",14+d)
xlabel("Normalized frequency (0.7812 Hz/bin)")