From 83a6a0a3f3c41df0d4eae12ca5ded8e4b7d69e39 Mon Sep 17 00:00:00 2001 From: Murilo Silva Jr Date: Fri, 17 Nov 2017 11:11:17 -0500 Subject: [PATCH 1/2] updated optimal beam code --- Code/convbeam_sinr.m | 6 ++-- Code/optmbeam.m | 58 +++++++++++++++++++++++++++++++++ Code/optmbeam_sinr.m | 77 ++++++++++++++++++++++++++++++++++++++++++++ Code/optmbeam_snr.m | 51 +++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 Code/optmbeam.m create mode 100644 Code/optmbeam_sinr.m create mode 100644 Code/optmbeam_snr.m diff --git a/Code/convbeam_sinr.m b/Code/convbeam_sinr.m index 0d13e19..bce4dd3 100644 --- a/Code/convbeam_sinr.m +++ b/Code/convbeam_sinr.m @@ -38,6 +38,8 @@ PI = real(wc'*RI*wc); % Interference Power Pn = real(wc'*Rn*wc); % Noise Power + PN = PI+Pn; + P = mean(abs(y).^2); % Power through array output P = real(wc'*R*wc); % Power through correlation matrix @@ -47,8 +49,8 @@ SINRout = PS/(PI+Pn); % Absolute SINRout_dB = 10*log10(SINRout); % [dB] Decibel - Gcalc = SINRout_calc/SINRin_calc; - Gestm = SINRout/SINRin_calc; + Gcalc = S0'*((eye(L)/SNR)^-1)*S0; + Gestm = (pI^2+1/SNR)/PN; tit1 = {'Signal + Interference + Noise Correlation Matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | pI= ' num2str(pI) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; tit2 = {'Noise Correlation matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | pI= ' num2str(pI) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; diff --git a/Code/optmbeam.m b/Code/optmbeam.m new file mode 100644 index 0000000..1c8ee82 --- /dev/null +++ b/Code/optmbeam.m @@ -0,0 +1,58 @@ +%% Optimal Costrained Beamformer +%% +%

Array and Source Parameters

+% +% * Number of array elements: $$L=16$ +% * Element spacing: $$d=\frac{\lambda}{2}m$ +% * Propagation speed: $$c=3*10^8\frac{m}{s}$ +% * Signal to Noise Ratio: $$SNR=[3, 10]dB$ +% * Signal power: $$ps=1$ +% * Noise power: $$\sigma_n^2=[0.5, 0.1]$ +% * Number of samples: $$N=[10,100]$ +% * Source direction: $$\theta_k=30^o$ +% * Steering Vector in the Look direction: $$\textbf{S}_0=[exp({j2{\pi}f_0{\tau}_l}),\ldots,exp({j2{\pi}f_0{\tau}_L})]^T$ +% +% Where $$\tau_l(\theta_k)=\frac{d}{c}(l-1)sin(\theta_k)$ +% +%

Optimal Costrained Beamformer

+% +% Weight vector: $$\hat{\textbf{w}}=\frac{R^{-1}_N\textbf{S}_0}{\textbf{S}_0^HR^{-1}_N\textbf{S}_0}$ +% +%

Correlation Matrix

+% +% $$R = p_s\textbf{S}_0\textbf{S}_0^H+p_I\textbf{S}_I\textbf{S}_I^H+\sigma^2_nI$ +% +%

Array output

+% +% $$y(t)=\hat{\textbf{w}}^H\textbf{x}(t)$ +% +%

Simulation Algorithm

+% +% # Generate signal for L element array +% # Use Coventional Beamformer weight vector +% # Calculate the array output y +% # Calculate output SNR +% # Calculate array Gain +%% Signal + Noise Only +% +%

Array input

+% +% $$\textbf{x}(t)=exp({j2{\pi}f_0t})\textbf{S}_0+\textbf{n}(t)$$ +% +%

Correlation Matrix

+% +% $$R=ps*\textbf{S}_0\textbf{S}_0^H+{\sigma}_n^2{I}$$ +% +%

Signal to Noise Ratio

+% +% $$SNR=\frac{ps}{\sigma_n^2}L$$ +% +%

Array Gain

+% +% $$G=L$$ +% +%

Simulations

+% +optmbeam_snr +%% References +% [1] L. Godara, Smart antennas. Boca Raton: CRC Press, 2004. \ No newline at end of file diff --git a/Code/optmbeam_sinr.m b/Code/optmbeam_sinr.m new file mode 100644 index 0000000..b88e7cd --- /dev/null +++ b/Code/optmbeam_sinr.m @@ -0,0 +1,77 @@ +format compact; clear; close all; clc +for L = 16 % Number of elements + for N = [10 100 10000] % Number of samples + for SNR_dB = [3 10] % [dB] Signal to Noise Ratio + for th_s = 30 % [deg] Source direction from normal of the array + for th_i = 60 % [deg] Interference direction from normal of the array + for pI = [0.1 1] % Interference Amplitude + %% + SNR = 10^(SNR_dB/10); % Absolute Signal to Noise Ratio + psi_s = pi*sind(th_s); % Phase difference between elements + psi_i = pi*sind(th_i); + SI = exp(-1j*psi_i*((1:L)-1)'); + S0 = exp(-1j*psi_s*((1:L)-1)'); + w = ((eye(L)/SNR)^-1)*S0/(S0'*((eye(L)/SNR)^-1)*S0); % convention beamformer in the look direction + + for N = 1:N + [~, S, n] = ArrayMeasurementPlusNoiseGenerator(SNR_dB,psi_s,L); % Generate array measurements + [~, I, ~] = ArrayMeasurementPlusNoiseGenerator(SNR_dB,psi_i,L); % Generate array measurements + I = pI*exp(-1j*2*pi*rand).*I; + x = S + I + n; + R(:,:,N) = x*x'; % Signal + Noise Correlation matrix for sample N + Rs(:,:,N) = S*S'; % Signal Correlation matrix for sample N + RI(:,:,N) = I*I'; % Interference Correlation matrix for sample N + Rn(:,:,N) = n*n'; % Noise Correlation matrix for sample N + y(N) = w'*x; % Array output + end + + SI = mean(SI,3); + + R = mean(R,3); % Signal + Noise Correlation matrix + Rs = mean(Rs,3); % Signal Correlation matrix + RI = mean(RI,3); % Interference Correlation matrix + Rn = mean(Rn,3); % Noise Correlation matrix + + rho = 1-((S0'*SI)*(SI'*S0))/(L^2); + + PS_cal = real(w'*S0*S0'*w); + PS = real(w'*Rs*w); % Signal Power + + PI_cal = real((0.1)^2*w'*SI*SI'*w); + PI = real(w'*RI*w); % Interference Power + + Pn_cal = real((1/SNR)*w'*w); + Pn = real(w'*Rn*w); % Noise Power + + P_cal = PS_cal + Pn_cal + PI_cal; + P = mean(abs(y).^2); % Power through array output + P = real(w'*R*w); % Power through correlation matrix + + PN = PI+Pn; + + SINRin_calc = 1/((pI^2)*(1-rho)+(1/SNR)); % Signal to Interference + Noise Ratio + SINRout_calc = 1/((pI^2)*(1-rho)+(1/SNR)/L); + + SINRout = PS/PN; % Absolute + SINRout_dB = 10*log10(SINRout); % [dB] Decibel + + Gcalc = ((pI^2)*L/(1/SNR))*(1+(1/SNR)/pI^2)*(rho+(1/SNR)/(pI^2*L))/(1+(1/SNR)/(pI^2*L)); + Gestm = (pI^2+1/SNR)/PN; + + tit1 = {'Signal + Interference + Noise Correlation Matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | pI= ' num2str(pI) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; + tit2 = {'Noise Correlation matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | pI= ' num2str(pI) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; + figure + imagesc(abs(R)) + title(tit1) + colorbar + figure + imagesc(abs(Rn)) + colorbar + title(tit2) + %% + end + end + end + end + end +end \ No newline at end of file diff --git a/Code/optmbeam_snr.m b/Code/optmbeam_snr.m new file mode 100644 index 0000000..3106d44 --- /dev/null +++ b/Code/optmbeam_snr.m @@ -0,0 +1,51 @@ +format compact; clear; close all; clc; +for L = 16 % Number of elements + for N = [10 100 10000] % Number of samples + for SNR_dB = [3 10] % [dB] Signal to Noise Ratio + for th_s = 30 % [deg] Source direction from normal of the array + %% + SNR = 10^(SNR_dB/10); % Absolute Signal to Noise Ratio + psi = pi*sind(th_s); % Phase difference between elements + + wc = (1/L)*exp(-1j*psi*((1:L)-1)'); % convention beamformer in the look direction + + for N = 1:N + [x, S, n] = ArrayMeasurementPlusNoiseGenerator(SNR_dB,psi,L); % Generate array measurements + R(:,:,N) = x*x'; % Signal + Noise Correlation matrix for sample N + Rs(:,:,N) = S*S'; % Signal Correlation matrix for sample N + Rn(:,:,N) = n*n'; % Noise Correlation matrix for sample N + y(N) = wc'*x; % Array output + end + + R = mean(R,3); % Signal + Noise Correlation matrix + Rs = mean(Rs,3); % Signal Correlation matrix + Rn = mean(Rn,3); % Noise Correlation matrix + + PS = real(wc'*Rs*wc); % Signal Power + Pn = real(wc'*Rn*wc); % Noise Power + + P = mean(abs(y).^2); % Power through array output + P = real(wc'*R*wc); % Power through correlation matrix + + SINRout = PS/Pn; % Absolute + SINRout_dB = 10*log10(SINRout); % [dB] Decibel + + Gcalc = L; + Gestm = (1/SNR)/Pn; + + tit1 = {'Signal + Noise Correlation matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; + tit2 = {'Noise Correlation matrix';['N=' num2str(N) ', SNR=' num2str(SNR_dB) ' | Calc. Gain= ' num2str(Gcalc) ' | Est. Gain= ' num2str(Gestm)]}; + + figure + imagesc(abs(R)) + title(tit1) + colorbar + figure + imagesc(abs(Rn)) + colorbar + title(tit2) + %% + end + end + end +end \ No newline at end of file From 947575b7818042e71baa928e95e709578ed8f37a Mon Sep 17 00:00:00 2001 From: Murilo Silva Jr Date: Wed, 22 Nov 2017 15:24:34 -0500 Subject: [PATCH 2/2] added LMS algorithm for both 1 and 2 sources --- Code/lmsbeam_1source.m | 67 ++++++++++++++++++++++++++++++++++++++++++ README.md | 3 +- docs/index.html | 11 ++++++- 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 Code/lmsbeam_1source.m diff --git a/Code/lmsbeam_1source.m b/Code/lmsbeam_1source.m new file mode 100644 index 0000000..00735d6 --- /dev/null +++ b/Code/lmsbeam_1source.m @@ -0,0 +1,67 @@ +format compact; clear; clc; close all; + +L = 16; + +w0 = 2*pi/2048; +mu = 0.01; +dth = 20; + +w = ones(L,1)*0.01; +w2= w; +N = 1000; % Number of look directions +dt = 1/N; % phase unwrap in sin(theta) domain +u = (-N:N)'; % increment in sin(theta) domain +theta=asin(u*dt); % theta vector [deg] +a = exp(1j*pi*dt*u*(0:(L-1))); +e = zeros(1,1e5); + +for K = [64] + figure('units','normalized','outerposition',[0 0 1 1]) + d1 = sign(rand(K,1)-0.5); + d2 = sign(rand(K,1)-0.5); + for n = 1:1e5 + th1 = 30+dth*sin(w0*n); + th2 = 30-dth*sin(w0*n); + psi1 = pi*sind(th1); + psi2 = pi*sind(th2); + [S1,~,~] = ArrayMeasurementPlusNoiseGenerator(10,psi1,L); + [S2,~,~] = ArrayMeasurementPlusNoiseGenerator(10,psi2,L); + + S = S1*d1(mod(n+K-1,K)+1) + S2*d2(mod(n+K-1,K)+1); + + %% Target 1 + y = w(:,n)'*S; + e(n) = d1(mod(n+K-1,K)+1)-y; + g = -2*S*e(n)'; + w(:,n+1) = w(:,n)-mu*g; + look = (abs(a*w(:,n))); + look = look./max(look); + + %% Target 2 + y2 = w2(:,n)'*S; + e2(n) = d2(mod(n+K-1,K)+1)-y2; + g2 = -2*S*e2(n)'; + w2(:,n+1) = w2(:,n)-mu*g2; + look2 = (abs(a*w2(:,n))); + look2 = look2./max(look2); + + %% Plotting + if mod(n-1,10)==0 + subplot(121) + polarplot(th1*pi/180,1,'*','linewidth',2) + hold on + polarplot(th2*pi/180,1,'*','linewidth',2) + polarplot(theta,look,'linewidth',2) + polarplot(theta,look2,'linewidth',2) + hold off + + subplot(122) + loglog((1:n)-1,abs(e(1:n)./max(abs(e(1:n)))),'-*','linewidth',2) + hold on + loglog((1:n)-1,abs(e2(1:n)./max(abs(e2(1:n)))),'-*','linewidth',2) + grid on + hold off + drawnow + end + end +end \ No newline at end of file diff --git a/README.md b/README.md index 943db17..01b53ee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# ECE595 -Adaptive Array Processing +[WEBSITE](https://msilva12.github.io/AdaptiveArrayProcessing/) \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index befdf7a..55e2fff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,5 +3,14 @@ title: Adaptive Array Processing ---

-

{{ site.description | default: site.github.project_tagline }}

+

This project contains beamformer code selection in MATLAB to illustrate their performances and implementations.

+

Beamformers Explored:

+ +

Adaptive Beamformers Explored:

+

\ No newline at end of file