% program 'productwindow.m'
% Program to plot spectra of 2-D window functions

% cd c:\jl\4F8_imageprocessing\imageprocessing4\imageproc4mat

clear,clc,close all,home

disp('Choose 1-D window function');
disp('1. Rectangular');
disp('2. Hamming');
disp('3. Kaiser');
option=input('option = ');

% for a 15x15 support input U=7
U=input('Support for window function = ');
if option==1
	w=boxcar(2*U+1);
	string1=['Product of rectangular windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum of product of rectangular windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
elseif option==2
	w=hamming(2*U+1);
	string1=['Product of Hamming windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum of product of Hamming windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
elseif option==3
%	beta=input('Sidelobe attenuation Kaiser window (dB) = ');
%	beta=0.1102*(beta-8.7);
%       use beta=3 to start with
	beta=input('beta for Kaiser window = ');
	w=kaiser(2*U+1,beta);
	string1=['Product of Kaiser windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum of product of Kaiser windows, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];

end

N=64;
f=-0.5+(1/(N-1))*(0:N-1);

% Form 2-D window
w2=w*w';
figure(1);
mesh(w2)
title(string1);
rotate3d on;
pause

w2pad=zeros(N,N);
w2pad(1:2*U+1,1:2*U+1)=w2;
%figure(3)
%mesh(w2pad)
%pause;

W2pad=fft2(w2pad);
figure(2);
mesh(f,f,abs((W2pad)))
title(string2)
rotate3d on;
pause;
mesh(f,f,abs(fftshift(W2pad)))
title(string2)
rotate3d on;

