clear
clc
close all
% % % %下列用到的一个组合
% % % %tic 计时开始
% % % %toc 计时结束
%==========================================================================
%线阵
%================================线阵-常规算法==============================
theta = linspace(0,180,1024);%theta采样点
N = 16;
I = ones(1,N); %10个阵元,等幅同向激励
j = sqrt(-1);
dx = 0.5; %阵元间距
dx = 3/4;
% 方向图计算
for th = 1:length(theta)
S(th) = 0;
for n = 1:N
S(th) = S(th)+I(n)*exp(j*n*2*pi*dx*cosd(theta(th)));
end
end
S_abs = abs(S); %方向图取模
S_max = S_abs/max(S_abs); %方向图归一
S_db = 20*log10(S_max); %归一转换为db,也可以写为 S_db = db(S_max);
% 作图
figure(1)
plot(theta,db(S_max));
% ===============================线阵-傅里叶变化=============================
% N = 10;
% I = ones(1,N);
% S_fft = ifft(I,512); %傅里叶变换
% S_2 = ifftshift(S_fft); %前后颠倒
% S_2_abs = abs(S_2);
% S_2_max = S_2_abs/max(S_2_abs);
% S_2_db = 20*log10(S_2_max);
% figure(3)
% plot(S_2_db)
% %线阵常规算法与傅里叶算法作图比较
% % %不做处理作图
% figure(4)
% plot(cosd(theta),S_db,'g-',linspace(-1,1,512),S_2_db,'b*')
% % % 根据间距进行变化,可见区域作图
% figure(5)
% plot(cosd(theta),S_db,'g-',linspace(-1/(2*dx),1/(2*dx),512),S_2_db,'b*')
%=================================面阵-傅里叶变换===========================
% I = ones(16,16);
% K = 512;
% S_fft = ifft2(I,K,K);
% S_2 = ifftshift(S_fft);
% S_2_abs = abs(S_2);
% S_2_max = S_2_abs/max(max(S_2_abs));
% S_2_db = 20*log10(S_2_max);
% % 常规面阵作图
% figure
% mesh(S_2_db)
% % u=0和v=0两个面画图
% figure
% plot(S_2_db(:,K/2+1));% AF_db代表的方向图,AF_db(:,K/2+1)冒号代表整个一行全部选中,选中第K/2+1列
% figure
% plot(S_2_db(K/2+1,:));
%================================面阵-常规作图==============================
% tic
% j = sqrt(-1);
% theta = 0:1:90;
% phi = 0:1:360;
% N = 10;
% dx = 0.5;
% dy = 0.5;
% x = zeros(1,N);
% y = zeros(1,N);
% x(2:end) = dx;
% y(2:end) = dy;
% x = cumsum(x);
% y = cumsum(y);
% [X,Y] = meshgrid(x,y);
% for th = 1:length(theta)
% for ph = 1:length(phi)
% U(th,ph) = sind(theta(th))*cosd(phi(ph));
% V(th,ph) = sind(theta(th))*sind(phi(ph));
% D(th,ph) = sum(sum(exp(j*2*pi*(X*U(th,ph)+Y*V(th,ph))+Z)));
% end
% end
% S = abs(D);
% S_max = max(max(S));
% AF = S/S_max;
% figure
% mesh(U,V,20*log10(AF))
% toc
%=============================使用克罗内克积进行计算=========================
%单算一个计算速度与普通的没有什么变化,但是用于循环的话,速度会变快
%==========================================================================
% tic
% j = sqrt(-1);
% theta = 0:1:90;
% phi = 0:1:360;
% N = 10;
% dx = 0.5;
% dy = 0.5;
% x = zeros(1,N);
% y = zeros(1,N);
% x(2:end) = dx;
% y(2:end) = dy;
% x = cumsum(x);
% y = cumsum(y);
% [X,Y] = meshgrid(x,y);
% for th = 1:length(theta)
% for ph = 1:length(phi)
% U(th,ph) = sind(theta(th))*cosd(phi(ph));
% V(th,ph) = sind(theta(th))*sind(phi(ph));
% end
% end
% A = exp(j*2*pi*(kron(U,X)+kron(V,Y)));
% m = ones(1,length(theta))*N;
% n = ones(1,length(phi))*N;
% B = mat2cell(A,m,n);
% I_1 = ones(N,N,50);%每组激励N*N个阵元,一共50组激励
% for M = 1:50
% I = I_1(:,:,M);
% C = cellfun(@(x) x.*I,B,'uniformoutput',false);
% D = cellfun(@sum,cellfun(@sum,C,'UniformOutput',false));
% S = abs(D);
% S_max = max(max(S));
% AF = S/S_max;
% SLL(:,:,M) = AF;
% end
% figure
% mesh(U,V,20*log10(SLL(:,:,2)))
% toc
评论5