pkg load signal
graphics_toolkit gnuplot
clear all; close all; clc
function out=gauss(sigma,M)
out=exp(-.5*(((0:M)-M/2)/(sigma*M/2)).^2);
endfunction
M=5600; % big number, divisible by 7 and 8
window = gauss(0.4,M); % M+1 samples of a Gaussian window
N=8; % actual window size, in "hops"
% Sample the window.
% Scale the abscissa. 0:M samples --> 0:7 "hops", and take 8 symmetrical hops, from 0 to 7
sam_per_hop_7 = M/7;
%symmetric8 = window(1+(0:7)*sam_per_hop_7);
symmetric8 = exp(-.5*(((0:7)-7/2)/(.4*7/2)).^2); % Equivalent method
% Scale the abscissa. 0:M samples --> 0:8 "hops", and take 8 asymmetrical hops, from 0 to 7
sam_per_hop_8 = M/8;
%periodic8 = window(1+(0:7)*sam_per_hop_8);
periodic8 = exp(-.5*(((0:7)-8/2)/(.4*8/2)).^2); % Equivalent method
% Compare equivalent noise bandwidths (info only)
ENBW_symmetric8 = N*sum(symmetric8.^2)/sum(symmetric8)^2 % 1.6233
ENBW_periodic8 = N*sum(periodic8.^2) /sum(periodic8)^2 % 1.4533
%------------------------------------------------------------------
% Plot the points
figure("position", [100 200 700 400])
plot(0:7, symmetric8, "color","red", ".", "markersize",14)
hold on
plot(0:7, periodic8, "color","blue", ".", "markersize",14)
% Connect the dots
hops = (0:M)/sam_per_hop_8;
plot(hops, window, "color","blue") % periodic
hops = (0:M)/sam_per_hop_7;
plot(hops, window, "color","red") % symmetric
xlim([0 8])
set(gca, "xgrid","on")
set(gca, "ygrid","on")
set(gca, "ytick",[0:.25:1])
set(gca, "xtick",[0:8])
title("Two 8-point Gaussian window functions", "fontsize",14, "fontweight","normal");
xlabel('\leftarrow n \rightarrow', "fontsize",14)
text(2.96, .56, 'Matlab "symmetric" \rightarrow', 'color', 'red', 'FontSize',12)
str = {'\leftarrow Matlab "periodic"',' ("DFT-even")'};
text(5.1, .813, str, 'color', 'blue', 'FontSize',12)
#{
% After this call, the cursor units change to a normalized ([0,1]) coordinate system
% Draw an annotated right-to-left arrow.
annotation("textarrow", [.683 .644], [.738 .738],...
"color", "blue", "string", {'Matlab "periodic"',' ("DFT-even")'}, "fontsize",10,...
"linewidth",1, "headstyle","vback1", "headlength",5, "headwidth",5)
% Draw an annotated left-to-right arrow.
% Bug alert: Unlike the right-to-left arrow, it centers the text at the arrow start point.
% So the string of blanks in the 1st continuation line is a work-around for that.
annotation("textarrow", [.565 .62], [.542 .542],...
"color", "red", "string", {'Matlab "symmetric" '}, "fontsize",10,...
"linewidth",1, "headstyle","vback1", "headlength",5, "headwidth",5)
#}