Commit 17a0d400 authored by Marco Berzborn's avatar Marco Berzborn Committed by Marco Berzborn

Deleted some obsolete functions and moved samplings into corresponding

folder
parent ba4883fa
function acData = ita_isht(acDataSH, gridData)
%ITA_ISHT - performs an inverse Spherical Harmonic transform on spherical data struct
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Author: Martin Pollow -- Email: mpo@akustik.rwth-aachen.de
% Created: 03-Dec-2008
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
acData = cell(size(acDataSH));
for n = 1:numel(acDataSH)
acData{n}.header = acDataSH{n}.header;
% TODO: neue EInheit
if isfield(acDataSH{n},'dat_SH')
oldFieldname = 'dat_SH';
newFieldname = 'dat';
elseif isfield(acDataSH{n},'spk_SH')
oldFieldname = 'spk_SH';
newFieldname = 'spk';
end
acData{n}.(newFieldname) = ita_sph_ISHT(acDataSH{n}.(oldFieldname), gridData);
end
\ No newline at end of file
function ita_plot_SH(coefs, sampling, varargin)
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
global sPlotPoints;
if nargin == 0, error; end;
if nargin > 1
% check if is a plot grid
if ~isa(sampling,'itaCoordinates')
varargin = [{sampling} varargin];
else
sPlotPoints = sampling;
end
end
% create sampling for plot if necessary
if isempty(sPlotPoints)
sPlotPoints = ita_sph_sampling_equiangular(31);
end
paraStruct = ita_sph_plot_parser(varargin);
% plottype = paraStruct.type;
% convert to given spatial grid
data = ita_sph_ISHT(coefs, sPlotPoints);
% call spatial plot function
[hFig, hSurf] = ita_sph_plot_spatial(data, sPlotPoints, varargin{:});
% now check if to plot dots also
colorSize = size(paraStruct.dotColor);
if colorSize(2) ~= 3
% there must be color dots given
% so plot them on the sphere
radiusBalloon = abs(ita_sph_functionvalue(coefs, paraStruct.dotSampling));
if strcmpi(paraStruct.type,'dB')
radiusBalloon = 20*log10(radiusBalloon);
end
% now set the radii
dotSampling_modifiedR = itaSamplingSph(paraStruct.dotSampling);
dotSampling_modifiedR.r = radiusBalloon;
[magn, color, colorMap] = ita_sph_plot_type(paraStruct.dotColor, paraStruct.type);
% set caxis
cminmax = caxis;
cmin = cminmax(1);
cmax = cminmax(2);
cmin = min(cmin, min(color));
cmax = max(cmax, max(color));
ita_plot_dots(dotSampling_modifiedR, 'dotColor', color,'caxis', [cmin cmax]);
end
function [hFig, hSurf] = ita_plot_balloon(spatial_data, sampling, varargin)
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% function [hFig, hSurf] = ita_sph_plot_spatial(data, sampling, varargin)
%ITA_SPH_PLOT_SPATIAL - plots a spatial spherical function (and sampling points)
% function ita_sph_plot_spatial(data, varargin)
%
% the optional parameter 'type' can be:
% 'complex' : radius is magnitude, color is phase
% 'sphere' : plots magnitude as color on unit sphere
% 'magnitude' : radius and color is magnitude
% 'spherephase' : plots phase as color on unit sphere
%
% the optional GeometryPoints and pointData give the information about
% spherical sampling points
% GeometryPoints.theta: vector of theta values
% GeometryPoints.phi: vector of phi values
% data: vector of sampling values
%
% type: default 'magnitude'
% GeometryPoints & pointData: default []
% axes: outer/inner, different 'design' (default: outer)
% fontsize: default 12, for axis annotations
% Martin Pollow (mpo@akustik.rwth-aachen.de)
% Institute of Technical Acoustics, RWTH Aachen, Germany
% 03.09.2008
% Modified: 14.01.2009 - mpe - parameter-structure:
% Complete rewrite: July-09 - mpo
% if nargin < 2
% sampling = data;
% data = ones(size(sampling));
%
% end
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
global sPlotPoints
if nargin == 0, error; end;
if nargin > 1
% check if is a plot grid
if ~isa(sampling,'itaCoordinates')
varargin = [{sampling} varargin];
else
sPlotPoints = sampling;
end
end
if isempty(sPlotPoints)
% use default: 64 x 64 equiangular grid (nmax = 31)
sPlotPoints = ita_sph_sampling_equiangular(31);
end
paraStruct = ita_sph_plot_parser(varargin);
type = paraStruct.type;
% get the values for the plot
[magn, color, colorMap] = ita_sph_plot_type(spatial_data,type);
% reshape for use in plot
% sizeGrid = size(sampling.weights);
dim = sPlotPoints.dim;
magn = reshape(magn,dim);
color = reshape(color,dim);
theta = reshape(sPlotPoints.theta,dim);
phi = reshape(sPlotPoints.phi,dim);
% add one vertical line of values to get a closed balloon
theta = theta(:,[1:end 1]);
phi = phi(:,[1:end 1]);
magn = magn(:,[1:end 1]);
color = color(:,[1:end 1]);
% plot the balloon
[X,Y,Z] = sph2cart(phi, pi/2 - theta, magn);
% hFig = figure;
hFig = gcf;
set(hFig, 'renderer', 'opengl')
hSurf = surf(X,Y,Z,color, 'EdgeAlpha', paraStruct.edgealpha, 'FaceAlpha', paraStruct.facealpha);
colorbar;
colormap(colorMap);
% set axes limits
maxMagn = max(max(magn));
if maxMagn > 0
xlim([-maxMagn maxMagn]);
ylim([-maxMagn maxMagn]);
zlim([-maxMagn maxMagn]);
end
daspect([1 1 1]);
axis vis3d
% set colorbar settings
if ismember(type, {'complex','spherephase'})
caxis([0 2*pi]);
else
caxis([0 maxMagn]);
end
grid on;
% bigger and fatter fonts
set(gca, 'FontSize', paraStruct.fontsize, 'FontWeight', 'bold');
% set background color to white
set(gcf, 'Color', 'w');
% view(90,0);
% view(3);
% view(0,90);
rotate3d;
xlabel('x');
ylabel('y');
zlabel('z');
switch paraStruct.axes
case 'inner'% alternative Achsen:
hold on;
maxim = max([max(max(abs(X))) max(max(abs(Y))) max(max(abs(Z)))]);
ak = [1.3*maxim -1.3*maxim]; nak = [0 0];
[X0,Y0] = pol2cart(0:pi/180:2*pi,1.1*maxim);
[X1,Y1] = pol2cart(0:pi/180:2*pi,1.0*maxim);
[X2,Y2] = pol2cart(0:pi/180:2*pi,0.9*maxim);
[X3,Y3] = pol2cart(0:pi/180:2*pi,0.8*maxim);
[X4,Y4] = pol2cart(0:pi/180:2*pi,0.7*maxim);
Z0=zeros(1,361);
plot3(ak, nak, nak, 'k', nak, ak, nak, 'k', nak, nak, ak, 'k');
text(1.35*maxim, 0, 0, 'x', 'FontSize', paraStruct.fontsize, 'FontWeight', 'bold'); text(0, 1.35*maxim, 0, 'y', 'FontSize', paraStruct.fontsize, 'FontWeight', 'bold'); text(0, 0, 1.35*maxim, 'z', 'FontSize', paraStruct.fontsize, 'FontWeight', 'bold');
plot3(X0,Y0,Z0,'k' ,X1,Y1,Z0,'k', X2,Y2,Z0,'k', X3,Y3,Z0,'k', X4,Y4,Z0,'k');
% kinder = get(gca,'Children');
grid off
axis off
case 'outer'
grid on
axis on
end
function acDataSH = ita_sht(acData, gridData, type)
%ITA_SHT - performs a Spherical Harmonic transform on spherical data struct
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Author: Martin Pollow -- Email: mpo@akustik.rwth-aachen.de
% Created: 03-Dec-2008
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
acDataSH = cell(size(acData));
for n = 1:numel(acData)
acDataSH{n}.header = acData{n}.header;
% TODO: neue EInheit
if isfield(acData{n},'dat')
oldFieldname = 'dat';
newFieldname = 'dat_SH';
elseif isfield(acData{n},'spk')
oldFieldname = 'spk';
newFieldname = 'spk_SH';
end
acDataSH{n}.(newFieldname) = ita_sph_SHT(acData{n}.(oldFieldname), gridData, type);
end
\ No newline at end of file
function [fRe, fIm] = ita_sph_complex2reim(fCompl)
%ITA_SPH_COMPLEX2REIM - converts complex function to real and imaginary part
% function [fRe, fIm] = ita_sph_complex2reim(fCompl)
%
% converts a spatial function given by its SH-coefficients to their
% real and imaginary part given also as SH-coefficients
% the resynthesis is: fCompl = fRe + j * fIm
%
% Martin Pollow (mpo@akustik.rwth-aachen.de)
% Institute of Technical Acoustics, RWTH Aachen, Germany
% 04.11.2008
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
nCoef = size(fCompl,1);
[degree, order] = ita_sph_linear2degreeorder(1:nCoef);
fRe = zeros(size(fCompl));
fIm = fRe;
for iCoef = 1:nCoef
m = order(iCoef);
% l = degree(iCoef);
if ~m % m=0
fRe(iCoef,:) = real(fCompl(iCoef,:));
fIm(iCoef,:) = imag(fCompl(iCoef,:));
elseif m > 0
fRe(iCoef,:) = (fCompl(iCoef,:) + (-1)^m * conj(fCompl(iCoef-(2*m))))/2;
fRe(iCoef-(2*m),:) = conj(fRe(iCoef,:)) * (-1)^m;
fIm(iCoef,:) = (fCompl(iCoef,:) - (-1)^m * conj(fCompl(iCoef-(2*m))))/(2*j);
fIm(iCoef-(2*m),:) = conj(fIm(iCoef,:)) * (-1)^m;
end
end
function sph = ita_sph_convert2vector(sph)
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
ita_verbose_obsolete('Marked as obsolete. Please report to mpo, if you still use this function.');
sph.theta = sph.theta(:);
sph.phi = sph.phi(:);
if isfield(sph,'r')
sph.r = sph.r(:);
end
sph.weights = sph.weights(:);
function correlation = ita_sph_correlationS2(F, G)
%ITA_SPH_CORRELATIONS2 - spatial correlation in SH-domain
% function correlation = ita_sph_correlationS2(F, G)
%
% computes the normalized spatial correlation of two functions
% on the 2-sphere in the spherical harmonic domain
%
% Martin Pollow (mpo@akustik.rwth-aachen.de)
% Institute of Technical Acoustics, RWTH Aachen, Germany
% 05.11.2008
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
ita_verbose_obsolete('Please use ita_sph_xcorr in future.')
if ~exist('G', 'var')
G = F;
end
if size(F,1) ~= size(G,1)
error('coefficient vectors must have the same size');
end
correlation = zeros(size(F,1),1);
for iFreq = 1:size(F,1)
correlation(iFreq) = conj(F(iFreq,:))*G(iFreq,:).'/(norm(F(iFreq,:))*norm(G(iFreq,:)));
end
\ No newline at end of file
This diff is collapsed.
function ita_sph_plot_SH(coefs, varargin)
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% check if 2nd parameter is the cell for the point plot
pointdata = [];
pointsampling = [];
if numel(varargin) && iscell(varargin{1})
pointcell = varargin{1};
if numel(pointcell) == 1
pointsampling = pointcell{1};
pointdata = pointsampling.r;
else
pointdata = pointcell{1};
pointsampling = pointcell{2};
end
varargin = varargin(2:end);
end
paraStruct = ita_sph_plot_parser(varargin);
plottype = paraStruct.type;
% load or make grid for plotting
persistent sampling
if ~isempty(paraStruct.sampling) && isa(paraStruct.sampling,'itaSamplingSph')
% a valid sampling given from input parameter
sampling = paraStruct.sampling;
elseif ~isa(sampling,'itaSamplingSph')
% persistant variable doesnt contain a valid grid
sampling = ita_sph_sampling_equiangular(64,64,'[]','[)');
end
% convert to given spatial grid
data = ita_sph_ISHT(coefs, sampling);
% call spatial plot function
[hFig, hSurf] = ita_sph_plot_spatial(data, sampling, varargin{:});
% do we want points on the sphere?
if ~isempty(pointdata)
% convert to spherical coordinates
% if ~strcmp(pointsampling.type,'sph')
pointsampling = cart2sph(pointsampling);
% end
[magn, color, colorMap] = ita_sph_plot_type(pointdata,plottype);
% sizeGrid = size(sampling.weights);
theta = pointsampling.theta;
phi = pointsampling.phi;
magn = reshape(magn,size(theta));
color = reshape(color,size(theta));
if numel(coefs) == 1
r_balloon = ones(size(theta)) .* coefs ./ sqrt(4*pi);
else
r_balloon = abs(ita_sph_functionvalue(coefs, pointsampling));
r_balloon = reshape(r_balloon,size(theta));
end
% find location of the dots
switch paraStruct.onballoon
case 'greater'
% all dots on or inside balloon
lineStyle = '-';
lineWidth = 3;
r_point = min(r_balloon, magn);
case 'smaller'
% all dot on or outsied balloon
lineStyle = ':';
lineWidth = 2;
r_point = max(r_balloon, magn);
case 'all'
% all dots on balloon
r_point = r_balloon;
otherwise
r_point = magn;
end
% find balloon radii
X = get(hSurf,'XData');
Y = get(hSurf,'YData');
Z = get(hSurf,'ZData');
R = sqrt(X.^2 + Y.^2 + Z.^2);
% maximum of balloon and dots
% maxVal = max(max(max(R(:)),max(magn)));
colorSurf = get(hSurf,'CData');
% maxColorSurf = max(max(colorSurf));
maxVal = max(max(colorSurf(:),max(color(:))));
% set colorbar data
if isempty(paraStruct.caxis)
% fix values
cmin = 0;
if strcmp(plottype,'complex') ...
|| strcmp(plottype,'spherephase')
cmax = 2*pi;
else
cmax = maxVal;
end
else
% parameter can change the colorbar data
cmin = paraStruct.caxis(1);
cmax = paraStruct.caxis(2);
if numel(cmax)
cmax = cmin;
end
end
caxis([cmin cmax]);
hold on
cmap = colormap(colorMap);
% length of color points
nPoints = size(cmap,1);
% from MatLab help "caxis":
% index = fix((color-cmin)/(cmax-cmin)*m)+1;
% fix the problem for the maximum value
% index(index >= m) = m;
index = fix((color-cmin)/(cmax-cmin)*(nPoints-1))+1;
x = r_point .* cos(phi) .* sin(theta);
y = r_point .* sin(phi) .* sin(theta);
z = r_point .* cos(theta);
nCmap = size(cmap,1);
for n = 1:nCmap
% indexBound element of 1..nCmap
indexBound = max(min(index,nCmap),1);
ind = (indexBound(:) == n);
plot3(x(ind), y(ind), z(ind), 'o', 'MarkerEdgeColor','k', 'MarkerFaceColor', cmap(n,:), 'MarkerSize',10);
end
if paraStruct.line
xSurf = r_balloon .* sin(theta) .* cos(phi);
ySurf = r_balloon .* sin(theta) .* sin(phi);
zSurf = r_balloon .* cos(theta);
line([xSurf x],[ySurf y],[zSurf z], 'LineWidth', lineWidth, 'Color', 'black','LineStyle',lineStyle);
end
end
hold off;
\ No newline at end of file
function ita_sph_plot_flat(GeometryGrid, GeometryPoints, GeometrySource, data, dataPoints, minmax, colorType)
%ITA_SPH_PLOT_FLAT - plots a projected spherical function (and sampling points)
% function ita_sph_plot_flat(GeometryGrid, GeometryPoints, GeometrySource, data, dataPoints, minmax, colorType)
%
% plots the approximated spherical function (data) on a flat surface, using
% cylindrical projection
% the discrete positions of sampling points are hereby given as circles,
% filled with an apropriate color
%
% GeometryGrid.theta: 2D-meshgrid of theta values (radians)
% GeometryGrid.phi: 2D-meshgrid of phi values (radians, '[0..2*pi)')
%
% Martin Pollow (mpo@akustik.rwth-aachen.de)
% Institute of Technical Acoustics, RWTH Aachen, Germany
% 03.09.2008
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% convert to spatial domain if given as SH vector
if size(data,1) == size(GeometryGrid.Y,2)
data = ISHT(data, g);
end
if nargin < 7
colorType = jet;
end
% rotate the target by pi
rot_steps = [0 size(GeometryGrid.phi,2)/2];
% phi = circshift(GeometryGrid.phi, rot_steps);
% theta = circshift(GeometryGrid.theta, rot_steps);
target = circshift(reshape(data, size(GeometryGrid.phi)), rot_steps);
% add another line to have full range between 0 and 2*pi
phi = [GeometryGrid.phi GeometryGrid.phi(:,1)+2*pi];
theta = [GeometryGrid.theta GeometryGrid.theta(:,1)];
target = [target target(:,1)];
% figure;
hold on
set(gcf, 'renderer', 'painters')
% white background, Position
set(gcf, 'color', 'w');%, 'Position', [1 1 700 500]);
cmap = colormap(colorType);
% extrema of color bar is calculated out of both directivity and pressure
% on microphones:
min_dataPoints = min(abs(dataPoints));
min_target = min(abs(data));
max_dataPoints = max(abs(dataPoints));
max_target = max(abs(data));
if nargin < 6
minmax = [min_dataPoints; max_dataPoints];
end
cmin = min([minmax(1) min_dataPoints min_target]);
cmax = max([minmax(2) max_dataPoints max_target]);
caxis([cmin cmax]);
% length of color points
m = size(cmap,1);
C = abs(dataPoints);
% from MatLab help "caxis":
index = fix((C-cmin)/(cmax-cmin)*m)+1;
% fix the problem for the maximum value
index(find(index >= m)) = m;
% set ranges
xlim([0 2*pi]);
ylim([0 pi]);
% put the north pole up
set(gca,'YDir','reverse')
% pcolor(con*phi2, con*theta2, abs(data2));
pcolor(phi, theta, abs(target));
for m = 1:size(dataPoints,1)
if m == 23, pointsign = 'v';
else pointsign = 'o';
end
C1 = mod(GeometryPoints.phi(m)+pi, 2*pi);
C2 = GeometryPoints.theta(m);
C3 = cmap(index(m),:);
plot(C1, C2, pointsign,'MarkerEdgeColor','k', ...
'MarkerFaceColor',C3,'MarkerSize',12);
end
for m = 1:length(GeometrySource.phi)
C1 = GeometrySource.phi(m);
C2 = GeometrySource.theta(m);
C3 = 'k';
pointsign = 'd';
plot(C1, C2, pointsign,'MarkerEdgeColor','k', ...
'MarkerFaceColor',C3,'MarkerSize',6);
end
% set ticks to pi values
set(gca, 'XTick', 0:pi:2*pi, 'YTick', 0:pi/4:pi);
% % set ticks to degree values
set(gca, 'XTick', (0:pi/2:2*pi), 'YTick', (0:pi/4:pi));
set(gca, 'XTicklabel', {'back', 'right', 'front', 'left', 'back'}, 'FontSize', 15);
set(gca, 'YTicklabel', {' 0 ', ' 45 ', ' 90 ', '135 ', '180 '}, 'FontSize', 15);
% avoid that the upper dot gets cut
set(gca, 'OuterPosition', [0 0 1 0.98])
shading interp;
% look from top
view(0,90);
function ita_sph_plot_new(data, samplingPoints, sampledValues, varargin)
%ITA_SPH_PLOT - plots a spherical function (and sampling points)
% function ita_sph_plot(data, varargin)
%
% the input data can be given as a spherical harmonic coefficient vector
%
% the optional parameter 'type' can be:
% 'complex' : radius is magnitude, color is phase
% 'sphere' : plots magnitude as color on unit sphere
% 'magnitude' : radius and color is magnitude
% 'spherephase' : plots phase as color on unit sphere
%
% the optional GeometryPoints and pointData give the information about
% spherical sampling points
% GeometryPoints.theta: vector of theta values
% GeometryPoints.phi: vector of phi values
% data: vector of sampling values
%
% type: default 'magnitude'
% GeometryPoints & pointData: default []
% axes: outer/inner, different 'design' (default: outer)
% fontsize: default 12, for axis annotations
% <ITA-Toolbox>
% This file is part of the application SphericalHarmonics for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Martin Pollow (mpo@akustik.rwth-aachen.de)
% Institute of Technical Acoustics, RWTH Aachen, Germany
% 03.09.2008
% Modified: 14.01.2009 - mpe - parameter-structure:
% default parameters
def.type = 'magnitude';
def.facealpha = 0.7;
def.edgealpha = 0.1;
def.samplingpoints = [];
def.sampledvalues = [];
def.geometrypoints = [];
def.axes = 'outer';
def.fontsize = 12;
def.onballoon = 'none'; % 'smaller', 'greater', 'both'
% def.angunit = 'rad'; % ToDo: Winkeldarstellung Bogenma/Grad ('deg')
% def.plottype = 'ita_sph_plot'; evtl. noch fr update-Funktion
def.caxis = [];
def.line = false;
% test if the sampling points are given
if nargin > 1 && isstruct(samplingPoints)
if ~exist('sampledValues','var')
sampledValues = samplingPoints.weights;
end
% or if they are not given, either way plot weights
if ~isnumeric(sampledValues)
varargin = {sampledValues varargin{:}};
sampledValues = samplingPoints.weights;
end
% now handle it via parser
varargin = {'samplingPoints' samplingPoints ...
'sampledValues' sampledValues varargin{:}};
clear samplingPoints sampledValues;
end