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

📄

📁 维特比编解码
💻
字号:
%0.m
   cla;
    fig = gcf;
    set(fig, 'name',  'Convolutional Encoding and Viterbi Decoding Simulation Demonstration');
    sp = get(fig,'position');
    ss = get(0,'ScreenSize');
    fp1 = [ss(3)*0.55-sp(3)*0.55  ss(4)*.75-sp(4) sp(3)*1.32 sp(4)*1.43];
  %  if ichange == 0  & size(slideData.param,2) == 1; set(gcf,'position',fp1); end;  %?????????????????????????????/
    SNRpBit = [4.5:.5:7]; linSNRpB = 10.^(SNRpBit(:).*0.1);
    M = 4; codeRate = 1/2; constlen = 7; k = log2(M); 
    dist = [10:2:16];  numErr = [36 211 1404 11633];
    expBER = 0.5.*erfc(sqrt(linSNRpB*codeRate));
    expVitBER = vitproberrdemo(expBER,dist,numErr);
    semilogy(SNRpBit,expVitBER,'g-');  xlabel('Eb/No (dB)'); ylabel('BER');
    title('Performance for R=1/2, K=7 Conv. Code and QPSK with Hard Decision' ); grid on;
    axis([4 8 10e-7 10e-3]); legend('Union Bound',0);
   
    
    %1.m
     %   SNRpBit = [4.5:.5:7]; linSNRpB = 10.^(SNRpBit(:).*0.1);
    %M = 4; codeRate = 1/2; constlen = 7; k = log2(M); 
    %dist = [10:16];  numErr = [36  0 211 0 1404 0 11633];
   % expBER = 0.5.*erfc(sqrt(linSNRpB*codeRate));
    %expVitBER = vitproberrdemo(expBER,dist,numErr);
    %semilogy(SNRpBit,expVitBER,'g-');  xlabel('Eb/No per bit (dB)'); ylabel('BER');
    %title('Performance for R=1/2, K=7 Conv. Code and QPSK with Hard Decision' ); grid on;
    %axis([4 8 10e-7 10e-3]); legend('Union Bound',0);
  
    
    
    %2.m
    	Fd = 1; Fs = 4; N = Fs/Fd; numSymb = 100; numPlot = 20;
	SNRpBitDemo = 3; SNR = SNRpBitDemo*k;                     
	seed = [12345678 87654321];              
	rand('state', seed(1));  randn('state', seed(2));              
	msg_orig = randsrc(numSymb,1,[0:1]);                      
	stem([0:numPlot-1], msg_orig(1:numPlot),'bx');                      
	axis([ 0 numPlot -0.2 1.2]);  xlabel('Time'); ylabel('Amplitude');
    title('Binary Symbols Before Convolutional Encoding' ); 
    
    
    %3.m
    	Fd = 1; Fs = 4; N = Fs/Fd; numSymb = 100; numPlot = 20;
SNRpBitDemo = 3; SNR = SNRpBitDemo*k;                     
	seed = [654321 123456];              
	rand('state', seed(1));  randn('state', seed(2));              
	msg_orig = randsrc(numSymb,1,[0:1]);                      
	stem([0:numPlot-1], msg_orig(1:numPlot),'bx');                      
	axis([ 0 numPlot -0.2 1.2]);  xlabel('Time'); ylabel('Amplitude');
    title('Binary Symbols Before Convolutional Encoding' ); 
    
    
    %4.m
        constlen = [7]; codegen = [171 133];  tblen = 32; codeRate = 1/2;
    trel = poly2trellis(constlen, codegen);
    [msg_enc_bi] = convenc(msg_orig, trel);
	numEncPlot = numPlot ./ codeRate; tEnc = [0:numEncPlot-1] * codeRate;
	stem(tEnc, msg_enc_bi(1:length(tEnc)),'rx');
	axis([ min(tEnc) max(tEnc) -0.2 1.2]);  xlabel('Time'); ylabel('Amplitude'); 
    
    
    title('Binary Symbols After Convolutional Encoding'); 
    
    
    %5.m
    
	randn('state', seed(2));            
	msg_enc  = bi2de(reshape(msg_enc_bi, size(msg_enc_bi,2)*k,size(msg_enc_bi,1) / k)');
	grayencod = bitxor([0:M-1],floor([0:M-1]/2)); msg_gr_enc = grayencod(msg_enc+1);
	msg_tx  = dmodce(msg_gr_enc, Fd, [Fs, pi/4], 'psk', M);
	msg_rx  = awgn(msg_tx, SNR-10*log10(1/codeRate)-10*log10(N));
	numModPlot = numEncPlot * Fs ./ k; tMod = [0:numModPlot-1] ./ Fs .* k;          
	plot(tMod, real(msg_tx(1:length(tMod))),'c-',tMod, imag(msg_tx(1:length(tMod))),'m-');
	axis([ min(tMod) max(tMod) -1.5 1.5]);  xlabel('Time'); ylabel('Amplitude'); 
    title('Encoded Symbols After QPSK Baseband Modulation' ); legend('In-phase','Quadrature',0);
    
    
    
    %6.m
   	msg_enc  = bi2de(reshape(msg_enc_bi, size(msg_enc_bi,2)*k,size(msg_enc_bi,1) / k)');,
	grayencod = bitxor([0:M-1],floor([0:M-1]/2)); msg_gr_enc = grayencod(msg_enc+1);
	msg_tx  = dmodce(msg_gr_enc, Fd, [Fs, pi/4], 'psk', M);
	msg_rx  = awgn(msg_tx, SNR-10*log10(1/codeRate)-10*log10(N));
	numModPlot = numEncPlot * Fs ./ k; tMod = [0:numModPlot-1] ./ Fs .* k;          
	plot(tMod, real(msg_tx(1:length(tMod))),'c-',tMod, imag(msg_tx(1:length(tMod))),'m-');
	axis([ min(tMod) max(tMod) -1.5 1.5]);  xlabel('Time'); ylabel('Amplitude'); 
    title('Encoded Symbols After QPSK Baseband Modulation' ); legend('In-phase','Quadrature',0);
    
    
    %7.m
    msg_gr_demod = ddemodce(msg_rx, Fd, [Fs, pi/4], 'psk', M);
	[dummy graydecod] = sort(grayencod); graydecod = graydecod - 1;
	msg_demod = graydecod(msg_gr_demod+1)';
    msg_demod_bi = de2bi(msg_demod,k)' ; msg_demod_bi =  msg_demod_bi(:);
	stem(tEnc, msg_enc_bi(1:numEncPlot),'rx'); hold on;  
	stem(tEnc, msg_demod_bi(1:numEncPlot),'bo'); hold off; 
	axis([ 0 numPlot -0.2 1.2]);  xlabel('Time'); ylabel('Amplitude'); title('Demodulated Symbols' ); 
    
    
    
    %8.
    	msg_dec = vitdec(msg_demod_bi, trel, tblen, 'cont', 'hard');
	stem([0:numPlot-1], msg_orig(1:numPlot),'rx'); hold on;  
	stem([0:numPlot-1], msg_dec(1+tblen:numPlot+tblen),'bo'); hold off; 
	axis([ 0 numPlot -0.2 1.2]);  xlabel('Time'); ylabel('Amplitude');
    title('Decoded Symbols' ); 
    
    
    
    
   %9.m
   	[errorBitCod ratioBitCod] = biterr(msg_enc, msg_demod);
	[errorBitCh ratioBitCh]   = biterr(msg_orig(1:end-tblen), msg_dec(1+tblen:end));
   
    
    %10.m
       cla;
	load('vitsimresults.mat');
	semilogy(SNRpBit,expVitBER,'K-',SNRperBit, ratio,'K*-'); xlabel('Eb/No (dB)'); ylabel('BER');
    title('Performance for R=1/2, K=7 Conv. Code and QPSK with Hard Decision' ); grid on;
    axis([4 8 10e-7 10e-3]);  legend('Union Bound','Simulation Results',0);
   
    

⌨️ 快捷键说明

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