配套毕业设计论文见百度文库
请搜索
《基于 MATLAB 的 GPS 信号仿真 123》
附录 C 仿真程序代码
1、数据码的产生
function datacode=data(x)
y=rand(1,x);
for i=1:x
if y(i)<0.5
datacode(i)=0;
else
datacode(i)=1;
end
end
y(1)=0;
show2(1)=datacode(1);
q=2;
for i=1:length(datacode)
for j=1:100
y(q)=i-1+j*0.01;
show2(q)=datacode(i);
q=q+1;
end
end
plot(y,show2);
axis([0 length(datacode) -0.2 1.2]);
1、C/A 码的产生及扩频调制
clc;
c=input('请输入数据码的长度:c=');
y=rand(1,c);
for i=1:c
if y(i)<0.5
datacode(i)=0;
else
datacode(i)=1;
end
end
x(1)=0;
show(1)=datacode(1);
p=2;
for i=1:c
for j=1:100
x(p)=i-1+j*0.01;
show(p)=datacode(i);
p=p+1;
end
end
subplot(4,1,1);
plot(x,show);
title('数据码');
axis([0 c -0.2 1.2]);
number=input('请输入卫星 PRN 号码:number=');
cacode=CAgenerate(number);
temp=cacode(1:100)
x(1)=0;
show(1)=temp(1);
p=2;
%下面的循环是为了将结果显示成方波形式
for i=1:length(temp)
for j=1:100
x(p)=i-1+j*0.01;
show(p)=temp(i);
p=p+1;
end
end
%画出仿真结果图
subplot(4,1,2);
plot(x,show);
title('C/A 码');
axis([0 100 -0.2 1.2]);
%截取 CA 码的前十个数据进行扩频,每个数据插入 5 个 CA 序列
cacode1=cacode(1:10);
for i=1:c
if datacode(i)==1
datacodek((i-1)*50+1:i*50)=ones(1,50);
else
datacodek((i-1)*50+1:i*50)=zeros(1,50);
end
end
for i=1:c
for j=1:50
addr=rem(((i-1)*50+j),10);
if addr==0
addr=10;
end
kuopindata((i-1)*50+j)=xor(datacodek((i-1)*50+j),cacode1(addr));
end
end
%下面的循环是为了将结果显示成方波形式
x(1)=0;
show(1)=kuopindata(1);
p=2;
for i=1:length(kuopindata)
for j=1:100
x(p)=i-1+j*0.01;
show(p)=kuopindata(i);
p=p+1;
end
end
subplot(4,1,3);
plot(x,show);
title('扩频数据');
axis([0 length(kuopindata) -0.2 1.2]);
%每位数据通过正弦波来调制
Sinwave=sin([0:2*pi/8:2*pi*7/8]);
Sinwave=single(Sinwave);
GPSsignal=zeros(1,1);
Sinwave=[Sinwave Sinwave Sinwave Sinwave Sinwave];
for i=1:length(kuopindata)
GPSsignal=[GPSsignal kuopindata(i)*Sinwave];
end
GPSsignal=GPSsignal(2:length(GPSsignal));
subplot(4,1,4);
plot(GPSsignal(1:500));
title('调制后数据');
C/A 码产生的子程序 CAgenerate:
function cacode=CAgenerate(number)
if (number<1)|(number>37)
disp('输入参数必须在 1 ~ 37 之间取值');
return
评论1