声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1068|回复: 0

[编程技巧] 帮帮忙啊,有谁能帮我看看程序啊

[复制链接]
发表于 2009-5-19 17:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
%matrixH
%m = [1  1];   % row indices of 1s
%n = [1  2];   % 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;
for  k=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))]);

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

end
semilogy(SNR,err,'b*-')
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-11 19:26 , Processed in 0.056385 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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