本文仿真了CW、LFM、HFM、Bark二相編碼、Costas頻率編碼信號的模糊函數(shù),此外還利用模擬退火算法尋找N相編碼的最優(yōu)編碼并繪制了其模糊函數(shù)。
模糊函數(shù)的計算和模擬退火算法有參考網(wǎng)絡(luò)資源。
代碼如下:
close all; clear all; clc;
T = 0.26;
fs = 20e3;
fc = 1e3;
B = 1000;
t = 0:1/fs:T-1/fs;
type_index = 6;
type_name = {'PCW', 'LFM', 'HFM', 'Bark', 'Costas', 'PolyPhase'};
switch type_index
case 1
% 1. pcw
x = exp(1i*2*pi*fc*t);
case 2
% 2. lfm
k = B/T;
f0 = fc-B/2;
x = exp(1i*2*pi*(f0*t+k/2*t.^2));
case 3
% 3. hfm
f0 = fc+B/2;
beta = B/f0/(fc-B/2)/T;
x = exp(1i*2*pi/beta*log(1+beta*f0*t));
case 4
% 4.bark信號
% 4. hfm + pcw
% f0 = fc+B/2;
% beta = B/f0/(fc-B/2)/T;
% x = sin(2*pi/beta*log(1+beta*f0*t)) + sin(2*pi*fc*t);
% bark = [1,1,1,1,1,-1,-1,1,1,-1,1,-1,1];
bark = (randi(2,1,100)-1)*2-1;
Tbark = T/length(bark);
tbark = 0:1/fs:Tbark-1/fs;
s = zeros(1,length(bark)*length(tbark));
for i = 1:length(bark)
if bark(i) == 1
s((i-1)*length(tbark)+1:i*length(tbark))=exp(1j*2*pi*fc*tbark);
else
s((i-1)*length(tbark)+1:i*length(tbark))=exp(1j*(2*pi*fc*tbark+pi));
end
end
x = [s, zeros(1,length(t)-length(s))];
case 5
% 5.costas信號
costas = [2,4,8,5,10,9,7,3,6,1];
f = fc-B/2+(costas-1)*B/(length(costas)-1);
Tcostas = T/length(costas);
tcostas = 0:1/fs:Tcostas-1/fs;
s = zeros(1,length(costas)*length(tcostas));
for i = 1:length(costas)
s((i-1)*length(tcostas)+1:i*length(tcostas)) = exp(1j*2*pi*f(i)*tcostas);
end
x = [s,zeros(1,length(t)-length(s))];
case 6
% 6.PolyPhase信號
N = 20;
M = 2;
[route_best,Energy_best] = SA_TSP(N, M);
Tsubpulse = T/N;
k = B/Tsubpulse;
tsubpulse = 0:1/fs: Tsubpulse-1/fs;
s = zeros(1,N*length(tsubpulse));
for i=1:N
s((i-1)*length(tsubpulse)+1:i*length(tsubpulse)) = exp(1j*(2*pi*fc*tsubpulse+pi*k*tsubpulse.^2+route_best(i)/M*2*pi));
end
x = [s,zeros(1,length(t)-length(s))];
end
re_fs = 0.9*fs:2:1.1*fs;
alpha = re_fs/fs; % Doppler ratio, alpha = 1-2*v/c
doppler = (1-alpha)*fc; % Doppler = 2v/c*fc = (1-alpha)*fc
N_a = length( resample(x,fs,min(re_fs)) );
N = N_a + length(x)-1;
afmag = zeros(length(alpha),N);
tic
parfor i = 1:length(alpha)
if ceil(length(x)/alpha(i)) ~= N_a
x_alpha = [resample(x,fs,re_fs(i)),zeros(1, N_a-ceil(length(x)/alpha(i)))];
else
x_alpha = resample(x,fs,re_fs(i));
end
% x_alpha = Doppler(x,1/re_fs(i),1/fs);
x_temp = zeros(1,length(x_alpha));
for j = 1:length(x_alpha)
x_temp(j) = conj(x_alpha(length(x_alpha)-j+1));
end
% disp(num2str(i))
afmag_temp = conv(x_temp,x);
M = length(afmag_temp);
afmag(i,:) = afmag_temp*sqrt(alpha(i));
end
toc
delay = ([1:N]-N_a)/fs;
tau = 0.2;
fd = 100;
indext = find(delay>=-tau & delay<=tau);
indexf = find(doppler>=-fd & doppler<=fd);
delay1 = delay(indext);
doppler1 = doppler(indexf);
mag = abs(afmag);
mag = mag/max(max(mag));
% mag = 10*log10(mag);
mag1 = mag(:,indext);
mag1 = mag1(indexf,:);
[row,column] = find(mag1<-100);
mag1(row,column)=-60;
figure(1);
mesh(doppler1,delay1,mag1.');
% axis([-100,100,-tau,tau,-50,0]);
colorbar;
set(gcf,'color','w');
xlabel('Doppler (Hz)','FontName','Times New Roman','FontSize',10);
ylabel('Delay (sec)','FontName','Times New Roman','FontSize',10);
zlabel('Level (dB)','FontName','Times New Roman','FontSize',10);
title(['WAF of ',type_name{type_index} ,' Signal'],'FontName','Times New Roman','FontSize',10);
figure(2);
% v=[-3,-3];
% contour(delay1,doppler1,mag1,v,'ShowText','on');grid on;%模糊度圖
contour(delay1,doppler1,mag1);grid on;%模糊度圖
xlabel('Delay (Sec)','FontName','Times New Roman','FontSize',10);
ylabel('Doppler (Hz)','FontName','Times New Roman','FontSize',10);
title('Contour of AF','FontName','Times New Roman','FontSize',10)
figure(3)
subplot(211);
plot(doppler1,mag1(:,floor(length(indext)/2)),'b')
xlabel('Doppler (Hz)','FontName','Times New Roman','FontSize',10);
ylabel('Amp','FontName','Times New Roman','FontSize',10);
title('Zero Delay','FontName','Times New Roman','FontSize',10)
subplot(212)
plot(delay1,mag1(floor(length(indexf)/2),:),'b')
xlabel('Delay (sec)','FontName','Times New Roman','FontSize',10);
ylabel('Amp','FontName','Times New Roman','FontSize',10);
title('Zero Doppler','FontName','Times New Roman','FontSize',10)
%%
temp=clock;
temp=sum(temp(4:6))*sum(temp(2:3));
temp=round(temp/10);
rand('seed',temp);
%%
plot([0:length(x_alpha)-1]/length(x_alpha)*fs,abs(fft(x_alpha)));
hold on;
plot([0:length(x_alpha2)-1]/length(x_alpha2)*fs,abs(fft(x_alpha2)))
2.模擬退火算法代碼如下:
function [route_best,Energy_best] = SA_TSP(N,M)
Initial_temp = 1000;
res = 1e-3; % 最低溫限制
ratio = 0.9; % 降溫參數(shù),控制溫度的下降
temperature = Initial_temp;
Markov_length = 20; % 改變解的次數(shù)
temp=clock;
temp=sum(temp(4:6))*sum(temp(2:3));
temp=round(temp/10);
rand('seed',temp);
route_new = randi(M, 1, N); % 新產(chǎn)生的解路線
Energy_current = inf; % 當(dāng)前解的能量
Energy_best = inf; % 最優(yōu)解的能量
route_current = route_new; % 當(dāng)前解路線
route_best = route_new; % 最優(yōu)解路線
pic_num = 1;
% 外層while循環(huán)控制降溫過程,內(nèi)層for循環(huán)控制新解的產(chǎn)生。
while temperature >res
Energy1=Energy_best; % 用于控制循環(huán)的結(jié)束條件
for i = 1: Markov_length
% 產(chǎn)生新解(對當(dāng)前解添加擾動)
if rand >0.5
% 兩點交換
a = 0;
b = 0;
while (a==b)
a = randi(N);
b = randi(N);
end
route_new(a) = randi(M);
route_new(b) = randi(M);
else
route_new(randperm(N,3)) = randi(M,1,3);
end
[Energy_new, ~] = SeqCorr(route_new,N,M);
% 按照Metroplis準(zhǔn)則接收新解
if Energy_new
3.代價函數(shù)模擬退火算法所優(yōu)化的目標(biāo)函數(shù)為編碼信號的積分旁瓣電平值(ISL)。
代碼如下:
function [cost, Correlation] = SeqCorr(route_new, N, M)
code = exp(1i*[1:M]/M*2*pi);
Seq = code(route_new);
Correlation = abs(xcorr(Seq, Seq));
cost = abs(sum(Correlation)-Correlation(N));
end
4.結(jié)果圖象以上是自己基于理解所做的仿真,若有錯誤,希望大家能指出并一起交流學(xué)習(xí)。
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧