clc;
clear all;
close all;
fs=54100;
y= audioread('dsp1.wav');
p= audioread('dsp2.wav');
figure(1);
plot(y);
figure(2);
plot(p);
xx = [y p];
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
figure(4);
subplot(2,2,1); plot(y); title('mixed audio - mic 1');
subplot(2,2,2); plot(p); title('mixed audio - mic 2');
subplot(2,2,3); plot(a, 'g'); title('unmixed wave 1');
subplot(2,2,4); plot(a(1,:),'r'); title('unmixed wave 2');
This code is for the cocktail party problem. I actually want to mix the two signals and extract them using ICA. Is the logic correct?? But,I am getting an error for the above code.
Out of memory. Type HELP MEMORY for your options.
Error in cov (line 97)
xy = (xc' * xc) / (m-1);
Error in mix1 (line 27)
yy = sqrtm(inv(cov(xx')))*(xx-repmat(mean(xx,2),1,size(xx,2)));

2 件のコメント

Walter Roberson
Walter Roberson 2017 年 7 月 27 日
What is the difference between this and your previous https://www.mathworks.com/matlabcentral/answers/350220-how-to-solve-the-code ? Is that previous question Answered to your satisfaction? If so you should Accept something there.
KSSV
KSSV 2017 年 7 月 27 日
Your size of xx would be very large.....so memory is not sufficient. Try taking a coarse signal.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 7 月 27 日

0 投票

You have
y= audioread('dsp1.wav');
p= audioread('dsp2.wav');
Each of those will be either N x 1 (one channel) or N x 2 (2 channels)
xx = [y p];
so xx will be N x 2 (one channel each) or N x 4 (two channels each)
yy = sqrtm(inv(cov(xx')))*(xx-repmat(mean(xx,2),1,size(xx,2)));
xx is N x 2 or N x 4 so xx' is 2 x N or 4 x N . The output of cov() is an M x M matrix where M is the number of columns in the input, so the output of cov() would try to be N x N . You simply do not have enough memory for that. You will need to work with a portion of the files at a time.

11 件のコメント

Darsana P M
Darsana P M 2017 年 7 月 27 日
So, inorder to execute all the lines at a time,what should i do? If i change the audio signal, will the error be removed??
Walter Roberson
Walter Roberson 2017 年 7 月 27 日
You would need to use shorter audio signals.
Darsana P M
Darsana P M 2017 年 7 月 29 日
Thanks a lot sir.
Darsana P M
Darsana P M 2017 年 7 月 29 日
I have one more doubt. I tried another signal.Then i could plot the graph properly.
clc;
clear all;
close all;
clf;
figure(1);
[y1,fs] = wavread('dsp4.wav');
t= linspace(0,length(y1)/fs,length(y1));
plot(t,y1);
figure(2);
[y2,fs] = wavread('dsp3.wav');
t= linspace(0,length(y2)/fs,length(y2));
plot(t,y2);
xx = [y1 y2];
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
figure(4);
subplot(2,2,1); plot(y1); title('mixed audio - mic 1');
subplot(2,2,2); plot(y2); title('mixed audio - mic 2');
subplot(2,2,3); plot(a, 'g'); title('unmixed wave 1');
subplot(2,2,4); plot(a(1,:),'r'); title('unmixed wave 2');
This is a similar code. But now the error is like this: "Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in mixaud (line 20) xx = [y1 y2]; "
The dimensions of the two audio signals must be the same.What should I do,to make their dimensions same??
Walter Roberson
Walter Roberson 2017 年 7 月 29 日
L = min(size(y1, 1),size(y2, 1));
y1 = y1(1:L,:);
y2 = y2(1:L,:);
Darsana P M
Darsana P M 2017 年 7 月 30 日
Thanks a lot for the answer.
Darsana P M
Darsana P M 2017 年 7 月 30 日
Sir,thanks a lot for the reply. Actually, i tried the same logic on two sine wave signals. I could mix them and could retrieve them back.Th code for this program is given below.
f1 = 100; % frequency of tone generator 1; unit: Hz
f2 = 250; % 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
t = [0:Ts:0.025];
% generate tones
%
y= audioread('dsp1.wav');
figure();
plot(y);
p= audioread('dsp2.wav');
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;
% figure(1);
% plot(y);
% figure(2);
% plot(p);
% Mixing matrix x= A*s
figure(3);
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,'b');
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
x = [mic1' mic2'];
[W,s,v]=svd((repmat(sum(x.*x,1),size(x,1),1).*x)*x');
figure(4)
plot(t,v(:,1),'r')
xlabel('time') % etc.
figure(5)
plot(t,v(:,2))
xlabel('time') % etc.
But when I tried this same logic on two audio signals, I am not getting the required output. The errors do not occur now, when I corrected the code as you said. But now when I run the below code, system gets hanged.
clc;
clear all;
close all;
% Ts = 41400; % 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
t1 = [0:.01:1];
%
figure(1);
[y1,fs] = wavread('dsp4.wav');
t= linspace(0,length(y1)/fs,length(y1));
plot(t,y1);
% y=reshape(y1,40000,1,[]);
figure(2);
[y2,fs] = wavread('dsp3.wav');
t= linspace(0,length(y2)/fs,length(y2));
plot(t,y2);
% x=reshape(y2,40000,1,[]);
L = min(size(y1, 1),size(y2, 1));
y3 = y1(1:L,:);
y4 = y2(1:L,:);
% dNear = (dSrc - dMic)/2;
% dFar = (dSrc + dMic)/2;
% mic1 = 1/dNear*y4 + 1/dFar*y3;
% mic2 = 1/dNear*y3+ 1/dFar*y4;
% plot(t1,mic1,'b');
% hold on;
% plot(t1,mic2,'r'); xlabel('time'); ylabel('amplitude'); axis([0 0.005 -1 1]); legend('mic 1', 'mic 2');
% hold off;
xx = [y3 y4];
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
figure(4);
plot(y3);
title('mixed audio - mic 1');
figure(5);
plot(y4);
title('mixed audio - mic 2');
What might be the problem? Is the logic wrong? Can you help me??
Walter Roberson
Walter Roberson 2017 年 7 月 30 日
You could get a "hang" if your signals were large enough that your system started using swap, but not large enough that you exceeded your defined swap. In a situation such as that, your system would spend most of its time reading and writing to disk to act as extended memory.
Darsana P M
Darsana P M 2017 年 7 月 30 日
Thanks a lot sir. So what is the other alternative.Should I change the audio signal?? Or should I use some other command?Can you suggest a way to get the output?
Walter Roberson
Walter Roberson 2017 年 7 月 30 日
You should use a shorter audio signal.
Darsana P M
Darsana P M 2017 年 7 月 30 日
thank you sir.i will try that

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by