⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syn_test.m

📁 Mtlab toolbox containing useful m files to generate LPI signals
💻 M
字号:
%% FREQUENCY SYNTHESIS ALGORITHM
%% Frequencies are in the vector "detection"
function syn_test = syn_test; 

fid=['Ship'];
global N;
global target;
new_rec= target(:,1:2);

%**********************************************
%NO EDITS BELOW
%**********************************************

% PULL OFF THE DECIMAL DIGITS

[nn,jo]=size(new_rec); 	% Determine number
			% of detections or rows
 			
			% Pull off the density
			% decimal digits as strings
delta=sprintf('%6.4f',new_rec(:,2)); 
ss=reshape(delta, 6, nn);
ss=ss';
			% Turn back into a number
			% with each digit a column
deltas(:,[1])=str2num(ss(:,3));
deltas(:,[2])=str2num(ss(:,4));
deltas(:,[3])=str2num(ss(:,5));
deltas(:,[4])=str2num(ss(:,6));

%% kk =4; 			% NUMBER OF DECIMAL DIGITS

			% Define probabilities
			% p1 through p4
p0=0;
p1=10^(-1) * sum(deltas(:,1));
p2=10^(-2) * sum(deltas(:,2));
p3=10^(-3) * sum(deltas(:,3));
p4=10^(-4) * sum(deltas(:,4));

			% Determine pi values
pi0= 0;
pi1= 10*p1;
pi2= (10*p1)+(10^2 * p2);
pi3= (10*p1)+(10^2 * p2)+(10^3 * p3);
pi4= (10*p1)+(10^2 * p2)+(10^3 * p3) + (10^4 * p4);

			% Determine test values for
			% the uniform random variable
ptest0=0;
ptest1=p1;
ptest2=ptest1+p2;
ptest3=ptest2+p3;
ptest4=ptest3+p4;

			% FILL MEMORY LOCATION
			% SET 1

ok=0; 
for j=1:nn    % RANDOM VARIABLE INDEX
	if deltas(j,1)~=0
		for i=1:deltas(j,1)	
			mem(i+ok,1)=j;
		end
		ok=i+ok;
	end
end
if deltas(j,1)~=0
    [mem_size xx]=size(mem);
else
     mem_size = 0;
     xx = 0;
end

			% FILL MEMORY LOCATIONS
			% SET 2
ok=0; 
for j=1:nn   % RANDOM VARIABLE INDEX
	if deltas(j,2)~=0
		for i=1:deltas(j,2)	
			mem(i+ok+mem_size,1)=j;
		end
		ok=i+ok;
      	end
end

[mem_size xx]=size(mem);

			% FILL MEMORY LOCATIONS
			% SET 3
ok=0; 
for j=1:nn   % RANDOM VARIABLE INDEX
	if deltas(j,3)~=0
		for i=1:deltas(j,3)	
			mem(i+ok+mem_size,1)=j;
		end
		ok=i+ok;
      	end
end

[mem_size xx]=size(mem);

			% FILL MEMORY LOCATIONS
			% SET 4
ok=0; 
for j=1:nn   % RANDOM VARIABLE INDEX
	if deltas(j,4)~=0
		for i=1:deltas(j,4)	
			mem(i+ok+mem_size,1)=j;
		end
		ok=i+ok;
      	end
end
%____________________________________________________
			% Now that mem is filled
			% generate the detections

			% nn number of detections

for gi=1:N
			% uni is the uniform RV
			% pull the decimal digits off
uni=rand;
uni_str=sprintf('%6.4f',uni) ;
sss=reshape(uni_str, 6, 1);
sss=sss';

d1=str2num(sss(:,3));
d2=str2num(sss(:,4));
d3=str2num(sss(:,5));
d4=str2num(sss(:,6));

			% Test the RV to find correct 
			% index.  Then generate detection
% DETECTION

global detection;
if uni >= 0 & uni < ptest1
	rv_index=mem(d1+1,1);
	detection(gi,[1])=new_rec(rv_index,(1:1));
elseif uni >= ptest1 & uni < ptest2
	const=pi1-(100*(p1));
	rv_index=mem(d1*10 + d2 + const +1,1);
	detection(gi,[1])=new_rec(rv_index,(1:1));
elseif uni >= ptest2 & uni < ptest3
	const=pi2-(1000*(p1+p2));
	rv_index=mem(d1*100 + d2*10 + d3 + const +1,1);
	detection(gi,[1])=new_rec(rv_index,(1:1));
elseif uni >= ptest3 & uni < ptest4
	const=pi3-(10000*(p1+p2+p3));
	rv_index=mem(d1*1000 + d2*100 + d3*10 +d4 + const +1,1);
	detection(gi,[1])=new_rec(rv_index,(1:1));
end

end



% % ____________________PLOTS____________________
% % 
% figure
% 
% orient tall;
% subplot(2,1,1),
% hist(detection(:,1),N);
% xlabel('Detection Index');
% ylabel('Number of Occurences');
% fid1=[fid,'  SYNTHETIC'];
% title(fid1);
% 
% subplot(2,1,2),
% bar(new_rec(:,1), new_rec(:,2));
% xlabel('Detection Index')
% ylabel('Probability')
% fid2=[fid,'  ORIGINAL'];
% title(fid2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -