声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2967|回复: 4

[综合讨论] 采用bic准则的音频流分割程序

[复制链接]
发表于 2006-10-20 10:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
采用bic准则的音频流分割程序,能够准确找出不同音频种类的分界点位置,如音乐和语音。

给程序有两个函数组成,详细如下:

audioSeg.m
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. function [y,fs,position] = audioSeg(filenm,clipLen)
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. %
  5. %This is main audio stream segment function,it can classfication the audio file to different segments.
  6. %
  7. %input:
  8. %     filenm = the flie which need to be classification;
  9. %     clipLen = segment clip length,unit is frame,default value is 100;
  10. %output:
  11. %     y = the points vector of the file;
  12. %     fs = sample rate;
  13. %     position = type change points;
  14. %
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. %% Written by Qian Yong Gao                   %%
  17. %% Data:June 23,2006                          %%
  18. %% Update:June 23,2006 by Qian Yong Gao       %%
  19. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  20. if nargin < 2
  21.     clipLen = 100;
  22. end
  23.          
  24. [fid,msg] = fopen(filenm,'rb');%open file
  25. error(msg);
  26. fseek(fid,8,-1);%file point rewind
  27. header = fread(fid,4,'uchar');

  28. % makesure '*wav' file format
  29. if header' ~= 'WAVE'
  30.     error('This file is not a wavfile');
  31. else
  32.     fseek(fid,8,0);
  33.     iPCM = fread(fid,1,'ushort');%PCM code format
  34.     iMono = fread(fid,1,'ushort');%Mono channel
  35.     if (iPCM ~= 1) & (iMono ~= 1)
  36.         error('This wavefile is not Mono PCM type');
  37.     end
  38. end
  39. fs = fread(fid,1,'ushort');%sample rate
  40. fseek(fid,8,0);
  41. nBit = fread(fid,1,'ushort');%each sample bits
  42. nByte = nBit/8;%each sample bytes;
  43. header = fread(fid,4,'uchar');
  44. if header' ~= 'data'
  45.     error('The file is corrupt');
  46. end   
  47. if nByte == 1
  48.     nData = fread(fid,1,'ulong'); %file samples number
  49.     rid = 'uchar';
  50. else
  51.     nData = fread(fid,1,'ulong') / 2;
  52.     rid = 'short';
  53. end   

  54. position = 0;%beginning position is '0'
  55. nRead = 0; %n samples read
  56. nFrame = 0; %n frame read
  57. segLen = 0; %n clip read
  58. y = [];%signal read
  59. frameLen = floor(0.02 * fs); %frame length
  60. frameMov = ceil(0.01 * fs); %frame step
  61. overlap = frameLen - frameMov;%frame overlap

  62. while nRead <= nData - frameLen
  63.     y1 = fread(fid,frameLen,rid);%read a frame
  64.     nRead = nRead + frameMov;%read samples number increase frameMov
  65.     if fid == 'uchar'
  66.         y1 = (y1 - 128) / 128 ;
  67.         fseek(fid,-overlap,0);%8 bit,rewind file pointer overlap bites
  68.     else
  69.         y1 = y1 / 32768;
  70.         fseek(fid,-2 * overlap,0);%16 bit,rewind file pointer 2*overlap bites
  71.     end   
  72.     nFrame = nFrame + 1;%increase read frame number
  73.     y = [y;y1'];%read signal     
  74.     %when read frame is clipLen's integer times,nClip increase 1
  75.     segLen = segLen + 1;
  76.     if segLen == 3*clipLen
  77.         clipMat = y([nFrame-3*clipLen+1:nFrame],:);%clip matrix which wait for classifcation
  78.         f = fft(clipMat'.*(hamming(frameLen)*ones(1,3*clipLen)),1024);
  79.         f = abs(f);
  80.         mfc = melfc(f,30,30);
  81.         segN = BeyasInfoCrit(mfc,frameLen,frameMov,0.6);
  82.         if (segN>=clipLen) & (segN<=2*clipLen)
  83.             position = [position;nFrame-3*clipLen+segN];
  84.             segLen = 3 * clipLen - segN;
  85.         else
  86.             segLen = 2 * clipLen;
  87.         end
  88.     end
  89. end   
  90. fclose(fid);
  91. position(2:end) = ((position(2:end)-1)*frameMov+frameLen) / fs;
  92. y = y';
  93. y1 = y(:,end);
  94. y(:,end) = [];
  95. y(frameMov+1:end,:) = [];
  96. y = y(:);
  97. y = [y;y1];
  98. t = [1:length(y)] / fs;
  99. plot(t,y,'k');
  100. hold on
  101. for l = 1:length(position)
  102.     line([position(l) position(l)], [min(y) max(y)], 'Color', 'r');
  103. end   
  104. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
复制代码

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-10-20 10:22 | 显示全部楼层
BeyasInfoCrit.m

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. function segN = BeyasInfoCrit(c,framelen,framemov,labeta)
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. %
  5. % This function use BIC to find the change point of c
  6. %input:
  7. %     c = frame feature matrix;
  8. %     framelen = frame length
  9. %     framemov = frame move
  10. %output:
  11. %     segN = segment change point
  12. %
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. %% Written by Qian Yong Gao                   %%
  15. %% Data:October 25,2005                       %%
  16. %% Update:May 30,2006 by Qian Yong Gao        %%
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. if nargin < 4
  19.     labeta = 0.8;
  20. end   
  21. [N,fd] = size(c);
  22. u0 = mean(c);
  23. sigma0 = sum((c-u0(ones(1,N),:)).^2)/N;
  24. det0 = max(prod(max(sigma0,eps)),realmin);%行列式的值
  25. detBIC = zeros(1,N-1);
  26. for m = 1:N-1  %计算假定断点在m(1~N-1)处的BIC值
  27.     %计算前一部分的参数
  28.     c1 = c(1:m,:);
  29.     u1 = mean(c1);
  30.     sigma1 = sum((c1-u1(ones(1,m),:)).^2)/m;;
  31.     %以对角线乘积代替行列式的值,避免数据不够带来的估计不正确
  32.     det1 = max(prod(max(sigma1,eps)),realmin);
  33.    
  34.     c2 = c(m+1:N,:);
  35.     u2 = mean(c2);
  36.     sigma2 = sum((c2-u2(ones(1,N-m),:)).^2)/(N-m);
  37.     det2 = max(prod(max(sigma2,eps)),realmin);
  38.     %计算两种假设带来的差值
  39.     detBIC(m) = 0.5*(N*log(det0)-m*log(det1)-(N-m)*log(det2))...
  40.         - labeta*0.25*fd*(fd+3)*log(N);
  41. end
  42. [DB,index] = max(detBIC);
  43. if DB > 0
  44.     %segN = framemov*(index-1) + framelen;
  45.     segN = index;
  46. else
  47.     segN = N;%framemov*(N-1) + framelen;
  48. end
复制代码
发表于 2008-4-20 18:24 | 显示全部楼层
请问mfc = melfc(f,30,30);中的melfc是什么函数,如有源程序能否发给我890516k@163.com
发表于 2009-3-17 22:03 | 显示全部楼层

求melfc函数代码

我也想要一份melfc 函数的代码,能否发给我:jingxinshulin@163.com
谢谢!
发表于 2011-5-11 23:18 | 显示全部楼层
我也想要一份melfc 函数的代码,能否发给我:z.heng@foxmail.com,谢谢了
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 13:28 , Processed in 0.054963 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表