1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| clc;clear;close all; f_clk=1.023e6; fs=f_clk*10; t=[0:(1/fs):((10e-3)-1/fs)]; N=1023; tags = [[2 6];[3 7];[4 8];[5 9];[1 9];[2 6];[1 8];[2 9];[3 10];[2 3];... [3 4];[5 6];[6 7];[7 8];[8 9];[9 10];[1 4];[2 5];[3 6];[4 7];... [5 8];[6 9];[1 3];[4 6];[5 7];[6 8];[7 9];[8 10];[1 6];[2 7];... [3 8];[4 9]]; [wave_CA_1,code_CA_1]=CA_generation(tags(6,:),f_clk,t); [wave_CA_2,code_CA_2]=CA_generation(tags(12,:),f_clk,t);
x_cor=-2*N+1:1:2*N-1; m_1=cor_cir(code_CA_1,code_CA_1,length(x_cor))/length(code_CA_1); m_12=cor_cir(code_CA_1,code_CA_2,length(x_cor))/length(code_CA_1); figure(); subplot(2,1,1); plot(x_cor,m_1); ylim([-0.2,1.2]); title('CA码自相关函数'); xlabel('延迟码片数'); ylabel('自相关函数值'); subplot(2,1,2); plot(x_cor,m_12); ylim([-0.2,1.2]); title('CA码互相关函数'); xlabel('延迟码片数'); ylabel('自相关函数值'); [psd_CA,w_CA]=pwelch(wave_CA_1,[],[],[],fs,'centered','psd'); figure(); plot(w_CA/1e6,10*log10(psd_CA)); title('CA码功率谱密度'); xlabel("频率/MHz"); ylabel("幅度/dB");
function [wave,code]=CA_generation(phase_tag,F_CLK,T) reg_G1=-ones(1,10); reg_G2=-ones(1,10); index_code=0; t_chip=1/F_CLK; wave=zeros(1,length(T)); code=zeros(1,length(T)*F_CLK*(T(2)-T(1))); for i0=1:length(T) if (T(i0)>=T(1)+index_code*t_chip) sum_G1=reg_G1(3)*reg_G1(10); reg_G1(2:10)=reg_G1(1:9); reg_G1(1)=sum_G1; sum_G2=reg_G2(2)*reg_G2(3)*reg_G2(6)*reg_G2(8)*reg_G2(9)*reg_G2(10); reg_G2(2:10)=reg_G2(1:9); reg_G2(1)=sum_G2; index_code=index_code+1; code(index_code)=reg_G1(10)*reg_G2(phase_tag(1))*reg_G2(phase_tag(2)); end wave(i0)=code(index_code); end end
function [seq_cor]=cor_cir(code_in1,code_in2,cor_n) seq_cor=zeros(1,cor_n); for i1=1:length(seq_cor) for i2=1:length(code_in1) f=mod(i2+i1,length(code_in1)); if (f==0) f=length(code_in1); end seq_cor(i1)=seq_cor(i1)+code_in1(i2)*code_in2(f); end end end
|