Advertisement
Guest User

Untitled

a guest
Feb 11th, 2010
1,736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. function tsm_using_stftm(filename, scale)
  2.  
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. % Author: Yang Lu
  5. % Time: Nov, 2009
  6. % http://www.utdallas.edu/~yxl053100/
  7. %
  8. % The University of Texas at Dallas
  9. %
  10. % No warranty!
  11. %
  12. % Usage:
  13. % tsm_using_stftm('sp01.wav', 1.5)
  14. %
  15. %
  16. % Reference:
  17. % X. Zhu, G. T. Beauregard and L. L. Wyse, "Real-Time Signal Estimation
  18. % From Modi?ed Short-Time Fourier Transform Magnitude Spectra", IEEE Trans.
  19. % on Audio, Speech, and Language Processing, VOL. 15, NO. 5, JULY 2007
  20. %
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22.  
  23. [x Fs nBits] = wavread(filename);
  24. sent_L = length(x);
  25.  
  26. if scale>2|scale<0.5
  27. scale = 1.5;
  28. fprintf('scale has to be in [0.5 2].\n scale is reset to be 1.5.\n')
  29. end
  30.  
  31. L = 256; %frame length
  32. S = L/4; %hop size
  33. m_S = round(S/scale);
  34. overlap = L - S;
  35. Nframe = floor((sent_L-overlap)/S);
  36.  
  37. a = 0.50;
  38. b = -0.50;
  39. n = 1:L;
  40. win = sqrt(S)/sqrt((4*a^2+2*b^2)*L)*(a+b*cos(2*pi*n/L));
  41. win = win(:);
  42. Nit = 5;
  43.  
  44. L_recon = round(sent_L/scale);
  45. xfinal = zeros(L_recon,1);
  46.  
  47. U = sum(win)/(m_S);
  48.  
  49. k = 1;
  50. kk = 1;
  51. h = waitbar(0,'Please wait...');
  52. for n = 1:Nframe
  53. frm = win.*x(k:k+L-1)/U;
  54. xSTFTM = abs(fft(frm));
  55.  
  56. if kk+L-1<=L_recon
  57. res = xfinal(kk:kk+L-1);
  58. else
  59. res = [xfinal(kk:L_recon);zeros(L - (L_recon-kk+1),1)];
  60. end
  61. x_recon = iterated_recon(xSTFTM, res, Nit, win);
  62.  
  63. if (kk+L-1<=L_recon)
  64. xfinal(kk:kk+L-1) = xfinal(kk:kk+L-1) + x_recon;
  65. else
  66. xfinal(kk:L_recon) = xfinal(kk:L_recon) + x_recon(1:L_recon-kk+1);
  67. end
  68. k = k + S;
  69. kk = kk + m_S;
  70. waitbar(n/Nframe, h)
  71. end
  72.  
  73. close(h)
  74.  
  75.  
  76. outfile = [filename(1:end-4),'_recon.wav'];
  77. wavwrite(xfinal, Fs, outfile);
  78.  
  79.  
  80. function x_recon = iterated_recon(xSTFTM, x_res, Nit, win)
  81.  
  82. j = sqrt(-1);
  83. for i = 1:Nit
  84. phi = phase(fft(win.*x_res)) + randn(size(x_res))*0.01*pi;
  85. % random phase purturbation will reduce some resonance.
  86. % added by Yang Lu
  87. x = xSTFTM.*exp(j*phi); %M-constraint
  88. x_recon = ifft(x);
  89. x_res = real(x_recon);
  90. end
  91.  
  92. x_recon = x_res;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement