⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 turbo_sys_demo.html

📁 Turbo coding toolbox in MATLAB
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"><html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">   <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document.      -->      <title>turbo_sys_demo</title>      <meta name="generator" content="MATLAB 7.6">      <meta name="date" content="2008-11-10">      <meta name="m-file" content="turbo_sys_demo"><style>body {  background-color: white;  margin:10px;}h1 {  color: #990000;   font-size: x-large;}h2 {  color: #990000;  font-size: medium;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. */ p,h1,h2,div.content div {  max-width: 600px;  /* Hack for IE6 */  width: auto !important; width: 600px;}pre.codeinput {  background: #EEEEEE;  padding: 10px;}@media print {  pre.codeinput {word-wrap:break-word; width:100%;}} span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.codeoutput {  color: #666666;  padding: 10px;}pre.error {  color: red;}p.footer {  text-align: right;  font-size: xx-small;  font-weight: lighter;  font-style: italic;  color: gray;}  </style></head>   <body>      <div class="content"><pre class="codeinput"><span class="comment">% This script simulates the classical turbo encoding-decoding system.</span><span class="comment">% It simulates parallel concatenated convolutional codes.</span><span class="comment">% Two component rate 1/2 RSC (Recursive Systematic Convolutional) component encoders are assumed.</span><span class="comment">% First encoder is terminated with tails bits. (Info + tail) bits are scrambled and passed to</span><span class="comment">% the second encoder, while second encoder is left open without tail bits of itself.</span><span class="comment">%</span><span class="comment">% Random information bits are modulated into +1/-1, and transmitted through a AWGN channel.</span><span class="comment">% Interleavers are randomly generated for each frame.</span><span class="comment">%</span><span class="comment">% Log-MAP algorithm without quantization or approximation is used.</span><span class="comment">% By making use of ln(e^x+e^y) = max(x,y) + ln(1+e^(-abs(x-y))),</span><span class="comment">% the Log-MAP can be simplified with a look-up table for the correction function.</span><span class="comment">% If use approximation ln(e^x+e^y) = max(x,y), it becomes MAX-Log-MAP.</span><span class="comment">%</span><span class="comment">% Copyright Nov 1998, Yufei Wu</span><span class="comment">% MPRG lab, Virginia Tech.</span><span class="comment">% for academic use only</span>clear <span class="string">all</span><span class="comment">% Write display messages to a text file</span>diary <span class="string">turbo_logmap.txt</span><span class="comment">% Choose decoding algorithm</span>dec_alg = input(<span class="string">' Please enter the decoding algorithm. (0:Log-MAP, 1:SOVA)  default 0    '</span>);<span class="keyword">if</span> isempty(dec_alg)   dec_alg = 0;<span class="keyword">end</span><span class="comment">% Frame size</span>L_total = input(<span class="string">' Please enter the frame size (= info + tail, default: 400)   '</span>);<span class="keyword">if</span> isempty(L_total)   L_total = 400;	 <span class="comment">% infomation bits plus tail bits</span><span class="keyword">end</span><span class="comment">% Code generator</span>g = input(<span class="string">' Please enter code generator: ( default: g = [1 1 1; 1 0 1 ] )      '</span>);<span class="keyword">if</span> isempty(g)   g = [ 1 1 1;         1 0 1 ];<span class="keyword">end</span><span class="comment">%g = [1 1 0 1; 1 1 1 1];</span><span class="comment">%g = [1 1 1 1 1; 1 0 0 0 1];</span>[n,K] = size(g);m = K - 1;nstates = 2^m;<span class="comment">%puncture = 0, puncturing into rate 1/2;</span><span class="comment">%puncture = 1, no puncturing</span>puncture = input(<span class="string">' Please choose punctured / unpunctured (0/1): default 0     '</span>);<span class="keyword">if</span> isempty(puncture)    puncture = 0;<span class="keyword">end</span><span class="comment">% Code rate</span>rate = 1/(2+puncture);<span class="comment">% Fading amplitude; a=1 in AWGN channel</span><span class="comment">% a = 1;</span><span class="comment">% Number of iterations</span>niter = input(<span class="string">' Please enter number of iterations for each frame: default 5       '</span>);<span class="keyword">if</span> isempty(niter)   niter = 5;<span class="keyword">end</span><span class="comment">% Number of frame errors to count as a stop criterior</span>ferrlim = input(<span class="string">' Please enter number of frame errors to terminate: default 15        '</span>);<span class="keyword">if</span> isempty(ferrlim)   ferrlim = 15;<span class="keyword">end</span>EbN0db = input(<span class="string">' Please enter Eb/N0 in dB : default [2.0]    '</span>);<span class="keyword">if</span> isempty(EbN0db)   EbN0db = [2.0];<span class="keyword">end</span>fprintf(<span class="string">'\n\n----------------------------------------------------\n'</span>);<span class="keyword">if</span> dec_alg == 0   fprintf(<span class="string">' === Log-MAP decoder === \n'</span>);<span class="keyword">else</span>   fprintf(<span class="string">' === SOVA decoder === \n'</span>);<span class="keyword">end</span>fprintf(<span class="string">' Frame size = %6d\n'</span>,L_total);fprintf(<span class="string">' code generator: \n'</span>);<span class="keyword">for</span> i = 1:n    <span class="keyword">for</span> j = 1:K        fprintf( <span class="string">'%6d'</span>, g(i,j));    <span class="keyword">end</span>    fprintf(<span class="string">'\n'</span>);<span class="keyword">end</span><span class="keyword">if</span> puncture==0   fprintf(<span class="string">' Punctured, code rate = 1/2 \n'</span>);<span class="keyword">else</span>   fprintf(<span class="string">' Unpunctured, code rate = 1/3 \n'</span>);<span class="keyword">end</span>fprintf(<span class="string">' iteration number =  %6d\n'</span>, niter);fprintf(<span class="string">' terminate frame errors = %6d\n'</span>, ferrlim);fprintf(<span class="string">' Eb / N0 (dB) = '</span>);<span class="keyword">for</span> i = 1:length(EbN0db)    fprintf(<span class="string">'%10.2f'</span>,EbN0db(i));<span class="keyword">end</span>fprintf(<span class="string">'\n----------------------------------------------------\n\n'</span>);fprintf(<span class="string">'+ + + + Please be patient. Wait a while to get the result. + + + +\n'</span>);<span class="keyword">for</span> nEN = 1:length(EbN0db)   en = 10^(EbN0db(nEN)/10);      <span class="comment">% convert Eb/N0 from unit db to normal numbers</span><span class="comment">%    L_c = 4*a*en*rate; 	% reliability value of the channel</span>   sigma = 1/sqrt(2*rate*en); 	<span class="comment">% standard deviation of AWGN noise</span><span class="comment">% Clear bit error counter and frame error counter</span>   errs(nEN,1:niter) = zeros(1,niter);   nferr(nEN,1:niter) = zeros(1,niter);   nframe = 0;    <span class="comment">% clear counter of transmitted frames</span>   <span class="keyword">while</span> nferr(nEN, niter)&lt;ferrlim      h =(randn(1,1)+j*randn(1,1));      a = abs(h); L_c = 4*a*en*rate; 	<span class="comment">% reliability value of the channel</span>      nframe = nframe + 1;      x = round(rand(1, L_total-m));    <span class="comment">% info. bits</span>      [temp, alpha] = sort(rand(1,L_total));        <span class="comment">% random interleaver mapping</span>      en_output = encoderm( x, g, alpha, puncture ) ; <span class="comment">% encoder output (+1/-1)</span>      r = h*en_output+sigma*randn(1,L_total*(2+puncture)); <span class="comment">% received bits</span>      yk = demultiplex(r,alpha,puncture); <span class="comment">% demultiplex to get input for decoder 1 and 2</span><span class="comment">% Scale the received bits</span>      rec_s = 0.5*L_c*yk;<span class="comment">% Initialize extrinsic information</span>      L_e(1:L_total) = zeros(1,L_total);      <span class="keyword">for</span> iter = 1:niter<span class="comment">% Decoder one</span>         L_a(alpha) = L_e;  <span class="comment">% a priori info.</span>         <span class="keyword">if</span> dec_alg == 0            L_all = logmapo(rec_s(1,:), g, L_a, 1);  <span class="comment">% complete info.</span>         <span class="keyword">else</span>            L_all = sova0(rec_s(1,:), g, L_a, 1);  <span class="comment">% complete info.</span>         <span class="keyword">end</span>         L_e = L_all - 2*rec_s(1,1:2:2*L_total) - L_a;  <span class="comment">% extrinsic info.</span><span class="comment">% Decoder two</span>         L_a = L_e(alpha);  <span class="comment">% a priori info.</span>         <span class="keyword">if</span> dec_alg == 0            L_all = logmapo(rec_s(2,:), g, L_a, 2);  <span class="comment">% complete info.</span>         <span class="keyword">else</span>            L_all = sova0(rec_s(2,:), g, L_a, 2);  <span class="comment">% complete info.</span>         <span class="keyword">end</span>         L_e = L_all - 2*rec_s(2,1:2:2*L_total) - L_a;  <span class="comment">% extrinsic info.</span><span class="comment">% Estimate the info. bits</span>         xhat(alpha) = (sign(L_all)+1)/2;<span class="comment">% Number of bit errors in current iteration</span>         err(iter) = length(find(xhat(1:L_total-m)~=x));<span class="comment">% Count frame errors for the current iteration</span>         <span class="keyword">if</span> err(iter)&gt;0            nferr(nEN,iter) = nferr(nEN,iter)+1;         <span class="keyword">end</span>      <span class="keyword">end</span>	<span class="comment">%iter</span><span class="comment">% Total number of bit errors for all iterations</span>      errs(nEN,1:niter) = errs(nEN,1:niter) + err(1:niter);      <span class="keyword">if</span> rem(nframe,3)==0 | nferr(nEN, niter)==ferrlim<span class="comment">% Bit error rate</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -