hmmplot.m
资源名称:speech.rar [点击查看]
上传用户:ay_070428
上传日期:2014-12-04
资源大小:11427k
文件大小:3k
源码类别:
语音合成与识别
开发平台:
Matlab
- function hmmPlot(feature, state, hmmPath)
- %HMMPLOT Plot the result of HMM evaluation
- % Usage:
- % hmmPlot(feature, state, hmmPath)
- clf;
- if 1,
- featureDim = size(feature, 1);
- frameNum = size(feature, 2);
- stateNum = length(state);
- % Vertical yellow grid line
- for i = 1:frameNum,
- line([i, i], [1, stateNum], 'color', 'y');
- end
- % Horizontal yellow grid line
- for j = 1:stateNum,
- line([1, frameNum], [j, j], 'color', 'y');
- end
- % ====== Solution obtained by DTW
- for i = 1:length(hmmPath)-1,
- line([i, i+1], [hmmPath(i), hmmPath(i+1)], ...
- 'color', 'r', 'marker', '.');
- end
- xlabel('Frames');
- ylabel('States');
- box on
- axis tight
- axis image
- return
- end
- vec1 = vec1(:);
- vec2 = vec2(:);
- pos = get(gcf, 'pos');
- width = pos(3);
- height = pos(4);
- % Assume width > height
- % Assume the aspect ratio of the signal axis is b:1
- b = 4;
- k = height/(b+2.5);
- vec1Axis = subplot(2,2,4);
- plot(1:length(vec1), vec1, 1:length(vec1), vec1, 'ro');
- axis tight
- ylabel('vec1');
- set(vec1Axis, 'unit', 'pixels');
- set(vec1Axis, 'position', [width-(b+0.5)*k, height-(b+2)*k, b*k, k]);
- vec2Axis = subplot(2,2,1);
- plot(min(vec2)+max(vec2)-vec2, 1:length(vec2), min(vec2)+max(vec2)-vec2, 1:length(vec2), 'ro');
- axis tight;
- xlabel('vec2');
- set(vec2Axis, 'unit', 'pixels');
- set(vec2Axis, 'position', [width-(b+2)*k, height-(b+0.5)*k, k, b*k]);
- % The following should be done after axis is resized
- xticklabel = get(vec2Axis, 'xticklabel');
- set(vec2Axis, 'xticklabel', flipud(xticklabel));
- pathAxis = subplot(2,2,2);
- box on;
- set(pathAxis, 'unit', 'pixels');
- position = [width-(b+0.5)*k, height-(b+0.5)*k, b*k, b*k];
- set(pathAxis, 'position', position);
- % Plot the yellow grid line
- for i = 1:length(vec1),
- line([i, i], [1, length(vec2)], 'color', 'y');
- end
- for i = 1:length(vec2),
- line([1, length(vec1)], [i, i], 'color', 'y');
- end
- % ====== Solution obtained by DTW
- for i = 1:size(DTWpath,2)-1,
- line(DTWpath(1, i:i+1), DTWpath(2, i:i+1), 'color', 'r', 'marker', '.');
- end
- if ~isempty(DTWpath),
- dtwDist = sum(abs(vec1(DTWpath(1,:))-vec2(DTWpath(2,:))));
- else
- dtwDist = inf;
- end
- title(['DTW distance = ', num2str(dtwDist)]);
- axis equal
- axis tight
- if length(vec2)>length(vec1),
- % Adjust the axis of vec1
- dtwPlotWidth = position(3)*length(vec1)/length(vec2);
- oldPos = get(vec1Axis, 'pos');
- position = oldPos;
- position(1) = oldPos(1)+(oldPos(3)-dtwPlotWidth)/2;
- position(3) = dtwPlotWidth;
- set(vec1Axis, 'pos', position);
- else
- % Adjust the axis of vec2
- dtwPlotHeight = position(3)*length(vec2)/length(vec1);
- oldPos = get(vec2Axis, 'pos');
- position = oldPos;
- position(2) = oldPos(2)+(oldPos(4)-dtwPlotHeight)/2;
- position(4) = dtwPlotHeight;
- set(vec2Axis, 'pos', position);
- end
- set(findobj(gcf, 'unit', 'pixel'), 'unit', 'normalize');