标题: 从乐谱中提取基音频率matlab代码 [打印本页]

作者: mingyang1996    时间: 2017-12-12 21:54
标题: 从乐谱中提取基音频率matlab代码
大家好,这是我们之前做的音乐识别dsp项目用到的乐谱F0提取matlab代码,先在matlab上面仿真后再迁移到CPU上面。看到有的人做dsp用到,发在这里共享。

源程序如下:

  1. % [x,Fs] = audioread('DJF0.wav');
  2. % % y=abs(hilbert(x));
  3. % % plot(y);title('解调信号');
  4. %
  5. % % fs=30;
  6. % t=0:1/Fs:13.306;
  7. % x6=x;
  8. % x66 = hilbert(x6);
  9. % xx = abs(x66+j*x6);
  10. % figure(1)
  11. % hold on
  12. % plot(t,x6);
  13. % plot(t,xx,'r')
  14. % xlim([0 5])
  15. % hold off
  16. % % 包络算法,未考虑边界条件
  17. % d = diff(x6);
  18. % n = length(d);
  19. % d1 = d(1:n-1);
  20. % d2 = d(2:n);
  21. % indmin = find(d1.*d2<0 & d1<0)+1;
  22. % indmax = find(d1.*d2<0 & d1>0)+1;
  23. % envmin = spline(t(indmin),x6(indmin),t);
  24. % envmax = spline(t(indmax),x6(indmax),t);
  25. % figure
  26. % hold on
  27. % plot(t,x6);
  28. % plot(t,envmin,'r');
  29. % plot(t,envmax,'m');
  30. % hold off
  31. % xlim([0 5])
  32. clc,clear;
  33. % c=readmidi('潇洒走一回MIDI.mid');
  34. c=readmidi('res.mid');
  35. b=melcontour(c,0.25,'abs'); %% 0.25拍每个点,即每0.25beat取一个点
  36. plot(b);%%画出旋律轮廓(melodic contour),画出F0;
  37. d=midi2hz(b);%把从midi格式代表的音高转换为频率,基频;
  38. gettempo(c);%得到文件中音乐的bpm 即每分钟多少拍;从而可以计算出每秒多少拍,即音乐频率
  39. %在“潇洒走一回”音乐中,得到1beat对应2Hz,
  40. %则在midi文件中,因为每0.25beat取1个点,则计算得到对应8Hz(合成时需要的fs)

  41. save mydata b;


复制代码

所有资料51hei提供下载:
tiqu.rar (778 Bytes, 下载次数: 27)







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1