ita_tpa_plot_matrix.m 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
function ita_tpa_plot_matrix(data_raw,varargin)
% This function show a video of 3D matrices over frequency,
% like a Tomography you can pass trought the matrix.
%
% call: ita_tpa_plot_matrix(audioMatrix)
% call: ita_tpa_plot_matrix(audioMatrixCellArray)
%

% <ITA-Toolbox>
% This file is part of the application TPA-TPS for the ITA-Toolbox. All rights reserved. 
% You can find the license for this m-file in the application folder. 
% </ITA-Toolbox>


% Author: Lian Gomes, Pascal Dietrich pdi@akustik.rwth-aachen.de

sArgs   = struct('freqVector',[],'filename','','colorbar',false,'ticksF','','ticksV','',...
    'bands','false','waitTime',0.1);
[sArgs] = ita_parse_arguments(sArgs,varargin(:));

printFiles = ~ isempty(sArgs.filename);
if isempty(sArgs.ticksV)
    sArgs.ticksV = {'UX','UY','UZ','RX','RY','RZ'};
end
if isempty(sArgs.ticksF)
    sArgs.ticksF = {'FX','FY','FZ','MX','MY','MZ'};
end

if sArgs.bands
    for idx = 1:numel(data_raw)
        comment{idx} = data_raw{idx}(1,1).comment;
    end
    data_raw = ita_matrixfun(@ita_spk2frequencybands, data_raw);
    sArgs.waitTime = sArgs.waitTime * 10;
    for idx = 1:numel(data_raw)
         data_raw{idx}(1,1).comment = comment{idx};
    end
end

%% get data matrices
if ~iscell(data_raw)
    data{1} = data_raw;
else
    data = data_raw;
end

%% printing?
if nargin == 1
    printFiles = false;
end

%% freq Vector
if isempty(sArgs.freqVector)
    sArgs.freqVector = data{1}(1,1).freqVector;
end
fIdx = data{1}(1,1).freq2index(sArgs.freqVector);

%% get data out of matrix
for matIdx = 1:numel(data)
    if size(data{matIdx},3)==1
        for idx = 1:size(data{matIdx},1)
            for jdx = 1:size(data{matIdx},2)
                A{matIdx}(idx,jdx,:) = data{matIdx}(idx,jdx).freqData;
            end
        end
        Alog{matIdx} = 20*log10(abs(A{matIdx})); %#ok<*AGROW>
        detect_maxA(matIdx) = max(max(max(Alog{matIdx})));
    end
end

detect_max  = max( detect_maxA );
limits = [-70 detect_max];

%% colorbar
nSubplots = numel(data) + sArgs.colorbar;
ita_plottools_figure();
ita_plottools_aspectratio(.4);

for matIdx = 1:numel(data)
    subplot(1,nSubplots,matIdx);
end
h = subplot(1,nSubplots,nSubplots);
axis off
% limits
set(h,'Clim',limits)

if sArgs.colorbar
    colorbar;
else
    colorbar('off');
end

DOF1 = size(data{1},1);
DOF2 = size(data{1},2);
pause(0.1)


%% find ticks
multiplierF = ceil(size(data{matIdx},1)/(numel(sArgs.ticksF)));
multiplierV = ceil(size(data{matIdx},2)/(numel(sArgs.ticksV)));
F_ticks = sArgs.ticksF;
F_ticks = repmat(F_ticks,1,multiplierF);
v_ticks = sArgs.ticksV;
v_ticks = repmat(v_ticks,1,multiplierV);

%% go thru all frequencies
for idx= 1: numel(fIdx)
    pause(sArgs.waitTime) %wait for figure to appear
    
    for matIdx = 1:numel(data)
        h = subplot(1,nSubplots,matIdx);
        set(h,'FontSize' ,13)
        imagesc(Alog{matIdx}(:,:,fIdx(idx)))
        shading flat
        set(gca,'PlotBoxAspectRatio',[1 1 1])

        title([ data_raw{matIdx}(1,1).comment ' - ' num2str(sArgs.freqVector(idx)) ' Hz'],'FontSize',30)
        set(h,'Xtick',1:DOF1) ;
        set(h,'Ytick',1:DOF2) ;
        set(h,'FontSize' ,16)
        
        set(h,'XtickLabel',F_ticks,'FontSize',20)
        set(h,'YtickLabel',v_ticks,'FontSize',20)
        set(h,'Clim',limits)
        ita_plottools_colormap('artemis');
        
    end
    
    if printFiles
        filename = [sArgs.filename ita_angle2str(idx,5) '.png'];
        print('-dpng','-r300',filename)
    end
end

end