├── CMakeLists.txt ├── README.txt ├── data └── target.wav └── src ├── Matlab ├── ADMMGLA.m ├── FGLA.m ├── GLA.m ├── STFT.m ├── iSTFT.m ├── main_phase_reconstruction.m ├── run.sh └── winDual.m ├── README.md ├── cpp ├── ADMMGLA.cpp ├── FGLA.cpp ├── GLA.cpp ├── STFT.cpp ├── iSTFT.cpp ├── main_phase_reconstruction.cpp └── winDual.cpp └── python └── admmgla.py /CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/CMakeLists.txt -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % -- Example Script for ADMMGLA ------------------------------------------- 4 | % 5 | % 6 | % Coded by Y. Masuyama, (mas-03151102@akane.waseda.jp) 7 | % Copyright 2018 Yoshiki Masuyama 8 | % 9 | % 10 | % # Reference 11 | % Y. Masuyama, K. Yatabe, and Y. Oikawa, " Griffin-Lim Like Phase Recovery 12 | % via Alternating Direction Method of Multipliers," IEEE Signal Process. 13 | % Lett., 2019. 14 | % 15 | % 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | 18 | 19 | Note: 20 | The proposed algorithm is compared with the Griffin-Lim algorithm (GLA) [1] and the fast GLA (FGLA) [2]. 21 | 22 | In the letter, we used utterances in "TIMIT Database" contained in the "PhaseLab Toolbox" [3], and the babble noise in "NOISEX-92" [4]. 23 | Due to the licence, an utterance in "CMU Arctic Databases" [5] and the Gaussian noise are used in this example script. 24 | 25 | The reconstructed signals were evaluated by PESQ [6], STOI [7], and the spectral convergence [8]. 26 | For evaluating PESQ and STOI, "pesq2" in "PhaseLab Toolbox" [3] and "taal2011" in "Auditory Modeling Toolbox" [9] were used. 27 | Please download and i those toolboxes. 28 | 29 | Note that we use our "STFT" and "iSTFT" for publishing this example script. 30 | However, for the experiment in the letter, "Large Time-Frequency Analysis Toolbox" [10] was used for STFT and iSTFT. 31 | 32 | 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | % 35 | % -- Reference ------------------------------------------------------------ 36 | % [1] D. Griffin and J. Lim, "Signal estimation from modified short-time 37 | % Fourier transform," IEEE Trans. Acoust., Speech, Signal Process., vol. 38 | % 32, no. 2, pp. 236-243, Apr. 1984. 39 | % 40 | % [2] N. Perraudin, P. Balazs, and P. L. Sondergaard, "A fast Griffin-Lim 41 | % algorithm," in IEEE Workshop Appl. Signal Process. Audio Acoust., 42 | % Oct. 2013, pp. 1-4. 43 | % 44 | % [3] P. Mowlaee, J. Kulmer, J. Stahl, and F. Mayer, Single Channel 45 | % Phase-Aware Signal Processing in Speech Communication: Theory and 46 | % Practice, Wiley, 2016. 47 | % (https://www2.spsc.tugraz.at/people/pmowlaee/PhaseLab.html) 48 | % 49 | % [4] A. Varga, H. J. M. Steeneken, M. Tomlinson, and D. Jones, "The NOISEX 50 | % -92 study on the effect of additive noise on automatic speech 51 | % recognition," Technical Report, DRA Speech Research Unit, 1992. 52 | % (http://spib.linse.ufsc.br/noise.html) 53 | % 54 | % [5] John Kominek and Alan W Black, "The CMU Arctic Speech Databases," in 55 | % Proc. 5th ISCA Speech Synthesis Workshop (SSW5), June 2004. pp. 223-224. 56 | % (http://festvox.org/cmu_arctic/) 57 | % 58 | % [6] A. W. Rix, J. G. Beerends, M. P. Hollier, and A. P. Hekstra, 59 | % "Perceptual evaluation of speech quality (PESQ) - A new method for speech 60 | % quality assessment of telephone networks and codecs," in IEEE Int. 61 | % Conf. Acoust., Speech Signal Process. (ICASSP), May 2001, vol. 19, 62 | % pp. 2125-2136. 63 | % 64 | % [7] C. H. Taal, R. C. Hendriks, R. Heusdens, and J. Jensen, "An algorithm 65 | % for intelligibility prediction of time-frequency weighted noisy speech," 66 | % IEEE Trans. Audio, Speech, Lang. Process., vol. 19, no. 7, pp. 2155-2136, 67 | % 2011. 68 | % 69 | % [8] N. Strumel and L. Daudet, "Signal reconstruction from STFT magnitude: 70 | % a state of the ar," in Int. Conf. Digit. Audio Effects (DAFx), Sept. 71 | % 2011, pp. 375-386. 72 | % 73 | % [9] P. Sondergaard, and P. Majdak, "The Auditory Modeling Toolbox," in 74 | % The Technology of Binaural Listening, (Springer, Berlin, Heidelberg), 75 | % pp. 33-56. 2013. 76 | % (http://amtoolbox.sourceforge.net/) 77 | % 78 | % [10] Z. Prusa, P. L. Sondergaard, N. Holighaus, C. Wiesmeyr, and P. 79 | % Balazs, "The Large Time-Frequency Analysis Toolbox 2.0.," in Sound, 80 | % Music, and Motion, Lecture Notes in Computer Science, pp. 419-442. 2014. 81 | % (http://ltfat.github.io/) 82 | % 83 | % 84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 85 | -------------------------------------------------------------------------------- /data/target.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/data/target.wav -------------------------------------------------------------------------------- /src/Matlab/ADMMGLA.m: -------------------------------------------------------------------------------- 1 | function sigr = ADMMGLA(X,A,Iter,rho,win,windual,skip,winLen,Ls) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % Proposed ADMMGLA 5 | % 6 | % Y. Masuyama, K. Yatabe, and Y. Oikawa, " Griffin-Lim Like Phase Recovery 7 | % via Alternating Direction Method of Multipliers," IEEE Signal Process. 8 | % Lett., 2019. 9 | % 10 | % 11 | %%% -- Input -------------------------------------------------------------- 12 | % X : initial complex-valued spectrogram (freq x time) 13 | % A : given amplitude spectrogram (freq x time) 14 | % Iter : iteration number (1 x 1) 15 | % rho : hyperparameter (1 x 1) 16 | % win : analysis window (winLen x 1) 17 | % windual: synthesis window (winLen x 1) 18 | % skip : skipping samples (1 x 1) 19 | % winLen : window length (1 x 1) 20 | % Ls: signal length (1 x 1) 21 | % 22 | % !! Attention !! 23 | % length(sig) = Ls = win + skip x N 24 | % where N in natural numbers 25 | % 26 | % 27 | %%% -- Output ------------------------------------------------------------- 28 | % sigr : reconstructed signal (Ls x 1) 29 | % 30 | % 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | 33 | Pc2 = @(X) A.*sign(X); 34 | Pc1 = @(X) STFT(iSTFT(X,windual,skip,winLen,Ls),win,skip,winLen,Ls); 35 | 36 | Z = X; 37 | U = zeros(size(X)); 38 | 39 | for m = 1:Iter 40 | 41 | X = Pc2(Z-U); 42 | Y = X+U; 43 | Z = (rho*Y+Pc1(Y))/(1+rho); 44 | U = U+X-Z; 45 | 46 | end 47 | sigr = iSTFT(X,windual,skip,winLen,Ls); 48 | end 49 | -------------------------------------------------------------------------------- /src/Matlab/FGLA.m: -------------------------------------------------------------------------------- 1 | function sigr = FGLA(X,A,Iter,alpha,win,windual,skip,winLen,LS) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % Fast Griffin-Lim Algorithm 5 | % 6 | % N. Perraudin, P. Balazs, and P. L. Sondergaard, "A fast Griffin-Lim 7 | % algorithm," in IEEE Workshop Appl. Signal Process. Audio Acoust., 8 | % Oct. 2013, pp. 1-4. 9 | % 10 | % 11 | %%% -- Input -------------------------------------------------------------- 12 | % X : initial complex-valued spectrogram (freq x time) 13 | % A : given amplitude spectrogram (freq x time) 14 | % Iter : iteration number (1 x 1) 15 | % alpha : hyperparameter (1 x 1) 16 | % win : analysis window (winLen x 1) 17 | % windual: synthesis window (winLen x 1) 18 | % skip : skipping samples (1 x 1) 19 | % winLen : window length (1 x 1) 20 | % Ls : signal length 21 | % 22 | % !! Attention !! 23 | % length(sig) = Ls = win + skip x N 24 | % where N in natural numbers 25 | % 26 | %%% -- Output ------------------------------------------------------------- 27 | % sigr : reconstructed signal (Ls x 1) 28 | % 29 | % 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | 32 | Pc2 = @(X) A.*sign(X); 33 | Pc1 = @(X) STFT(iSTFT(X,windual,skip,winLen,LS),win,skip,winLen,LS); 34 | 35 | Y = X; 36 | 37 | for m = 1:Iter 38 | 39 | Xold = X; 40 | X = Pc1(Pc2(Y)); 41 | Y = X+alpha*(X-Xold); 42 | 43 | end 44 | 45 | sigr = iSTFT(X,windual,skip,winLen,LS); 46 | end 47 | 48 | -------------------------------------------------------------------------------- /src/Matlab/GLA.m: -------------------------------------------------------------------------------- 1 | function sigr = GLA(X,A,Iter,win,windual,skip,winLen,Ls) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % Griffin-Lim Algorithm 5 | % 6 | % D. Griffin and J. Lim, "Signal estimation from modified short-time 7 | % Fourier transform," IEEE Trans. Acoust., Speech, Signal Process., vol. 8 | % 32, no. 2, pp. 236-243, Apr. 1984. 9 | % 10 | %%% -- Input -------------------------------------------------------------- 11 | % X : initial complex-valued spectrogram (freq x time) 12 | % A : given amplitude spectrogram (freq x time) 13 | % Iter : iteration number (1 x 1) 14 | % win : analysis window (winLen x 1) 15 | % windual: synthesis window (winLen x 1) 16 | % skip : skipping samples (1 x 1) 17 | % winLen : window length (1 x 1) 18 | % Ls : signal length (1 x 1) 19 | % 20 | % !! Attention !! 21 | % length(sig) = Ls = win + skip x N 22 | % where N in natural numbers 23 | % 24 | % 25 | %%% -- Output ------------------------------------------------------------- 26 | % sigr : reconstructed signal (Ls x 1) 27 | % 28 | % 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | 31 | Pc2 = @(X) A.*sign(X); 32 | Pc1 = @(X) STFT(iSTFT(X,windual,skip,winLen,Ls),win,skip,winLen,Ls); 33 | 34 | for m = 1:Iter 35 | 36 | X = Pc1(Pc2(X)); 37 | 38 | end 39 | 40 | sigr = iSTFT(X,windual,skip,winLen,Ls); 41 | end 42 | -------------------------------------------------------------------------------- /src/Matlab/STFT.m: -------------------------------------------------------------------------------- 1 | function C = STFT(sig,win,skip,winLen,Ls) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % STFT 5 | % 6 | %%% -- Input -------------------------------------------------------------- 7 | % sig : signal (samples x 1) 8 | % win : analysis window (winLen x 1) 9 | % skip : skipping samples (1 x 1) 10 | % winLen: window length (1 x 1) 11 | % Ls : signal length (1 x 1) 12 | % 13 | % !! Attention !! 14 | % length(sig) = Ls = win + skip x N 15 | % where N in natural numbers 16 | % 17 | % 18 | %%% -- Output ------------------------------------------------------------- 19 | % C : spectrograms (freq x time) 20 | % 21 | % 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | 24 | sigLC = circshift(sig,winLen/2); 25 | idx = (1:winLen)' + (0:skip:Ls-winLen); 26 | C = fft(ifftshift(sigLC(idx).*win,1)); 27 | hWL = floor(winLen/2); 28 | C = C(1:hWL+1,:).*exp(-2i*pi*(mod((0:hWL)'*(0:size(C,2)-1)*skip,winLen)/winLen)); 29 | end 30 | -------------------------------------------------------------------------------- /src/Matlab/iSTFT.m: -------------------------------------------------------------------------------- 1 | function sigr = iSTFT(C,win,skip,winLen,Ls) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % inverse STFT 5 | % 6 | %%% -- Input -------------------------------------------------------------- 7 | % C : spectrograms (freq x time) 8 | % win : synthesis window (winLen x 1) 9 | % skip : skipping samples (1 x 1) 10 | % winLen: window length (1 x 1) 11 | % Ls : signal length (1 x 1) 12 | % 13 | % !! Attention !! 14 | % length(sig) = Ls = win + skip x N 15 | % where N in natural numbers 16 | % 17 | % 18 | %%% -- Output ------------------------------------------------------------- 19 | % sigr : signal (samples x 1) 20 | % 21 | % 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 23 | 24 | hWL = floor(winLen/2); 25 | C = C.*exp(+2i*pi*(mod((0:hWL)'*(0:size(C,2)-1)*skip,winLen)/winLen)); 26 | sigr = fftshift(ifft([C;zeros(size(C)-[2,0])],'symmetric'),1).*win; 27 | idx = (1:winLen)' + (0:skip:Ls-winLen); 28 | idx2 = repmat(1:size(C,2),winLen,1); 29 | sigr = full(sum(sparse(idx(:),idx2(:),sigr(:)),2)); 30 | sigr = circshift(sigr,-winLen/2); 31 | end 32 | -------------------------------------------------------------------------------- /src/Matlab/main_phase_reconstruction.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % -- Example Script for ADMMGLA ------------------------------------------- 4 | % 5 | % 6 | % Coded by Y. Masuyama, (mas-03151102@akane.waseda.jp) 7 | % Copyright 2018 Yoshiki Masuyama 8 | % 9 | % 10 | % # Reference 11 | % Y. Masuyama, K. Yatabe, and Y. Oikawa, " Griffin-Lim Like Phase Recovery 12 | % via Alternating Direction Method of Multipliers," IEEE Signal Process. 13 | % Lett., 2019. 14 | % 15 | % 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 17 | 18 | 19 | 20 | %% -- Options ----------------------------------------------------- 21 | addpath('Functions') 22 | SNRopt = 3; % 1: SNR 0dB, 2: SNR 20dB, 3: Clean 23 | Iter = 10; % iteration number for all algorithms 24 | 25 | %% -- Hyperparameters --------------------------------------------- 26 | % If alpha = 0.0, FGLA is equal to GLA 27 | % If rho = 0.0, ADMMGLA is the proposed Alg. 1. 28 | % If rho > 0.0, ADMMGLA becomes the proposed Alg. 2, and it coincides with 29 | % GLA when rho = 1.0. 30 | 31 | alpha = 0.99; % hyperparamter for FGLA (0.00 ~ 1.00) 32 | rho = 0.00; % hyperparamter for ADMMGLA (0.00 ~ 1.00) 33 | 34 | 35 | %% -- Setup ------------------------------------------------------- 36 | % In this script, an utterance in "CMU Arctic Databases" [1] is used 37 | % instead of the utterances used in the experiments (in "TIMIT Database") 38 | % due to the license. (Please check 'README.txt'). 39 | 40 | filename = '../data/target.wav'; 41 | [target,fs] = audioread(filename); 42 | 43 | winLen = 512; % window length (1 x 1) 44 | skip = 216; % skipping samples (1 x 1) 45 | win = hann(winLen,'periodic'); % analysis window (winLen x 1) 46 | windual = winDual(win,skip); % synthesis window (winLen x 1) 47 | 48 | % !! Ls must be even number due to our STFT/iSTFT implementation !! 49 | Ls = ceil((length(target)+2*(winLen-skip)-winLen)/skip)*skip+winLen; 50 | 51 | % zero padding at both ends for adjusting the signal length 52 | target = [zeros(winLen-skip,1);target; ... 53 | zeros(Ls-length(target)-2*(winLen-skip),1);zeros(winLen-skip,1)]; 54 | 55 | 56 | %% -- Magnitude calculation --------------------------------------- 57 | % We consider two-type amplitude spectrograms for phase reconstruction: 58 | % clean amplitude spectrogram and degraded one. 59 | 60 | SNRset = {0,20,'clean'}; 61 | SNR = SNRset{SNRopt}; 62 | 63 | if strcmp(SNR,'clean') 64 | 65 | C = STFT(target,win,skip,winLen,Ls); % clean spectrogram 66 | A = abs(C); 67 | 68 | else 69 | 70 | % Degraded amplitude spectrogram is calculated by Wiener filter. 71 | % In this script, the Gaussian noise is used for degradation instead of 72 | % the babble noise due to the licence (Please check 'README.txt'). 73 | 74 | noise = randn(Ls-2*(winLen-skip),1); 75 | noise = [zeros(winLen-skip,1); noise; zeros(winLen-skip,1)]; 76 | C = STFT(target,win,skip,winLen,Ls); % clean spectrogram 77 | Cnoise = STFT(noise,win,skip,winLen,Ls); 78 | A = abs(C).^2./(abs(C).^2+abs(Cnoise).^2); % ideal Wiener filter 79 | 80 | end 81 | 82 | 83 | %% -- Phase reconstruction ---------------------------------------- 84 | % The corresponding phase is reconstructed from a given amplitude by 85 | % GLA [2], FGLA [3], and the proposed algorithm (ADMMGLA). 86 | 87 | X0 = A; % initial complex-valued spectrogram 88 | sig_gla = GLA(X0,A,Iter,win,windual,skip,winLen,Ls); 89 | sig_fgla = FGLA(X0,A,Iter,alpha,win,windual,skip,winLen,Ls); 90 | sig_admmgla = ADMMGLA(X0,A,Iter,rho,win,windual,skip,winLen,Ls); 91 | 92 | 93 | %% -- Output ------------------------------------------------------ 94 | Normalize = @(x) x/max(abs(x)); 95 | audiowrite('../results/reconstructed_gla.wav',Normalize(sig_gla),fs); 96 | audiowrite(['../results/reconstructed_fgla_', ... 97 | num2str(alpha,'%.2f'),'.wav'],Normalize(sig_fgla),fs); 98 | audiowrite(['../results/reconstructed_admmgla_', ... 99 | num2str(rho,'%.2f'),'.wav'],Normalize(sig_admmgla),fs); 100 | 101 | 102 | %% -- Evaluation -------------------------------------------------- 103 | % Here we evaluate the reconstructed signal by PESQ [4], STOI [5], and the 104 | % spectral convergence [6]. 105 | % For evaluating PESQ and STOI, "PhaseLab Toolbox" and 106 | % "Auditory Modeling Toolbox" are required (Please check 'README.txt'). 107 | % 108 | % sig_eval = sig_gla; 109 | % PESQ= pesq2(target,sig_eval,fs); 110 | % STOI = taal2011(target, sig_eval,fs); 111 | % SpCon = norm(A-abs(STFT(sig_eval,win,skip,winLen,Ls)),'fro')/ ... 112 | % norm(A,'fro'); % spectral convergence 113 | 114 | 115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 116 | % 117 | % -- Reference ------------------------------------------------------------ 118 | % [1] John Kominek and Alan W Black, "The CMU Arctic Speech Databases," in 119 | % Proc. 5th ISCA Speech Synthesis Workshop (SSW5), June 2004. pp. 223-224. 120 | % (http://festvox.org/cmu_arctic/) 121 | % 122 | % [2] D. Griffin and J. Lim, "Signal estimation from modified short-time 123 | % Fourier transform," IEEE Trans. Acoust., Speech, Signal Process., vol. 124 | % 32, no. 2, pp. 236-243, Apr. 1984. 125 | % 126 | % [3] N. Perraudin, P. Balazs, and P. L. Sondergaard, "A fast Griffin-Lim 127 | % algorithm," in IEEE Workshop Appl. Signal Process. Audio Acoust., 128 | % Oct. 2013, pp. 1-4. 129 | 130 | % [4] A. W. Rix, J. G. Beerends, M. P. Hollier, and A. P. Hekstra, 131 | % "Perceptual evaluation of speech quality (PESQ) - A new method for speech 132 | % quality assessment of telephone networks and codecs," in IEEE Int. 133 | % Conf. Acoust., Speech Signal Process. (ICASSP), May 2001, vol. 19, 134 | % pp. 2125-2136. 135 | % 136 | % [5] C. H. Taal, R. C. Hendriks, R. Heusdens, and J. Jensen, "An algorithm 137 | % for intelligibility prediction of time-frequency weighted noisy speech," 138 | % IEEE Trans. Audio, Speech, Lang. Process., vol. 19, no. 7, pp. 2155-2136, 139 | % 2011. 140 | % 141 | % [6] N. Strumel and L. Daudet, "Signal reconstruction from STFT magnitude: 142 | % a state of the ar," in Int. Conf. Digit. Audio Effects (DAFx), Sept. 143 | % 2011, pp. 375-386. 144 | % 145 | % 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 147 | -------------------------------------------------------------------------------- /src/Matlab/run.sh: -------------------------------------------------------------------------------- 1 | echo "Running main_phase_reconstruction" 2 | matlab -nodisplay -nosoftwareopengl -r \ 3 | "main_phase_reconstruction" 4 | 5 | -------------------------------------------------------------------------------- /src/Matlab/winDual.m: -------------------------------------------------------------------------------- 1 | function windual = winDual(win,skip) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % 4 | % Calculating the canonical dual window 5 | % 6 | %%% -- Input -------------------------------------------------------------- 7 | % win : analysis window (winLen x 1) 8 | % skip : skipping samples (1 x 1) 9 | % 10 | %%% -- Output ------------------------------------------------------------- 11 | % windual: synthesis window (winLen x 1) 12 | % 13 | % 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | windual = [win; zeros(skip*ceil(length(win)/skip)-length(win),1)]; 17 | windual = reshape(windual,skip,[]); 18 | windual = windual./sum(abs(windual).^2,2); 19 | windual = reshape(windual(1:length(win)),[],1); 20 | end 21 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # C++ Implementation of Griffin-Lim Like Phase Recovery via Alternating Direction Method of Multipliers 2 | 3 | by Yoshiki Masuyama et al., 2018 4 | 5 | Python/C++ implementation by Dendi Suhubdy 6 | -------------------------------------------------------------------------------- /src/cpp/ADMMGLA.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/ADMMGLA.cpp -------------------------------------------------------------------------------- /src/cpp/FGLA.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/FGLA.cpp -------------------------------------------------------------------------------- /src/cpp/GLA.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/GLA.cpp -------------------------------------------------------------------------------- /src/cpp/STFT.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/STFT.cpp -------------------------------------------------------------------------------- /src/cpp/iSTFT.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/iSTFT.cpp -------------------------------------------------------------------------------- /src/cpp/main_phase_reconstruction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/main_phase_reconstruction.cpp -------------------------------------------------------------------------------- /src/cpp/winDual.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dendisuhubdy/ADMMGLA/4a68ad66a86a2e396f70a428679b30195fb2befb/src/cpp/winDual.cpp -------------------------------------------------------------------------------- /src/python/admmgla.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Dec 4 16:53:10 2018 4 | @author: Yoshiki Masuyama 5 | 6 | This script requires following additioal functions 7 | 8 | winDual: calculate dual window 9 | STFT : calculate short-time Fourier transform 10 | iSTFT : calculate inverse short-time Fourier transform 11 | 12 | Please replace 'my_modules' to your own modules. 13 | """ 14 | ## Import 15 | import numpy as np 16 | from scipy import hanning 17 | import my_modules as mine 18 | 19 | def Pc1(X, win, windual, nfft, shift, T): 20 | x = mine.myiSTFT(X, win, nfft, shift, T) 21 | Xr = mine.mySTFT(x, windual, nfft, shift, T) 22 | return Xr 23 | 24 | def Pc2(X, A): 25 | return A*np.sign(X) 26 | 27 | 28 | ## Setup 29 | filename = 'target.wav' 30 | target, fs = mine.audioread(filename) 31 | 32 | nfft = 512 33 | shift = 216 34 | win = hanning(nfft) 35 | windual = mine.winDual(win, shift) 36 | maxiter = 10 37 | 38 | ## Adjust Signal length 39 | # Because of the difference of the STFT/iSTFT imprementation, the adjusting 40 | # rule is different from the code in the code ocean (in MATLAB). 41 | T = int(np.floor((len(target) - nfft)/float(shift))) 42 | target = target[0:(T-1)*shift+nfft] 43 | target[0:shift] = 0.0 44 | target[-shift:-1] = 0.0 45 | 46 | ## Consider only the clean case 47 | C = mine.mySTFT(target, win, nfft, shift, T) 48 | A = np.abs(C).astype(np.complex128) 49 | Z = A 50 | 51 | ## GLA 52 | for i in range(maxiter): 53 | X = Pc2(Z, A) 54 | Z = Pc1(X, win, windual, nfft, shift, T) 55 | 56 | sig_gla = mine.myiSTFT(X, windual, nfft, shift, T) 57 | 58 | ## ADMMGLA 59 | Z = A 60 | U = np.zeros(Z.shape,Z.dtype) 61 | for i in range(maxiter): 62 | X = Pc2(Z-U, A) 63 | Z = Pc1(X+U, win, windual, nfft, shift, T) 64 | U = U + X - Z 65 | 66 | sig_admmgla = mine.myiSTFT(X, windual, nfft, shift, T) 67 | 68 | ## Output 69 | #mine.audiowrite('gla.wav', mine.normalize(sig_gla), fs) 70 | #mine.audiowrite('admmgla.wav', mine.normalize(sig_admmgla), fs) 71 | 72 | --------------------------------------------------------------------------------