annotate matlab/MATLAB-Chroma-Toolbox_2.0/visualizePitch.m @ 60:1ea2aed23d4a tip

Fix version
author Chris Cannam
date Thu, 13 Feb 2020 13:37:36 +0000
parents b54ee0a0be67
children
rev   line source
Chris@0 1 function visualizePitch(f_pitch,parameter)
Chris@0 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chris@0 3 % Name: visualizePitch
Chris@0 4 % Date of Revision: 2011-03
Chris@0 5 % Programmer: Meinard Mueller, Sebastian Ewert
Chris@0 6 %
Chris@0 7 % Description:
Chris@0 8 % Visualization of f_pitch
Chris@0 9 %
Chris@0 10 % Input:
Chris@0 11 % f_pitch
Chris@0 12 % parameter.midiMin = 21;
Chris@0 13 % parameter.midiMax = 108;
Chris@0 14 % parameter.featureRate = 0;
Chris@0 15 % parameter.colorbar = 1;
Chris@0 16 % parameter.colormap = hot2;
Chris@0 17 % parameter.print = 0;
Chris@0 18 % parameter.printFile = 'figure.eps';
Chris@0 19 % parameter.printDir = '';
Chris@0 20 % parameter.title = '';
Chris@0 21 % parameter.xlabel = '';
Chris@0 22 % parameter.ylabel = '';
Chris@0 23 % parameter.imagerange = 0; %[0 1]; % 0 means automatic
Chris@0 24 % parameter.usePitchNameLabels = 0;
Chris@0 25 % parameter.PitchNameLabels = ...
Chris@0 26 % parameter.Ytick = [1 10 20 30 40 50 60 70 80 90 100 110 120]; % not used when usePitchNameLabels==1
Chris@0 27 % parameter.printPaperPosition = [1 10 26 15]; %[left, bottom, width, height]
Chris@0 28 % parameter.fontSize = 0; % 0 means automatic
Chris@0 29 % parameter.createAxisLabel = 1;
Chris@0 30 %
Chris@0 31 % License:
Chris@0 32 % This file is part of 'Chroma Toolbox'.
Chris@0 33 %
Chris@0 34 % 'Chroma Toolbox' is free software: you can redistribute it and/or modify
Chris@0 35 % it under the terms of the GNU General Public License as published by
Chris@0 36 % the Free Software Foundation, either version 2 of the License, or
Chris@0 37 % (at your option) any later version.
Chris@0 38 %
Chris@0 39 % 'Chroma Toolbox' is distributed in the hope that it will be useful,
Chris@0 40 % but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 42 % GNU General Public License for more details.
Chris@0 43 %
Chris@0 44 % You should have received a copy of the GNU General Public License
Chris@0 45 % along with 'Chroma Toolbox'. If not, see <http://www.gnu.org/licenses/>.
Chris@0 46 %
Chris@0 47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chris@0 48
Chris@0 49 if nargin<2
Chris@0 50 parameter=[];
Chris@0 51 end
Chris@0 52
Chris@0 53 if isfield(parameter,'midiMin')==0
Chris@0 54 parameter.midiMin = 21;
Chris@0 55 end
Chris@0 56 if isfield(parameter,'midiMax')==0
Chris@0 57 parameter.midiMax = 108;
Chris@0 58 end
Chris@0 59 if isfield(parameter,'featureRate')==0
Chris@0 60 parameter.featureRate = 0;
Chris@0 61 end
Chris@0 62 if isfield(parameter,'colorbar')==0
Chris@0 63 parameter.colorbar = 1;
Chris@0 64 end
Chris@0 65 if (isfield(parameter,'colormap')==0) || (isstr(parameter.colormap) && strcmpi(parameter.colormap,'hot2'))
Chris@0 66 hot2 = hot(64);
Chris@0 67 hot2 = [hot2; hot2(32:64,:); hot2(32:64,:)];
Chris@0 68 hot2 = sort(hot2);
Chris@0 69 parameter.colormap = hot2;
Chris@0 70 end
Chris@0 71 if isfield(parameter,'print')==0
Chris@0 72 parameter.print = 0;
Chris@0 73 end
Chris@0 74 if isfield(parameter,'printFile')==0
Chris@0 75 parameter.printFile = 'figure.eps';
Chris@0 76 end
Chris@0 77 if isfield(parameter,'printDir')==0
Chris@0 78 parameter.printDir = '';
Chris@0 79 end
Chris@0 80 if isfield(parameter,'title')==0
Chris@0 81 parameter.title = '';
Chris@0 82 end
Chris@0 83 if isfield(parameter,'xlabel')==0
Chris@0 84 parameter.xlabel = '';
Chris@0 85 end
Chris@0 86 if isfield(parameter,'ylabel')==0
Chris@0 87 parameter.ylabel = '';
Chris@0 88 end
Chris@0 89 if isfield(parameter,'imagerange')==0
Chris@0 90 parameter.imagerange = 0; %[0 1];
Chris@0 91 end
Chris@0 92 if isfield(parameter,'usePitchNameLabels')==0
Chris@0 93 parameter.usePitchNameLabels = 0;
Chris@0 94 end
Chris@0 95 if isfield(parameter,'PitchNameLabels')==0
Chris@0 96 parameter.PitchNameLabels = ...
Chris@0 97 [' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 98 'C0 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 99 'C1 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 100 'C2 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 101 'C3 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 102 'C4 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 103 'C5 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 104 'C6 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 105 'C7 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 106 'C8 ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';' ';...
Chris@0 107 'C9 '];
Chris@0 108 end
Chris@0 109 if isfield(parameter,'Ytick')==0
Chris@0 110 parameter.Ytick = [1 10 20 30 40 50 60 70 80 90 100 110 120]; % not used when usePitchNameLabels==1
Chris@0 111 end
Chris@0 112 if isfield(parameter,'printPaperPosition')==0
Chris@0 113 parameter.printPaperPosition = [1 10 26 15]; %[left, bottom, width, height]
Chris@0 114 end
Chris@0 115 if isfield(parameter,'fontSize')==0
Chris@0 116 % 0 means automatic
Chris@0 117 parameter.fontSize = 0;
Chris@0 118 end
Chris@0 119 if isfield(parameter,'createAxisLabel')==0
Chris@0 120 parameter.createAxisLabel = 1;
Chris@0 121 end
Chris@0 122
Chris@0 123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chris@0 124 % Visualization
Chris@0 125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chris@0 126 figure;
Chris@0 127
Chris@0 128 if parameter.featureRate == 0
Chris@0 129 t_axis = (1:size(f_pitch,2));
Chris@0 130 else
Chris@0 131 t_axis = (0:size(f_pitch,2)-1)/parameter.featureRate;
Chris@0 132 end
Chris@0 133
Chris@0 134 p_axis = (parameter.midiMin:parameter.midiMax);
Chris@0 135 f_image = f_pitch(p_axis,:);
Chris@0 136
Chris@0 137 if parameter.imagerange == 0
Chris@0 138 imagesc(t_axis,p_axis,f_image);
Chris@0 139 else
Chris@0 140 imagesc(t_axis,p_axis,f_image,parameter.imagerange);
Chris@0 141 end
Chris@0 142
Chris@0 143 set(gca,'YTick',parameter.Ytick);
Chris@0 144 set(gca,'YDir','normal');
Chris@0 145
Chris@0 146 if parameter.usePitchNameLabels
Chris@0 147 set(gca,'YTick',[parameter.midiMin:parameter.midiMax]);
Chris@0 148 set(gca,'YTickLabel',parameter.PitchNameLabels(parameter.midiMin:parameter.midiMax,:));
Chris@0 149 end
Chris@0 150
Chris@0 151 title(parameter.title);
Chris@0 152 xlabel(parameter.xlabel);
Chris@0 153 ylabel(parameter.ylabel);
Chris@0 154
Chris@0 155 if ~parameter.createAxisLabel
Chris@0 156 set(gca, 'XTick', [], 'YTick', [])
Chris@0 157 end
Chris@0 158
Chris@0 159 colormap(parameter.colormap);
Chris@0 160
Chris@0 161 if parameter.fontSize
Chris@0 162 set(gca,'FontSize',parameter.fontSize)
Chris@0 163 end
Chris@0 164
Chris@0 165 if parameter.colorbar == 1
Chris@0 166 hColorbar = colorbar;
Chris@0 167 if parameter.fontSize
Chris@0 168 set(hColorbar,'FontSize',parameter.fontSize)
Chris@0 169 end
Chris@0 170 end
Chris@0 171
Chris@0 172 drawnow;
Chris@0 173
Chris@0 174 if parameter.print == 1
Chris@0 175 set(gcf,'PaperPosition',parameter.printPaperPosition);
Chris@0 176 print('-depsc2',strcat(parameter.printDir,parameter.printFile));
Chris@0 177 end
Chris@0 178
Chris@0 179 end
Chris@0 180
Chris@0 181