www.gusucode.com > GPS仿真Matlab编程源码程序 > GPS仿真Matlab编程源码程序/test_gpsArray_mianzhen.m

    % ***** 由单颗卫星数据(>=4颗)合成阵列天线数据,
% ***** 
% ***  wl 2009.07.14
clc;
clear; close all

% 读取数据

N=6e4;   % 10ms数据,6M采样率


tic
for i=1:3640   % 1 s data length,
    
    fid=fopen('C:\sv1.dat');
    status=fseek(fid,2*N*(i-1),0)  % cof or "0" :  move position indicator N bytes after origin
    dat1=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星1
    fclose(fid)
    guiyiDat1=(dat1-mean(dat1))/sqrt(var(dat1));

   fid=fopen('C:\sv2.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat2=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星2
   fclose(fid)
   guiyiDat2=(dat2-mean(dat2))/sqrt(var(dat2));
   
   fid=fopen('C:\sv3.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat3=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星3
   fclose(fid)
   guiyiDat3=(dat3-mean(dat3))/sqrt(var(dat3));
   
   fid=fopen('C:\sv6.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat4=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星4
   fclose(fid)
   guiyiDat4=(dat4-mean(dat4))/sqrt(var(dat4));
   
    fid=fopen('C:\sv14.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat5=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星5
   fclose(fid)
   guiyiDat5=(dat5-mean(dat5))/sqrt(var(dat5));
   
   fid=fopen('C:\sv20.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat6=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星6
   fclose(fid)
   guiyiDat6=(dat6-mean(dat6))/sqrt(var(dat6));
   clear dat6
      
   fid=fopen('C:\sv22.dat');
   status=fseek(fid,2*N*(i-1),0)  % cof or "0"
   dat7=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星7
   fclose(fid)
   guiyiDat7=(dat7-mean(dat7))/sqrt(var(dat7));
   clear dat7
         
%    fid=fopen('D:\pp\数据生成\tag\sv25.dat');  
%    status=fseek(fid,2*N*(i-1),0)  % cof or "0"
%    dat8=fread(fid,N,'uint16=>single'); %  卫星8
%    fclose(fid)
%    guiyiDat8=(dat8-mean(dat8))/sqrt(var(dat8));
%    clear dat8
%    
%    fid=fopen('D:\pp\数据生成\tag\sv27.dat');
%    status=fseek(fid,2*N*(i-1),0)  % cof or "0"
%    dat9=fread(fid,N,'uint16=>single'); % inf: end of the file ; 卫星9
%    fclose(fid)
%    guiyiDat9=(dat9-mean(dat9))/sqrt(var(dat9));
%    clear dat9
   
   fs=6e6;       %  Jammer=sin
   fc=4.309e6;
   T=1/fs;
   N=fs*0.01;
   t=(0:N-1)*T;
   s_jam=sin(2*pi*fc*t);
   s_jam=s_jam';
   guiyiJam=(s_jam-mean(s_jam))/sqrt(var(s_jam));
   
 % 构成阵列数据
snr=-20;    % dB
jnr1=20; 
jnr2=10;
As=10^(snr/20); % 以噪声为参考,设为1
% Aj1=10^(jnr1/20);
Aj2=10^(jnr2/20);

s=[As*guiyiDat1'; 
    As*guiyiDat2'; 
    As*guiyiDat3';
    As*guiyiDat4';
    As*guiyiDat5';
    As*guiyiDat6';
    As*guiyiDat7';
%     Aj1*guiyiDat8';
%     As*guiyiDat9';
    Aj2*guiyiJam'];       %    s_jam:干扰信号,干扰为参考,系数为1
% s=[As*guiyiDat1'; Aj*guiyiJam']; 

a1=68; % DOA of wanted 卫星真实方向
a2=46;  
a3=22;
a4=42;
a5=64;
a6=41;
a7=6;
% a8=10; 
% a9=23;
a10=-20;   % DOA of interfere

M=4;    % num of antenna 
a=exp(-j*pi*[0:M-1]'*sin(a1*pi/180));  % 1
b=exp(-j*pi*[0:M-1]'*sin(a2*pi/180));  % 2 
c=exp(-j*pi*[0:M-1]'*sin(a3*pi/180));  % 3
d=exp(-j*pi*[0:M-1]'*sin(a4*pi/180));  % 4
e=exp(-j*pi*[0:M-1]'*sin(a5*pi/180));  % 5
f=exp(-j*pi*[0:M-1]'*sin(a6*pi/180));  % 6
g=exp(-j*pi*[0:M-1]'*sin(a7*pi/180));  % 7
% h=exp(-j*pi*[0:M-1]'*sin(a8*pi/180));  % 8
% k=exp(-j*pi*[0:M-1]'*sin(a9*pi/180));  % 9

doa_J=exp(-j*pi*[0:M-1]'*sin(a10*pi/180));    % 干扰

A=[a,b,c,d,e,f,g,doa_J];%%h,k,
% A=[a, doa_J];
% Nn=10^((sjr-snr)/20);  % 噪声幅度
randn('state',111);
Noise=randn(M,N)+j*randn(M,N);   % Complex noise复噪声
y=A*s;
 x=A*s + Noise;  %  M阵元的阵列数据size=(M*N)
   
   
%    clear dat1; 
%    clear dat2;
%    clear dat3;
%    clear dat4;
%    clear s_jam

      
 % write data to file, 每一个阵元的数据写入一个文件   
   fid=fopen('D:\MrealD10.dat','a');   % 列优先存!!!
   count=fwrite(fid,real(x.'),'single');       % 实部
   fclose(fid)
   
   fid=fopen('D:\MimagD10.dat','a'); 
   count=fwrite(fid,imag(x.'),'single');                     % 虚部
   fclose(fid)
    
%    save D1.mat x
     
end

toc