function [x,X,F,T]=genera_mezcla(s,fs,d,theta,w,NFFT,noverlap,metodo);
% Funcion que hace una mezcla de señales a partir de la distancia entre
% micros (d), el angulo de llegada de las señales (theta) y los parametros
% para calcular el espectrograma (w es la ventana y NFFT el numero de puntos
% de la FFT). fs es la frecuencia de muestreo.

c=344;  % Velocidad de propagacion del sonido

n=length(s(:,1));
theta=theta*pi/180; % Angulos en radianes

[S(:,:,1),F,T]=specgram(s(1,:),NFFT,fs,w,noverlap);
for k=2:n
    S(:,:,k)=specgram(s(k,:),NFFT,fs,w,noverlap);
end

% Masking
if metodo=='m'
    a=ones(1,n)-theta/(2*pi);
    tau=d(1)*sin(theta)/c;
    x1=zeros(1,length(s(1,:)));
    for k=1:n
        x1=x1+s(k,:);
    end
    X(:,:,1)=specgram(x1,NFFT,fs,w,noverlap);
    X(:,:,2)=mezcla(S,a,tau,F);
end

% Anemuller
if metodo=='a'
    if theta(1,1)<0
        theta=-theta;
    end
    tau=zeros(2);
    tau(1,2)=d(1)*sin(theta(1,1))/c;
    tau(2,1)=d(1)*sin(-theta(1,2))/c;
    a=1./(ones(n)+tau*1e3);
    X=mezcla_con_retardo_2(S,F,a,tau);
end

% Subbandas
if metodo=='s'
    if theta(1,1)<0
        theta=-theta;
    end
    tau=zeros(n);
    if n==2
        tau(1,2)=-d*sin(theta(1,1))/c;
        tau(2,1)=d*sin(theta(1,2))/c;
        a(1,2)=1-theta(1,1)/(2*pi);
        a(2,1)=1-theta(1,2)/(2*pi);
    else
        tau(1,2)=-d(1,1)*sin(theta(1,2))/c;
        tau(1,3)=-(d(1,1)+d(1,2))*sin(theta(1,2))/c;
        tau(2,1)=d(1,1)*sin(theta(1,1))/c;
        tau(2,3)=-d(1,2)*sin(theta(1,3))/c;
        tau(3,1)=(d(1,1)+d(1,2))*sin(theta(1,1))/c;
        tau(3,2)=d(1,2)*sin(theta(1,2))/c;
    end
    a=1./(ones(n)+tau*1e3);
    X=mezcla_con_retardo_2(S,F,a,tau);            
end

if n==3 && metodo=='s'
    x(1,:)=real(ISTFT_overlapadd(X(:,:,1),NFFT,fs,w,noverlap));
    x(2,:)=real(ISTFT_overlapadd(X(:,:,2),NFFT,fs,w,noverlap));
    x(3,:)=real(ISTFT_overlapadd(X(:,:,3),NFFT,fs,w,noverlap));
else
    x(1,:)=real(ISTFT_overlapadd(X(:,:,1),NFFT,fs,w,noverlap));
    x(2,:)=real(ISTFT_overlapadd(X(:,:,2),NFFT,fs,w,noverlap));
end