noteMatch.asv
资源名称:10_11.rar [点击查看]
上传用户:abcwxk
上传日期:2016-05-20
资源大小:434k
文件大小:1k
源码类别:
midi
开发平台:
Visual C++
- function [names_top10, costs_top10] = noteMatch(notes_steps);
- L2 = length(notes_steps);
- % 读取库
- load midLib; % 库中一首歌的midi音符序列
- count = midLib{1,1};
- midData = midLib{1,2};
- costs_top10 = [NaN NaN NaN NaN NaN...
- NaN NaN NaN NaN NaN;...
- 0 0 0 0 0 0 0 0 0 0];
- names_top10 = cell(1,10);
- % 遍历,寻找top10最低差错的序列,返回
- for n = 1:count
- % 读取第n个歌曲的相对音高序列
- notes_relative = midData{n,2};
- % 在歌曲中寻找最小距离的一段
- % 2字符串的相似矩阵 M,相同表示0,不同表示1
- % 例如:1 2 -2 4 -3 0
- L1 = length(notes_relative);
- M = zeros(L1, L2);
- for i = 1:L1
- for j=1:L2
- M(i,j) = (notes_relative(i) ~= notes_steps(j));
- end
- end
- % 寻找最相似的片段起始位置,并计算错误字符数
- sim = zeros(1,(L1 - L2 +1));
- for i = L2: L1
- sum = 0;
- for j = 1: L2
- sum = sum + M( j+i-L2, j);
- end
- sim(i - L2 + 1) = sum;
- end
- [cost,N] = min(sim);
- % 更新costs_top10
- if sum(costs_top10(1,:)==NaN) ~= 0 % 包含NaN
- tmp1 = find(costs_top10 == NaN);
- [tmp1,tmp2] = max(costs_top10(1,:)); % 找到costs中最大的一个,更新这个
- if cost < tmp1;
- costs_top10(1, tmp2) = cost;
- costs_top10(2, tmp2) = N;
- end
- end
- for i = 1:10
- names_top10(i) = midData{costs_top10(2,i),1};
- end
- costs_top10 = costs_top10(1,:);
- return;