Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Parte 1
- clear;clc;
- N = 512;
- % criar variavel y
- load trab03.mat;
- figure(1);
- imagesc(reshape(y,N,N));
- colormap(gray);
- colorbar;
- % (1)
- simbolos = length( unique(y) )
- % (1).a
- % faz o array de [0:255] <=> 8bits
- gama = unique(y);
- % conta o nº de simbolos para um array;
- % p.ex [ 22 13 ... ] conta desde os 0s ate aos 255s
- size_bar = histc( y(:),gama );
- figure(2);
- bar(gama,size_bar)
- % (1).b = 8bits. 2^8 = 256;
- % (2).a
- dc_y = mean(y)
- ytx = y - dc_y;
- dc_ytx = mean(ytx)
- %EXEMPLO: gerar sinal Wn com potencia de 5W e media nula:
- % desvio padrao
- sigma = 5;
- % media
- m = 0;
- %ruido
- wn = sigma * randn(size(y))+m;
- powerwn_exp = mean(wn.^2)
- powerwn_teo = sigma.^2
- powerytx = mean(ytx.^2);
- SNR = powerytx./powerwn_exp
- figure(3);
- imagesc( reshape(ytx,N,N) )
- colormap(gray);
- % (2).b
- % 0db = 1 of SNR
- % 5db = 3.2 of SNR
- % 10db = 10 of SNR
- % 15db = 32 of SNR
- SNR = [1 3.2 10 32];
- % Wn = sigma * randn( size(y) ) + m;
- % sigma = sqrt(mean(ytx.^2)./SNR)
- wn = sqrt(powerytx./SNR).*randn( size(ytx) );
- %valor medio ja é 0 <=> DC eliminada
- img1 = y + wn(:,1);
- img2 = y + wn(:,2);
- img3 = y + wn(:,3);
- img4 = y + wn(:,4);
- figure(4)
- colormap(gray);
- subplot(2,2,1),imagesc( reshape(img1,N,N) ),title('0dB')
- subplot(2,2,2),imagesc( reshape(img2,N,N) ),title('5dB')
- subplot(2,2,3),imagesc( reshape(img3,N,N) ),title('10dB')
- subplot(2,2,4),imagesc( reshape(img4,N,N) ),title('15dB')
- % (3)
- clear;clc;close all;
- load trab03.mat;
- N=512;
- % conversao para binario [0 1]
- yb = rem( double(dec2bin(y,8)),2 );
- % conversao para binario polarizado [ -1 1]
- ybp = 2*yb-1;
- % potencia sinal binario polarizado == 1W
- power_y = mean(ybp(:).^2)
- for dB=0:5:20
- SNR = 10.^(dB./10);
- sigma = sqrt(power_y./SNR);
- % criar ruido
- wn = sigma * randn( size(ybp) );
- y_withnoise = ybp + wn;
- % conversao de [-1 1] para [0 1]
- ybp_decision = y_withnoise > 0;
- % conversao de digital para analogico
- y_withnoise_analogic = ybp_decision * [128 64 32 16 8 4 2 1]';
- figure((dB./5)+1);
- subplot(2,3,dB/5+1)
- imagesc( reshape(y_withnoise_analogic,N,N) )
- colormap(gray)
- end
- % (5)
- clear;clc;close all;
- load 'trab03.mat';
- % conversao para binario [0 1]
- yb = rem( double(dec2bin(y,8)),2 );
- % 7LSB e DAC
- yq = yb(:,2:8)*[64 32 16 8 4 2 1]';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement