Advertisement
r4j

PLCA

r4j
Jul 15th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.19 KB | None | 0 0
  1. function [w zf zt h] = coupled_plca(spec_f, spec_t, Bs, Bt, R, iter)
  2. % Perform coupled PLCA
  3. %
  4. % [w zf zt h] = coupled_plca(spec_f, spec_t, Bs, Bt, R, iter)
  5. %
  6. % spec_f: spectrogram with high spectral resolution
  7. % spec_t: spectrogram with high time resolution
  8. % Bs = blurring function for spectral components
  9. % Bt = blurring function for temporal components
  10. % R = number of components
  11. % iter = number of EM iterations
  12. %
  13. % Output parameters
  14. % w = spectral basis vectors (hi-res)
  15. % zf = component weights for spectral vectors
  16. % zt = component weights for temporal vectors
  17. % h = temporal vectors (hi-res too!)
  18. %
  19. % Juhan Nam
  20. %   Apr-11-2010: initial version
  21. %   Mar-11-2013: normalizing blur_h and blur_w right after blurring
  22.  
  23. % size check
  24. if size(spec_t,1) ~= size(spec_f,1)
  25.     error('coupled_plca.m: the sizes of row are equal');
  26. end
  27.  
  28. if size(spec_t,2) ~= size(spec_f,2)
  29.     error('coupled_plca.m: the sizes of column are equal');
  30. end
  31.  
  32. % initializations
  33. [m, n] = size(spec_t);
  34.  
  35. % spectral basis vectors,
  36. %w = rand(m, R)+1;
  37. ind = randperm(n);
  38. w = spec_f(:,ind(1:R))+eps;
  39. w = bsxfun(@rdivide, w, sum( w, 1));
  40.  
  41. % temporal basis vectors
  42. h = rand(R, n)+1;
  43. h = bsxfun(@rdivide, h, sum( h, 2));
  44.  
  45. zf = rand(R)+1; % weights vector for good freq res plca
  46. zf = zf / sum(zf); % normalize
  47.  
  48. zt = rand(R)+1; % weights vector for good time res plca
  49. zt = zt / sum(zt); % normalize
  50.  
  51.  
  52. Bs = Bs(:);  % vertical
  53. Bt = Bt(:)'; % horizontal
  54.  
  55. % EM iterations
  56. for it = 1:iter    
  57.     % E-step for high frequency resolution spectrogram
  58.     blur_h = conv2(h, Bt, 'same');
  59.     blur_h = bsxfun(@rdivide, blur_h, sum(blur_h,2)+eps);
  60.     zfh = diag(zf) * blur_h;
  61.     Rf = spec_f ./ (w * zfh);
  62.    
  63.     % E for high time resolution spectrogram
  64.     zth = diag(zt) * h;
  65.     blur_w = conv2(w, Bs, 'same');
  66.     blur_w = bsxfun(@rdivide, blur_w, sum(blur_w,1)+eps);
  67.     Rt = spec_t ./ (blur_w * zth);
  68.    
  69.     % M-step
  70.     nw = w .* ( Rf * zfh');
  71.     nh = zth .* (w'* Rt);
  72.     nzf = sum(nw, 1);
  73.     nzt = sum( blur_w, 1);
  74.    
  75.     % normalize
  76.     w = bsxfun(@rdivide, nw, sum(nw,1)+eps);
  77.     h = bsxfun(@rdivide, nh, sum(nh,2)+eps);
  78.     zf = nzf / sum(nzf+eps);
  79.     zt = nzt / sum(nzt+eps);    
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement