Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.80 KB | None | 0 0
  1. %% Parte 1
  2.     clear;clc;
  3.  
  4.     N = 512;
  5.     % criar variavel y
  6.     load trab03.mat;
  7.  
  8.     figure(1);
  9.     imagesc(reshape(y,N,N));
  10.     colormap(gray);
  11.     colorbar;
  12.    
  13. % (1)
  14.     simbolos = length( unique(y) )
  15.  
  16. % (1).a
  17.     % faz o array de [0:255] <=> 8bits
  18.     gama = unique(y);
  19.     % conta o nº de simbolos para um array;
  20.     % p.ex [ 22 13 ... ] conta desde os 0s ate aos 255s
  21.     size_bar = histc( y(:),gama );
  22.    
  23.     figure(2);
  24.     bar(gama,size_bar)
  25.  
  26. % (1).b = 8bits. 2^8 = 256;
  27.  
  28. % (2).a
  29.     dc_y = mean(y)
  30.     ytx = y - dc_y;
  31.     dc_ytx = mean(ytx)
  32.    
  33.     %EXEMPLO: gerar sinal Wn com potencia de 5W e media nula:
  34.         % desvio padrao
  35.         sigma = 5;
  36.         % media
  37.         m = 0;
  38.         %ruido
  39.         wn = sigma * randn(size(y))+m;
  40.        
  41.         powerwn_exp = mean(wn.^2)
  42.         powerwn_teo = sigma.^2
  43.        
  44.         powerytx = mean(ytx.^2);
  45.        
  46.         SNR = powerytx./powerwn_exp
  47.        
  48.         figure(3);
  49.         imagesc( reshape(ytx,N,N) )
  50.         colormap(gray);
  51.  
  52. % (2).b
  53.     % 0db = 1 of SNR
  54.     % 5db = 3.2 of SNR
  55.     % 10db = 10 of SNR
  56.     % 15db = 32 of SNR
  57.    
  58.     SNR = [1 3.2 10 32];
  59.    
  60.     % Wn = sigma * randn( size(y) ) + m;
  61.     % sigma = sqrt(mean(ytx.^2)./SNR)
  62.     wn = sqrt(powerytx./SNR).*randn( size(ytx) );
  63.     %valor medio ja é 0 <=> DC eliminada
  64.    
  65.     img1 = y + wn(:,1);
  66.     img2 = y + wn(:,2);
  67.     img3 = y + wn(:,3);
  68.     img4 = y + wn(:,4);
  69.    
  70.     figure(4)
  71.     colormap(gray);
  72.     subplot(2,2,1),imagesc( reshape(img1,N,N) ),title('0dB')
  73.     subplot(2,2,2),imagesc( reshape(img2,N,N) ),title('5dB')
  74.     subplot(2,2,3),imagesc( reshape(img3,N,N) ),title('10dB')
  75.     subplot(2,2,4),imagesc( reshape(img4,N,N) ),title('15dB')
  76.    
  77. % (3)
  78.     clear;clc;close all;
  79.     load trab03.mat;
  80.     N=512;
  81.    
  82.     % conversao para binario [0 1]
  83.     yb = rem( double(dec2bin(y,8)),2 );
  84.     % conversao para binario polarizado [ -1 1]
  85.     ybp = 2*yb-1;
  86.    
  87.     % potencia sinal binario polarizado == 1W
  88.     power_y = mean(ybp(:).^2)
  89.    
  90.     for dB=0:5:20
  91.         SNR = 10.^(dB./10);
  92.         sigma = sqrt(power_y./SNR);
  93.         % criar ruido
  94.         wn = sigma * randn( size(ybp) );
  95.        
  96.         y_withnoise = ybp + wn;
  97.        
  98.         % conversao de [-1 1] para [0 1]
  99.         ybp_decision = y_withnoise > 0;
  100.        
  101.         % conversao de digital para analogico
  102.         y_withnoise_analogic = ybp_decision * [128 64 32 16 8 4 2 1]';
  103.        
  104.         figure((dB./5)+1);
  105.         subplot(2,3,dB/5+1)
  106.         imagesc( reshape(y_withnoise_analogic,N,N) )
  107.         colormap(gray)
  108.     end
  109.  
  110. % (5)
  111.     clear;clc;close all;
  112.     load 'trab03.mat';
  113.    
  114.     % conversao para binario [0 1]
  115.     yb = rem( double(dec2bin(y,8)),2 );
  116.     % 7LSB e DAC
  117.     yq = yb(:,2:8)*[64 32 16 8 4 2 1]';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement