1. MEASUREMENT OF BIT ERROR RATE AIM: To measure bit error rate using binary data using MATLAB.
PROGRAM: clc; format rat; [number,ratio,individual]=biterr([1 2;3 4],[5 7],4,'overall')
OUTPUT: Number =7 Ratio =7/16 Individual = 1 2 2 2
RESULT: Hence, bit error rate is computed using MATLAB and are observed.
2. VERIFICATION OF MINIMUM DISTANCE IN HAMMING CODE
AIM: To write a program to find the minimum distance of message bits using MATLAB. PROGRAM: m=3; n=2^m-1; k=4; msg=[0 0 0 0;0 0 0 1;0 0 1 0;0 0 1 1;0 1 0 0;0 1 0 1;0 1 1 0;0 1 1 1]; code1=encode(msg,n,k,'hamming\binary'); code2=num2str(code1); code=bin2dec(code2); number1=[ ]; for i=1:8 for j=i+1:8 [number]=biterr(code(i),code(j),7); number1=[number1 number]; end; end; minidistance=min(number1) OUTPUT: minidistance =3 RESULT: Hence the minimum distance of the given message bit is calculated using MATLAB.
3. DETERMINATION OF OUTPUT OF A CONVOLUTIONAL ENCODER
AIM: To determine the output of aconvolutional encoder using MATLAB PROGRAM:
%convolution Encoder;input=1bit output=2 with 3 memory elements,code %rate=1/2 %Function(encoded_sequence)=convenc(message) %text message message1=[1 0 1 0 1 1 1 1 0 0 0 1 1 0 1 1 0 0]; enco_mem=[0 0 0]; %#memory length=3; encoded_sequence=zeros(1,(length(message1))*2); enco_mem(1,3)=enco_mem(1,2); enco_mem(1,2)=enco_mem(1,1); enco_mem(1,1)=message1(1,1); temp=xor(enco_mem(1),enco_mem(2)); o1=xor(temp,enco_mem(3)) %generator polynomial=1 1 1; o2=xor(enco_mem(1),enco_mem(3));%generator polynomial=1 0 1; encoded_sequence(1,1)=o1; encoded_sequence(1,2)=o2; msg_len=length(message1); c=3; for i=2:msg_len enco_mem(1,3)=enco_mem(1,2); enco_mem(1,2)=enco_mem(1,1); if(i<=msg_len) enco_mem(1,1)=message1(1,i); else enco_mem(1,1)=0; end temp=xor(enco_mem(1),enco_mem(2)); o1 = xor(temp,enco_mem(3)); o2 = xor(enco_mem(1),enco_mem(3)); encoded_sequence(1,c)=o1;%generator poly=(1,1,1); c=c+1; encoded_sequence(1,c)=o2;%02 generator poly(1,0,1) c=c+1; end
OUTPUT:o1 = 1 RESULT: Hence, the output of a convolutional encoder is determined using MATLAB.
4. DETERMINATION OF OUTPUT OF A CONVOLUTIONAL DECODER AIM: To decode the message through convolution decoder using MATLAB. PROGRAM: t=poly2trellis([3],[7 5]); msg=[1 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0]; code = convenc(msg,t) tb=2; decoded=vitdec(code,t,tb,'trunc','hard') output: code = Columns 1 through 11 1 1 1 0 0 0 1 0 0 0 0
Columns 12 through 22 1 1 0 0 1 1 1 0 0 1 1
Columns 23 through 33 0 1 0 1 0 0 0 1 0 1 1
Column 34 1 decoded = Columns 1 through 11 1 0 1 0 1 1 1 0 0 0 1
Columns 12 through 17 1 0 1 1 0 0
RESULT: Hence the encoded message is decoded using convolutional decoder using MATLAB.
5. DIRECT SEQUENCE SPREAD SPECTRUM
AIM: To design &generate a direct sequence spread spectrum signal using MATLAB. PROGRAM: clc; clear; %bit sequence b=round(rand(1,20)); pattern=[]; for k=1:20 if b(1,k)== 0 sig = zeros(1,6); else sig = ones(1,6); end pattern=[pattern sig]; end plot(pattern); axis([-1 130 -0.5 1.5]); spread_signal=round(rand(1,120)); figure,plot(spread_signal); axis([-1 130 -0.5 1.5]); title('\bf\it pseudo random bit sequence'); %xoring the pattern with the spread signal hopped_sig=xor(pattern,spread_signal); %modulating the hopped signal dsss_sig=[]; t=[0:100]; fc=0.1; c1=cos(2*pi*fc*t); c2=cos(2*pi*fc*t+pi); for k=1:120 if hopped_sig(1,k)==0 dsss_sig=[dsss_sig c1]; else dsss_sig=[dsss_sig c2]; end end figure,plot([1:12120],dsss_sig); axis([-1 12220 -1.5 1.5]); title('\bf\it dsss signal');
%plotting the fft of dsss signal figure,plot([1:12120],abs(fft(dsss_sig))); title('\bf\it fft of dsss signal');
OUTPUT:
ps eudo random bit s eque nce 1.5
0.5
-0.5
2 0
40
60
80
100
120
ds s ss ignal 1.5
0.5
-0.5
-1
-1.5 0
2000
4000
6000
8000
10000
12000
fft of ds s ss ignal 1000 900 800 700 600 500 400 300 200 100 0 0
2000
4000
6000
8000
10000
12000
14000
RESULT: Hence, design &generate a direct sequence spread spectrum signal using MATLAB.
7
6. FREQUENCY HOPPED SPREAD SPECTRUM
AIM: To design and generate a frequency hopped spread spectrum signal using MATLAB. PROGRAM: clc; clear; %generation of bit pattern s=round(rand(1,20)); signal=[]; carrier=[]; t=[0:10000]; fc=0.01; for k=1:20 if s(1,k)==0 sig= -ones(1,10001); else sig=ones(1,10001); end c=cos(2*pi*fc*t); carrier=[carrier c]; signal=[signal sig]; end figure(1); subplot(2,1,1); plot(signal); axis([-1 200050 -1.5 1.5]); title('\bf\it original bit sequence'); %FFT figure(2); plot([1:200020],abs(fft(signal))); title('\bf\it FFT of Bpsk Modulated Signal'); % 6 carrier freq fc1=0.01; fc2=0.02; fc3=0.03; fc4=0.04; fc5=0.05; fc6=0.06; c1=cos(2*pi*fc1*t); c2=cos(2*pi*fc2*t);
8
c3=cos(2*pi*fc3*t); c4=cos(2*pi*fc4*t); c5=cos(2*pi*fc5*t); c6=cos(2*pi*fc6*t); %rand freq hops spread_siganl=[]; for n=1:20 c=randint(1,1,[1 6]); switch(c) case(1) spread_siganl=[spread_siganl c1]; case(2) spread_siganl=[spread_siganl c2]; case(3) spread_siganl=[spread_siganl c3]; case(4) spread_siganl=[spread_siganl c4]; case(5) spread_siganl=[spread_siganl c5]; case(6) spread_siganl=[spread_siganl c6]; end end figure(3); plot([1:200020],abs(fft(spread_siganl))); title('\bf\it FFT of Spread Signal'); freq_hopped_sig=signal.*(spread_siganl); figure(4); plot([1:200020],abs(fft(freq_hopped_sig))); title('\bf\it FFT of frequency hopped Signal');
OUTPUT:
o r i g i n a lb i ts e q u e n c e 1
1 0 0 . 2 0 . 4 0 . 6 0 . 8 1 1 . 2 1 . 4 1 . 6 1 . 8 2 x1 0
5
8 7 6 5 4 3 2 1
x 10
FFT of Bps k Modulated Signal
0 0
0.5
1.5
2.5 x 10
5
10
x 10
FFT of Spread Signal
2.5
1.5
0.5
0 0
0.5
1.5
2.5 x 10
5
2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2
x 10
FFT of frequency hopped Signal
0 0
0.5
1.5
2.5 x 10
5
RESULT: Hence, designed & generated a frequency hopped spread spectrum using MATLAB.
11
7.VERIFICATION OF VARIOUS TRANSFORMS
AIM: i) To Compute the DCT for an image Using MATLAB. ii) To Compute the IDCT for an image Using MATLAB.
PROGRAM: RGB=imread('autumn.tif'); I=rgb2gray(RGB); J=dct2(I); J(abs(J)<10)=0; K=idct2(J); subplot(2,2,1);imshow(RGB),title('original colour image'); subplot(2,2,2);imshow(I),title('Gray Scale image'); subplot(2,2,3);imshow(log(abs(J))),title('DCT'); subplot(2,2,4);imshow(K,[0,255]),title('IDCT');
12
OUTPUT:
o rig ina l c olo ur im a ge
G ray S c a le im a ge
DCT
ID C T
RESULT: Hence, Computed the DCT of the autumn image its color and gray scale image are obtained. The IDCT of the image obtained is same as the original image computed by DCT.
13
AIM: i) To Compute the FT & IFT of a given image Using MATLAB.
PROGRAM: RGB=imread('peppers.png'); I=rgb2gray(RGB); J=fft2(I); K=ifft2(J); subplot(2,2,1);imshow(RGB),title('original colour image'); subplot(2,2,2);imshow(I),title('Gray Scale image'); subplot(2,2,3);imshow(J),title('DFT'); subplot(2,2,4);imshow(K,[0 255]),title('IDFT');
14
OUTPUT:
original c olour im age G ray S c ale im age
DFT
ID F T
RESULT: Hence, Computed the FT & IFT of the given image using MATLAB.
15
8. POINT, LINE AND EDGE DETECTION
AIM: To write a program to detect point, line and edge detection using derivative operation using MATLAB. PROGRAM: A) Point detection I=imread('circuit.tif'); H= [1 1 1; 1 -8 1; 1 1 1]; B=imfilter(I,H); subplot (1, 2, 1), imshow (I), title ('original image'); subplot (1, 2, 2), imshow (B), title ('point detection'); B) Line detection I=imread('circuit.tif'); H1= [-1 -1 -1; 2 2 2;-1 -1 -1]; H2= [-1 2 -1;-1 2 -1;-1 2 -1]; B1=imfilter(I,H1) B2=imfilter(I,H2) subplot (2, 2, 1),imshow(I) subplot (2, 2, 2),imshow(B1) subplot (2, 2, 3),imshow(B2) C) Edge detection I=imread('circuit.tif'); BW1=edge (I,'prewitt'); BW2=edge (I,'canny'); BW3=edge (I,'sobel'); subplot (2, 2, 1),imshow(BW1); xlabel('using prewitt method'); subplot (2, 2, 2),imshow(BW2); xlabel('using canny method'); subplot (2, 2, [3:4]),imshow(BW3); xlabel('using sobel method');
16
OUTPUT: a) Point detection
original image
point detection
17
b) Line detection
18
c) Edge Detection
us ing prewitt m ethod
us ing c anny m ethod
us ing s obel m ethod
RESULT: Hence point, line, & edge detection of an image is done successfully using MATLAB.
19
9. IMPLEMENTATION OF FIR FILTER
AIM: To write a program to design FIR filter using MATLAB. PROGRAM:
n=10; fp=200; fq=300; fs=1000; fn=2*fp/fs; window=triang(n+1); b=fir1(n,fn,window); [n,w]=freqz(b,1,128); subplot(2,1,1); plot(w/pi,abs(n)); title('Magnitude response of LPF'); ylabel('gain in db---->'); xlabel('normalized frequency---->'); subplot(2,1,2); plot(w/pi,angle(n)); title('Phase response of LPF'); ylabel('Angle---->'); xlabel('normalized frequency---->');
20
OUTPUT:
Magnitude response of LPF 1.5 gain in db---->
0.5
0.1
0.2
0.3
0.4 0.5 0.6 0.7 normalized frequency----> Phase response of LPF
0.8
0.9
4 2 Angle----> 0 -2 -4
0.1
0.2
0.3
0.4 0.5 0.6 0.7 normalized frequency---->
0.8
0.9
RESULT: Hence, the FIR filter is designed using MATLAB.
21
10. IMPLEMENTATION OF IIR FILTER
AIM: To design the IIR filter using MATLAB.
PROGARM:
wp=input('Enter passband cut-off frequency'); ws=input('Enter stopband cut-off frequency'); rp=input('Enter passband ripple in db'); rs=input('Enter stopband ripple in db'); fs=input('Enter the sampling frequency'); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs,'s'); [b,a]=butter(n,wn,'s'); w=0:0.01:pi; [n,omega]=freqs(b,a,w); gain=20*log10(abs(n)); an=angle(n); subplot(2,1,1); title('mag.response of LPF'); plot(omega/pi,gain); xlabel('normalised frequency---->'); ylabel('Gain in db'); subplot(2,1,2); title('phase response of LPF');
22
plot(omega/pi,an); xlabel('Normalised frequency---->');
ylabel('phase in radians');
OUTPUT :Enter passband cut-off frequency 1500 Enter stopband cut-off frequency 3000 Enter passband ripple in db 10 Enter stopband ripple in db 40 Enter the sampling frequency 7000
OUTPUT:
Gain in db
-50
-100
-150
0.1
0.2
0.3
0.4 0.5 0.6 0.7 normalised frequency---->
0.8
0.9
4 phase in radians 2 0 -2 -4
0.1
0.2
0.3
0.4 0.5 0.6 0.7 Normalised frequency---->
0.8
0.9
23
RESULT: Hence, the FIR filter is designed using MATLAB.
24