dtwplot.m
资源名称:speech.rar [点击查看]
上传用户:ay_070428
上传日期:2014-12-04
资源大小:11427k
文件大小:3k
源码类别:
语音合成与识别
开发平台:
Matlab
- function dtwplot(vec1, vec2, DTWpath)
- %DTWPLOT Plot the result of DTW of two pitch vectors
- % Usage:
- % dtwplot(vec1, vec2, DTWpath)
- clf;
- if size(vec1,1)>1 & size(vec2,1)>1, % Inputs are matrices, for ASR
- frame1num = size(vec1, 2);
- frame2num = size(vec2, 2);
- % Vertical yellow grid line
- for i = 1:frame1num,
- line([i, i], [1, frame2num], 'color', 'y');
- end
- % Horizontal yellow grid line
- for j = 1:frame2num,
- line([1, frame1num], [j, j], 'color', 'y');
- end
- % ====== Solution obtained by DTW
- for i = 1:size(DTWpath,2)-1,
- line([DTWpath(1,i), DTWpath(1,i+1)], [DTWpath(2,i), DTWpath(2,i+1)], ...
- 'color', 'r', 'marker', '.');
- end
- xlabel('Test vector');
- ylabel('Reference vector');
- if ~isempty(DTWpath),
- temp = vec1(:,DTWpath(1,:))-vec2(:,DTWpath(2,:));
- dtwDist = sum(sqrt(sum(temp.^2)));
- else
- dtwDist = inf;
- end
- title(['DTW distance = ', num2str(dtwDist)]);
- 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');