programing tip

칵테일 파티 알고리즘 SVD 구현… 코드 한 줄로?

itbloger 2020. 10. 20. 07:23
반응형

칵테일 파티 알고리즘 SVD 구현… 코드 한 줄로?


Coursera에서 Stanford의 Andrew Ng가 머신 러닝에 대한 입문 강의의 슬라이드에서 그는 오디오 소스가 공간적으로 분리 된 두 개의 마이크에 의해 녹음된다는 점에서 칵테일 파티 문제에 대해 다음과 같은 옥타브 솔루션을 제공합니다.

[W,s,v]=svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x');

슬라이드의 맨 아래에는 "출처 : Sam Roweis, Yair Weiss, Eero Simoncelli"가 있으며 이전 슬라이드 맨 아래에는 "이태원의 오디오 클립"이 있습니다. 비디오에서 Ng 교수는 이렇게 말합니다.

"그러므로 이런 비지도 ​​학습을보고 '이것을 구현하는 것이 얼마나 복잡합니까?'라고 질문 할 수 있습니다. 이 응용 프로그램을 빌드하려면이 오디오 처리를 수행하는 것처럼 보이며 많은 코드를 작성하거나 오디오를 처리하는 C ++ 또는 Java 라이브러리에 링크 할 수 있습니다. 이 오디오를 수행하는 복잡한 프로그램 : 오디오 분리 등. 방금들은 것을 수행하는 알고리즘이 밝혀졌습니다. 한 줄의 코드만으로 수행 할 수 있습니다 ... 바로 여기에 표시됩니다. 연구자들은 오랜 시간이 걸렸습니다. 그래서 이것이 쉬운 문제라고 말하는 것이 아닙니다.하지만 올바른 프로그래밍 환경을 사용하면 많은 학습 알고리즘이 정말 짧은 프로그램이 될 것입니다. "

비디오 강의에서 재생되는 분리 된 오디오 결과는 완벽하지는 않지만 제 생각에는 놀랍습니다. 한 줄의 코드가 어떻게 그렇게 잘 수행되는지에 대한 통찰력이있는 사람이 있습니까? 특히 한 줄의 코드와 관련하여 이태원, Sam Roweis, Yair Weiss, Eero Simoncelli의 작업을 설명하는 참고 문헌을 아는 사람이 있습니까?

최신 정보

마이크 분리 거리에 대한 알고리즘의 민감도를 보여주기 위해 다음 시뮬레이션 (옥타브)은 공간적으로 분리 된 두 톤 제너레이터에서 톤을 분리합니다.

% define model 
f1 = 1100;              % frequency of tone generator 1; unit: Hz 
f2 = 2900;              % frequency of tone generator 2; unit: Hz 
Ts = 1/(40*max(f1,f2)); % sampling period; unit: s 
dMic = 1;               % distance between microphones centered about origin; unit: m 
dSrc = 10;              % distance between tone generators centered about origin; unit: m 
c = 340.29;             % speed of sound; unit: m / s 

% generate tones
figure(1);
t = [0:Ts:0.025];
tone1 = sin(2*pi*f1*t);
tone2 = sin(2*pi*f2*t);
plot(t,tone1); 
hold on;
plot(t,tone2,'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -1 1]); legend('tone 1', 'tone 2');
hold off;

% mix tones at microphones
% assume inverse square attenuation of sound intensity (i.e., inverse linear attenuation of sound amplitude)
figure(2);
dNear = (dSrc - dMic)/2;
dFar = (dSrc + dMic)/2;
mic1 = 1/dNear*sin(2*pi*f1*(t-dNear/c)) + \
       1/dFar*sin(2*pi*f2*(t-dFar/c));
mic2 = 1/dNear*sin(2*pi*f2*(t-dNear/c)) + \
       1/dFar*sin(2*pi*f1*(t-dFar/c));
plot(t,mic1);
hold on;
plot(t,mic2,'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -1 1]); legend('mic 1', 'mic 2');
hold off;

% use svd to isolate sound sources
figure(3);
x = [mic1' mic2'];
[W,s,v]=svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x');
plot(t,v(:,1));
hold on;
maxAmp = max(v(:,1));
plot(t,v(:,2),'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -maxAmp maxAmp]); legend('isolated tone 1', 'isolated tone 2');
hold off;

랩톱 컴퓨터에서 약 10 분 동안 실행 한 후 시뮬레이션은 두 개의 분리 된 톤이 올바른 주파수를 갖는 것을 보여주는 다음 세 가지 그림을 생성합니다.

그림 1 그림 2 그림 3

그러나 마이크 분리 거리를 0 (즉, dMic = 0)으로 설정하면 시뮬레이션이 두 번째 톤을 분리 할 수 ​​없음을 나타내는 다음 세 가지 그림을 대신 생성합니다 (svd의 s 행렬에서 반환 된 단일 유효 대각선 항으로 확인 됨).

마이크 분리가없는 그림 1 마이크 분리가없는 그림 2 마이크 분리가없는 그림 3

스마트 폰의 마이크 이격 거리가 좋은 결과를 얻을 수있을만큼 충분히 커지기를 바랐지만 마이크 이격 거리를 5.25 인치 (즉, dMic = 0.1333 미터)로 설정하면 시뮬레이션에서 다음과 같은 결과가 생성됩니다. 첫 번째 격리 된 톤의 주파수 성분.

스마트 폰의 그림 1 스마트 폰의 그림 2 스마트 폰의 그림 3


나는 2 년 후 이것도 알아 내려고 노력했다. 그러나 나는 내 대답을 얻었다. 누군가를 도울 수 있기를 바랍니다.

You need 2 audio recordings. You can get audio examples from http://research.ics.aalto.fi/ica/cocktail/cocktail_en.cgi.

reference for implementation is http://www.cs.nyu.edu/~roweis/kica.html

ok, here's code -

[x1, Fs1] = audioread('mix1.wav');
[x2, Fs2] = audioread('mix2.wav');
xx = [x1, x2]';
yy = sqrtm(inv(cov(xx')))*(xx-repmat(mean(xx,2),1,size(xx,2)));
[W,s,v] = svd((repmat(sum(yy.*yy,1),size(yy,1),1).*yy)*yy');

a = W*xx; %W is unmixing matrix
subplot(2,2,1); plot(x1); title('mixed audio - mic 1');
subplot(2,2,2); plot(x2); title('mixed audio - mic 2');
subplot(2,2,3); plot(a(1,:), 'g'); title('unmixed wave 1');
subplot(2,2,4); plot(a(2,:),'r'); title('unmixed wave 2');

audiowrite('unmixed1.wav', a(1,:), Fs1);
audiowrite('unmixed2.wav', a(2,:), Fs1);

여기에 이미지 설명 입력


x(t) is the original voice from one channel/microphone.

X = repmat(sum(x.*x,1),size(x,1),1).*x)*x' is an estimation of the power spectrum of x(t). Although X' = X, the intervals between rows and columns are not the same at all. Each row represents the time of the signal, while each column is frequency. I guess this is an estimation and simplification of a more strict expression called spectrogram.

Singular Value Decomposition on spectrogram is used to factorize the signal into different components based on spectrum information. Diagonal values in s are the magnitude of different spectrum components. The rows in u and columns in v' are the orthogonal vectors that map the frequency component with the corresponding magnitude to X space.

I don't have voice data to test, but in my understanding, by means of SVD, the components fall into the similar orthogonal vectors are hopefully be clustered with the help of unsupervised learning. Say, if the first 2 diagonal magnitudes from s are clustered, then u*s_new*v' will form the one-person-voice, where s_new is the same of s except all the elements at (3:end,3:end) are eliminated.

사운드 형식 매트릭스SVD 에 대한 두 개의 기사는 참고 용입니다.

참고 URL : https://stackoverflow.com/questions/20414667/cocktail-party-algorithm-svd-implementation-in-one-line-of-code

반응형