Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

%%BER

clc;clear all;close all;


N = 10^6;
rand('state',100);
randn('state',200);
ip=rand(1,N)>0.5;
s=2*ip-1;
n=1/sqrt(2)*[randn(1,N)+j*randn(1,N)];
eb_no = [-3:10];
for i =1:length(eb_no)
y = s+10^(-eb_no(i)/20)*n;
iph=real(y)>0;
nerr(i)=size(find([ip-iph]),2);
end
sim_err=nerr/N;
the_err=0.5*erfc(sqrt(10.^(eb_no/10)));
semilogy(eb_no,the_err,'b.-');
hold on
semilogy(eb_no,sim_err,'rx-');
grid on
legend('Theory','Simulation');
%x=eb/no,y=BER
%%
%DCT on image
clc;clear all;close all;
I = imread('BI.jpg');
i = rgb2gray(I);
%show original image - imshow()
j=dct2(i);
imshow(log(abs(j)),[]);
j(abs(j)<20)=0;
figure;imshow(log(abs(j)),[])
%%

%sampling and quantization


clc;clear all;close all;
I = imread('BI.jpg');
i = rgb2gray(I);
l = 6;
di = downsample(i,l);
di = transpose(di);
di = downsample(di,l);
di = transpose(di);
imshow(di);
%show image di and its histogram imhist()
k = size(i);
q=50;
for x =1:k(1)
for y =1:k(2)
ri = rem(i(x,y),q);
if(ri~=0)
i(x,y)=i(x,y)-(q-ri);
end
end
end
figure;imshow(i);
%show image i and its histogram imhist()
%%
%Hamming
clc;clear all;close all;
m=3;
[h,g,n,k]=hammgen(m);
%disp h,g,n,k
c=0:1:2^m-1;
c=dec2bin(c);
v_c=rem(c*h,2)
r=input('recieved bits: ');

trt=syndtable(h)
synd=rem(r*h',2)
synd_d=bi2de(synd,'left-msb')
cor_vect = trt(1+synd_d,:)
corrected = rem(cor_vect+r,2)
%%
%Edge Detection
clc;clear all;close all;
I = imread('BI.jpg');
i = rgb2gray(I);
e1=edge(i,'prewitt');
e2=edge(i,'sobel');
e3=edge(i,'canny');
e4=edge(i,'roberts');
%show the 4 output images

You might also like