大家好,这是我们之前做的音乐识别dsp项目用到的乐谱F0提取matlab代码,先在matlab上面仿真后再迁移到CPU上面。看到有的人做dsp用到,发在这里共享。
源程序如下:
- % [x,Fs] = audioread('DJF0.wav');
- % % y=abs(hilbert(x));
- % % plot(y);title('解调信号');
- %
- % % fs=30;
- % t=0:1/Fs:13.306;
- % x6=x;
- % x66 = hilbert(x6);
- % xx = abs(x66+j*x6);
- % figure(1)
- % hold on
- % plot(t,x6);
- % plot(t,xx,'r')
- % xlim([0 5])
- % hold off
- % % 包络算法,未考虑边界条件
- % d = diff(x6);
- % n = length(d);
- % d1 = d(1:n-1);
- % d2 = d(2:n);
- % indmin = find(d1.*d2<0 & d1<0)+1;
- % indmax = find(d1.*d2<0 & d1>0)+1;
- % envmin = spline(t(indmin),x6(indmin),t);
- % envmax = spline(t(indmax),x6(indmax),t);
- % figure
- % hold on
- % plot(t,x6);
- % plot(t,envmin,'r');
- % plot(t,envmax,'m');
- % hold off
- % xlim([0 5])
- clc,clear;
- % c=readmidi('潇洒走一回MIDI.mid');
- c=readmidi('res.mid');
- b=melcontour(c,0.25,'abs'); %% 0.25拍每个点,即每0.25beat取一个点
- plot(b);%%画出旋律轮廓(melodic contour),画出F0;
- d=midi2hz(b);%把从midi格式代表的音高转换为频率,基频;
- gettempo(c);%得到文件中音乐的bpm 即每分钟多少拍;从而可以计算出每秒多少拍,即音乐频率
- %在“潇洒走一回”音乐中,得到1beat对应2Hz,
- %则在midi文件中,因为每0.25beat取1个点,则计算得到对应8Hz(合成时需要的fs)
- save mydata b;
复制代码
所有资料51hei提供下载:
tiqu.rar
(778 Bytes, 下载次数: 27)
|