小小笨笨5 发表于 2009-5-19 17:43

帮帮忙啊,有谁能帮我看看程序啊

%matrixH
%m = ;   % row indices of 1s
%n = ;   % column indices of 1s
%H=sparse(10000,20000);
%h(row_m,col_n)=1;
%h=sparse(row_m,col_n,ones(length(row_m),1)); % parity-check matrix H
%l = fec.ldpcdec(H);
clear
clc
H=dvbs2ldpc(2/3);
enc = fec.ldpcenc(H);% Construct a LDPC encoder object

% Construct a companion LDPC decoder object
dec = fec.ldpcdec(H);
dec.DecisionType = 'Hard decision';
dec.OutputFormat = 'Information part';
dec.NumIterations = 50;         
% Stop if all parity-checks are satisfied
dec.DoParityChecks = 'Yes';
randn('state',123456);
idx=1;
err_idx=1;
SNR=5;
for SNRdB=SNR
    SNRdB
    idx=1;
fork=1:10
% Generate and encode a random binary message
msg = randint(enc.NumInfoBits,1,2);
codeword = encode(enc,msg');

% Construct a BPSK modulator object
modObj = modem.pskmod('M',2,'PhaseOffset',0,'InputType','Bit');

% Modulate the signal (map bit 0 to 1 + 0i, bit 1 to -1 + 0i)
modulatedsig = modulate(modObj, codeword');

% Noise parameters
%SNRdB = 1;
sigma = sqrt(10^(-SNRdB/10));


    %h0_re=(sqrt(2)/2)*randn(length(modulatedsig),1);%normrnd(0,sqrt(2)/2,length(modulatedsig),1);
    %h0_im=(sqrt(2)/2)*randn(length(modulatedsig),1);%normrnd(0,sqrt(2)/2,length(modulatedsig),1);
    %h0=h0_re+h0_im*j;
   
    w_re=sigma*randn(length(modulatedsig),1);
    w_im=sigma*randn(length(modulatedsig),1);
    w=w_re+j*w_im;


% Transmit signal through AWGN channel
receivedsig = modulatedsig+w;%awgn(modulatedsig.*h0, SNRdB, 0); % Signal power = 0 dBW



% Construct a BPSK demodulator object to compute
% log-likelihood ratios
demodObj = modem.pskdemod(modObj,'DecisionType','LLR', ...
   'NoiseVariance',sigma^2);

% Compute log-likelihood ratios (AWGN channel)
llr = demodulate(demodObj, receivedsig);

% Decode received signal
decodedmsg = decode(dec, (llr<0)');
%decodedmsg=(decodedmsg<0)*1;
% Actual number of iterations executed
disp(['Number of iterations executed = ' ...
   num2str(dec.ActualNumIterations)]);
% Number of parity-checks violated
disp(['Number of parity-checks violated = ' ...
   num2str(sum(dec.FinalParityChecks))]);
% Compare with original message
disp(['Number of bits incorrectly decoded = ' ...
   num2str(nnz(decodedmsg'-msg))]);

=symerr(decodedmsg',msg);
idx=idx+1;
end
err(err_idx)=sum(rate)/k;
err_idx=err_idx+1;

end
semilogy(SNR,err,'b*-')
页: [1]
查看完整版本: 帮帮忙啊,有谁能帮我看看程序啊