clear all;
close all;
clc;

addpath('C:\Users\TT\Desktop\academics\FinalCode_UBSS\signals');

simcomale = load('simcomale.mat');
simcofemale = load('simcofemale.mat');
dctdic = load('DCTdic.mat');
fftdic = load('FFTdic.mat');

mm=wavread('dev2_female4_inst_mix.wav');

m1=mm(:,1);m2=mm(:,2);
mm1=buffer(m1,512,0,'nodelay');
mm2=buffer(m2,512,0,'nodelay'); 
TSM1=mm1;  
TSM2=mm2;

siglength = 160000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1 = m1;
x2 = m2;
x1=abs(x1);
x2=abs(x2);
figure;
subplot(20,1,[1 2]),plot(m1(1:100:siglength));xlabel('Sample indices'),ylabel('x_1');title('Speech mixtures');
subplot(20,1,[5 6]),plot(m2(1:100:siglength));xlabel('Sample indices'),ylabel('x_2');
subplot(20,1,[9 10 11 12 13 14 15 16 17 18 19 20]),plot(x1,x2,'.');axis([0 0.1 0 0.1], 'square'); xlabel('x_1'),ylabel('x_2');
gtext({'Scatter plot'});

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
simcomale.C1=simcomale.DTr'*TSM1;
simcomale.C2=simcomale.DTr'*TSM2;
x1 = reshape(simcomale.C1,160256,1);
x2 = reshape(simcomale.C2,160256,1);
xa1=abs(x1);
xa2=abs(x2);
figure;
%xlabel('x_1'),ylabel('x_2');
subplot(20,1,[1 2]),plot(x1(1:100:siglength));xlabel('Sample indices'),ylabel('m_1');title('Transformed male mixtures');
subplot(20,1,[5 6]),plot(x2(1:100:siglength));xlabel('Sample indices'),ylabel('m_2');
subplot(20,1,[9 10 11 12 13 14 15 16 17 18 19 20]),plot(xa1,xa2,'.');axis([0 0.5 0 0.5], 'square');xlabel('m_1'),ylabel('m_2');
gtext({'Scatter plot'});

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
simcofemale.C1=simcofemale.DTr'*TSM1;
simcofemale.C2=simcofemale.DTr'*TSM2;
x1 = reshape(simcofemale.C1,160256,1);
x2 = reshape(simcofemale.C2,160256,1);
xa1=abs(x1);
xa2=abs(x2);
figure;
%xlabel('x_1'),ylabel('x_2');
subplot(20,1,[1 2]),plot(x1(1:100:siglength));xlabel('Sample indices'),ylabel('m_1');title('Transformed female mixtures');
subplot(20,1,[5 6]),plot(x2(1:100:siglength));xlabel('Sample indices'),ylabel('m_2');
subplot(20,1,[9 10 11 12 13 14 15 16 17 18 19 20]),plot(xa1,xa2,'.');axis([0 0.5 0 0.5], 'square');xlabel('m_1'),ylabel('m_2');
gtext({'Scatter plot'});

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dctdic.C1=dctdic.DTr'*TSM1;
dctdic.C2=dctdic.DTr'*TSM2;
x1 = reshape(dctdic.C1,160256,1);
x2 = reshape(dctdic.C2,160256,1);
xa1=abs(x1);
xa2=abs(x2);
figure;
%xlabel('x_1'),ylabel('x_2');
subplot(20,1,[1 2]),plot(x1(1:100:siglength));xlabel('Sample indices'),ylabel('m_1');title('DCT of mixtures');
subplot(20,1,[5 6]),plot(x2(1:100:siglength));xlabel('Sample indices'),ylabel('m_2');
subplot(20,1,[9 10 11 12 13 14 15 16 17 18 19 20]),plot(xa1,xa2,'.');axis([0 0.5 0 0.5], 'square');xlabel('m_1'),ylabel('m_2');
gtext({'Scatter plot'});

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fftdic.C1=real(fftdic.DTr)'*TSM1;
fftdic.C2=real(fftdic.DTr)'*TSM2;
x1 = reshape(fftdic.C1,160256,1);
x2 = reshape(fftdic.C2,160256,1);
xa1=abs(x1);
xa2=abs(x2);
figure;
%xlabel('x_1'),ylabel('x_2');
subplot(20,1,[1 2]),plot(x1(1:100:siglength));xlabel('Sample indices'),ylabel('m_1');title('STFT of mixtures');
subplot(20,1,[5 6]),plot(x2(1:100:siglength));xlabel('Sample indices'),ylabel('m_2');
subplot(20,1,[9 10 11 12 13 14 15 16 17 18 19 20]),plot(xa1,xa2,'.');axis([0 0.5 0 0.5], 'square');xlabel('m_1'),ylabel('m_2');
gtext({'Scatter plot'});
