
clear all
close all
clc
%---------------
Frecuencia=500;
%---------------
Vertical=40;      
Horizontal=40;    
Step=0.05;

MICx=10;
MICy=20;



%[p,h,IR,fs]=arrayceroy17(Frecuencia,Vertical,Horizontal,Step,MICx,MICy);
%[p,h,IR,fs]=steering27(Frecuencia,Vertical,Horizontal,Step,MICx,MICy);

%[p,h,IR,fs]=paper(Frecuencia,Vertical,Horizontal,Step,MICx,MICy);
[p,h,IR,fs]=cbtdigital(Frecuencia,Vertical,Horizontal,Step,MICx,MICy);

figure
clipvals = [-42,0];
imagesc((0:Step:Horizontal-Step),(0:Step:Vertical-Step),(20.*log10(abs(p))),clipvals);shading interp; axis equal;colorbar;
%xlim([Horizontal/2-0.5 Horizontal]),%ylim([Vertical/2-20 Vertical/2+20])
title(['Frequency = ' num2str(Frecuencia) ' Hz']),xlabel('x(m)'),ylabel('y(m)');
text(MICx,abs(MICy-Vertical),'* MIC1')
   
%''''''''''''''''''''''''''''''''''''''''''''''
% figure
% clipvals = [-.8,.8];
% imagesc(0:Step:Horizontal-Step,0:Step:Vertical-Step,flipud(real(p)),clipvals);shading interp; axis equal;colorbar;
% title(['Frequency = ' num2str(Frecuencia) ' Hz']),xlabel('x(m)'),ylabel('y(m)')
%'''''''''''''''''''''''''''''''''''''''''''''''
% figure
% clipvals = [-pi,pi];
% imagesc(0:Step:Horizontal-Step,0:Step:Vertical-Step,flipud(angle(p)),clipvals);shading interp; axis equal;colorbar;
% title(['Frequency = ' num2str(Frecuencia) ' Hz']),xlabel('x(m)'),ylabel('y(m)')

figure
ang=0:2*pi/length(h):2*pi-2*pi/length(h);
negpolar(ang,h,'-k',-30,1);title(['Frequency = ' num2str(Frecuencia) ' Hz']);
set(gcf,'Color',[1,1,1]),view(-270,90);


Nfft=2048*4;

%load IRlobeinf
ff=fs*[0:Nfft-1]/Nfft-fs/2;
%IMPon=fft(IRon,Nfft);
IMP=fft(IR,Nfft);


% load IRlobeinf
%load IMPlmbymed

figure
%subplot(3,1,1)
plot(1000*(1:length(IR))/fs,IR);xlabel('time (ms)');title('Impulse Response');grid on;xlim([0 50])

subplot(2,1,1);semilogx(ff,20.*log10(abs(fftshift(IMP))));xlim([40 16000]);grid on;
title('Frequency Response');xlabel('Frequency (Hz)');ylabel('dB');ylim([-100 0]);legend('0','0 Deg')
subplot(2,1,2);semilogx(ff,(180/pi)*angle(fftshift(IMP)));xlim([0 fs/2]);grid on
title('Phase');xlabel('Frequency (Hz)');ylabel('Degrees');

% 
subplot(2,1,1);semilogx(ff,20.*log10(abs(fftshift(IMP))),ff,20.*log10(abs(fftshift(IMPmedia))));xlim([40 16000]);grid on;
title('Frequency Response');xlabel('Frequency (Hz)');ylabel('dB');ylim([-50 0]);legend('-17 Deg','0 Deg')
subplot(2,1,2);semilogx(ff,(180/pi)*angle(fftshift(IMP)),ff,(180/pi)*angle(fftshift(IMPmedia)));xlim([0 fs/2]);grid on
title('Phase');xlabel('Frequency (Hz)');ylabel('Degrees');













