找回密码
 注册
搜索
查看: 793|回复: 0

[综合资料] 求助一个matlab通信仿真的问题!!

[复制链接]
发表于 2006-5-10 11:04:00 | 显示全部楼层 |阅读模式
我是仿真超宽带在AWGN单一信道中的性能,cp0201_transmitter_2PPM_TH是发射端信号,cp0801_PPMcorrmask是接收端模版信号,cp0801_Gnoise2是噪声,cp0801_PPMreceiver是接收机;
所用命令如下:
Pow=-30;fc=50e9;numbits=10000;Ts=3e-9;Tc=1e-9;Nh=3;Np=30000;Tm=0.5e-9;tau=0.25e-9;dPPM=0.5e-9;G=0;
[bits1,THcode,s_ppm1,ref1]=cp0201_transmitter_2PPM_TH;
[bits2,THcode,s_ppm2,ref2]=cp0201_transmitter_2PPM_TH;
fc=50e9;
dPPM=0.5e-9;
Ts=3e-9;
numbit=10000;
numpulses1=10000;
[mppm1]=cp0801_PPMcorrmask(ref1,fc,numpulses1,dPPM);
numpulses2=30000;
[mppm2]=cp0801_PPMcorrmask(ref2,fc,numpulses2,dPPM);
exno=[0 2 4 6 8];
[rx_ppm1,noise]=cp0801_Gnoise2(s_ppm1,exno,numpulses1);
[rx_ppm2,noise]=cp0801_Gnoise2(s_ppm2,exno,numpulses2);
[RXbits1,BER1]=cp0801_PPMreceiver(rx_ppm1,mppm1,fc,bits1,numbit,1,Ts);
[RXbits2,BER2]=cp0801_PPMreceiver(rx_ppm2,mppm2,fc,bits2,numbit,3,Ts);
每个函数如下:
function [bits,THcode,Stx,ref]=cp0201_transmitter_2PPM_TH
% ----------------------------
% Step Zero - Input Parameters
% ----------------------------
Pow = -30;       % Average transmitted power (dBm)
fc = 50e9;       % sampling frequency
numbits = 2;     % number of bits generated by the source
Ts = 3e-9;       % frame time, i.e. average pulse
                 %  repetition period
Ns = 5;          % number of pulses per bit
Tc = 1e-9;       % chip time
Nh = 3;          % cardinality of the Time Hopping code
Np = 5;          % periodicity of the Time Hopping code
Tm = 0.5e-9;     % pulse duration
tau = 0.25e-9;   % shaping factor for the pulse    
dPPM = 0.5e-9;   % time shift introduced by the PPM
G = 1;
% G=0 -> no graphical output
% G=1 -> graphical output
% ----------------------------------------
% Step One - Simulating Transmission Chain
% ----------------------------------------
% binary source
bits = cp0201_bits(numbits);
% repetition coder
repbits = cp0201_repcode(bits,Ns);
% Time Hopping code
THcode = cp0201_TH(Nh,Np);
% Pulse Position Modulation + TH
[PPMTHseq,THseq] = ...
   cp0201_2PPM_TH(repbits,fc,Tc,Ts,dPPM,THcode);
% Shaping filter
power = (10^(Pow/10))/1000;     % average transmitted power
                                %  (watt)
Ex = power * Ts;                % energy per pulse
w0 = cp0201_waveform(fc,Tm,tau);% Energy Normalized pulse
                                %  waveform
wtx = w0 .* sqrt(Ex);           % pulse waveform
Sa = conv(PPMTHseq,wtx);        % Output of the filter
                                %  (with modulation)
Sb = conv(THseq,wtx);           % Output of the filter
                                %  (without modulation)
% Output generation
L = (floor(Ts*fc))*Ns*numbits;
Stx = Sa(1:L);
ref = Sb(1:L);
% ---------------------------
% Step Two - Graphical Output
% ---------------------------
if G
   
F = figure(1);
set(F,'Position',[32 223 951 420]);
tmax = numbits*Ns*Ts;
time = linspace(0,tmax,length(Stx));
P = plot(time,Stx);
set(P,'LineWidth',[2]);
ylow=-1.5*abs(min(wtx));
yhigh=1.5*max(wtx);
axis([0 tmax ylow yhigh]);
AX=gca;
set(AX,'FontSize',12);
X=xlabel('Time ');
set(X,'FontSize',14);
Y=ylabel('Amplitude [V]');
set(Y,'FontSize',14);
for j = 1 : numbits
    tj = (j-1)*Ns*Ts;
    L1=line([tj tj],[ylow yhigh]);
    set(L1,'Color',[0 0 0],'LineStyle', ...
       '--','LineWidth',[2]);
    for k = 0 : Ns-1
        if k > 0
            tn = tj + k*Nh*Tc;
            L2=line([tn tn],[ylow yhigh]);
            set(L2,'Color',[0.5 0.5 0.5],'LineStyle', ...
               '-.','LineWidth',[2]);
        end
        for q = 1 : Nh-1
            th = tj + k*Nh*Tc + q*Tc;
            L3=line([th th],[0.8*ylow 0.8*yhigh]);
            set(L3,'Color',[0 0 0],'LineStyle', ...
               ':','LineWidth',[1]);
        end
    end
end
end % end of graphical output


function [RXbits,BER] = ...
   cp0801_PPMreceiver(R,mask,fc,bits,numbit,Ns,Ts)
% -----------------------------
% Step Zero - Receiver settings
% -----------------------------
HDSD = 1;
% HDSD = 1 --> Hard Decision Detection
% HDSD = 2 --> Soft Decision Detection
% -----------------------------------------
% Step One - Implementation of the receiver
% -----------------------------------------
% N is the number of different signals at the receiver
% input L is the number of samples representing each signal
[N,L] = size(R);
RXbits = zeros(N,numbit);
dt = 1 / fc;                        % sampling time
framesamples = floor(Ts ./ dt);     % number of samples per
                                    %  frame
bitsamples = framesamples * Ns;     % number of samples per
                                    %  bit
for n = 1 : N
   
    rx = R(n,:);
    mx = rx .* mask;
   
    if HDSD == 1 % Hard Decision Detection
        
        for nb = 1 : numbit
            mxk = mx(1+(nb-1)*bitsamples:bitsamples+...
               (nb-1)*bitsamples);
            No0 = 0;
            No1 = 0;
            
            for np = 1 : Ns
                mxkp = mxk(1+(np-1)*framesamples:...
                   framesamples+(np-1)*framesamples);
                zp = sum(mxkp.*dt);
                if zp > 0
                    No0 = No0 + 1;
                else      
                    No1 = No1 + 1;
                end
            end % for np = 1 : Ns
            
            if No0 > No1
                % the estimated bit is '0'
                RXbits(n,nb) = 0;
            else
                % the estimated bit is '0'
                RXbits(n,nb) = 1;
            end
            
        end % for nb = 1 : numbit
        
    end % end of Hard Decision Detection
   
    if HDSD == 2 % Soft Decision Detection
        
        for nb = 1 : numbit
            
            mxk = mx(1+(nb-1)*bitsamples:bitsamples+...
               (nb-1)*bitsamples);
            zb = sum(mxk.*dt);
            
            if zb > 0
                % the estimated bit is '0'
                RXbits(n,nb) = 0;
            else
                % the estimated bit is '1'
                RXbits(n,nb) = 1;
            end
            
        end % for nb = 1 : numbit
               
    end % end of Soft Decision Detection
end % for n = 1 : N
% ---------------------
% Step Two - Statistics
% ---------------------
for n = 1 : N
    WB = sum(abs(bits-RXbits(n,:)));
    BER(n) = WB / numbit; % average Bit Error Rate
end

function [mask] = cp0801_PPMcorrmask(ref,fc,numpulses,dPPM)
% ---------------------------------------------
% Step One - Evaluation of the correlation mask
% ---------------------------------------------
dt = 1 / fc;
% Energy normalization
Epulse = (sum((ref.^2).*dt))/numpulses;
ref = ref./sqrt(Epulse);
% Mask construction
PPMsamples = floor (dPPM ./ dt);
sref(1:PPMsamples)=ref(length(ref)- ...
   PPMsamples+1:length(ref));
sref(PPMsamples+1:length(ref)) = ref(1:length(ref)- ...
   PPMsamples);
mask = ref-sref;

unction [output,noise] = ...
   cp0801_Gnoise2(input,exno,numpulses)
% -------------------------------
% Step One - Introduction of AWGN
% -------------------------------
Ex = (1/numpulses)*sum(input.^2);  % measured energy per
                                   %  pulse
ExNo = 10.^(exno./10);             % Ex/No in linear units     
No = Ex ./ ExNo;                   % Unilateral spectral
                                   %  density
nstdv = sqrt(No./2);               % Standard deviation for
                                   %  the noise
for j = 1 : length(ExNo)
        
    noise(j,:) = nstdv(j) .* randn(1,length(input));
    output(j,:) = noise(j,:) + input;
   
end

我运行之后,得到cp0801_PPMcorrmask有错误:
??? Index exceeds matrix dimensions.
Error in ==> L:\MATLAB\CP0801_PPMRECEIVER.M
On line 59  ==>             mxk = mx(1+(nb-1)*bitsamples:bitsamples+...
这是怎么回事??
多谢指点!!
[此贴子已经被作者于2006-5-10 11:34:07编辑过]
高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-11-26 11:34 , Processed in 0.047002 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表