% program rotatedwindow.m
% Program to plot spectra of 2-D window functions obtained by rotation of 
% 1-D window functions

% need to be in directory c:\jl\I8_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 = ');

U=input('Support for window function = ');
% use 7 to produce the pictures in the handouts
if option==1
	w=boxcar(2*U+1);
	string1=['Rotated rectangular window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum of rotated rectangular window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	w2=zeros(2*U+1,2*U+1);
	for n1=1:2*U+1
		for n2=1:2*U+1
			u=sqrt((n1-U)^2+(n2-U)^2);
			if u<=U
				w2(n1,n2)=1.0;
			end
		end
	end

elseif option==2
	string1=['Rotated Hamming window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum of rotated Hamming window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	w2=zeros(2*U+1,2*U+1);
	for n1=1:2*U+1
		for n2=1:2*U+1
			u=sqrt((n1-U)^2+(n2-U)^2);
			if u<=U
				w2(n1,n2)=0.54+0.46*cos(pi*u/U);
			end
		end
	end
elseif option==3
%	beta=input('Sidelobe attenuation Kaiser window (dB) = ');
%	beta=0.1102*(beta-8.7);
%       input beta=3 to reproduce figure in handouts
	beta=input('beta for Kaiser window = ');
	w=kaiser(2*U+1,beta);
	string1=['Rotated Kaiser window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	string2=['Spectrum rotated Kaiser window, N= '...
	,num2str(2*U+1),'*',num2str(2*U+1)];
	w2=zeros(2*U+1,2*U+1);
	for n1=1:2*U+1
		for n2=1:2*U+1
			u=sqrt((n1-U)^2+(n2-U)^2);
			if u<=U
				w2(n1,n2)=besseli(0,beta*sqrt(1-(u/U)^2))/besseli(0,beta);
			end
		end
	end

end

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

% Plot 2-D window
mesh(w2)
title(string1);
rotate3d on;
pause

w2pad=zeros(N,N);
w2pad(1:2*U+1,1:2*U+1)=w2;
W2pad=fft2(w2pad);
mesh(f,f,abs(fftshift(W2pad)))
title(string2)
rotate3d on

