ADVANCED DIGITAL SIGNAL PROCESSING Lab Manual

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-1
DISCRETE FOURIER TRANSFORM

AIM:
To verify the Discrete Fourier Transform and its properties by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.Discrete Fourier Transform:

clc;
clear all;
close all;
x=[0 -1 2 -3];
N=length(x);
for k=0:1:(N-1)
sum=0;
for n=0:1:(N-1)
sum=sum+x(n+1)*exp(-(j*2*pi*n*(k+N))/N);
end;
M(k+1)=sum;
end;
k=0:1:(N-1)
subplot(1,2,1);
stem(k,abs(M));
title('magnitude spectrum');
xlabel('fork');
ylabel('amplitude');
subplot(1,2,2);
stem(k,angle(M));
title('phase spectrum');
xlabel('fork');
ylabel('phase');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

PROPERTIES OF DFT:

2.Linearity:

clc;
clear all;
close all;
x1=[0 1 2 3];
x2=[0 1 2 3];
m=2*x1+3*x2;
P=length(x1);
Q=length(x2);
R=length(m);
for k=0:1:P-1
sum1=0;
for n=0:1:(P-1)
sum1=sum1+x1(n+1)*exp(-(j*2*pi*n*k)/P);
end;
X1(k+1)=sum1;
end;
for k=0:1:Q-1
sum2=0;
for n=0:1:(Q-1)
sum2=sum2+x2(n+1)*exp(-(j*2*pi*n*k)/Q);
end;
X2(k+1)=sum2;
end;
for k=0:1:R-1
sum3=0;
for n=0:1:(R-1)
sum3=sum3+m(n+1)*exp(-(j*2*pi*n*k)/R);
end;
M(k+1)=sum3;
end;k=0:1:(P-1)
subplot(3,2,1);
stem(k,abs(X1));
title('magnitude spectrum for X1');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,2);
stem(k,angle(X1));
title('phase spectrum for X1');
xlabel('--> k');
ylabel('-->phase');
k=0:1:(Q-1)
subplot(3,2,3);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

stem(k,abs(X2));
title('magnitude spectrum for X2');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,4);
stem(k,angle(X2));
title('phase spectrum for X2');
xlabel('--> k');
ylabel('-->phase');
k=0:1:(R-1)
subplot(3,2,5);
stem(k,abs(M));
title('magnitude spectrum for M');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,6);
stem(k,angle(M));
title('phase spectrum for M');
xlabel('--> k');
ylabel('-->phase');

3.Periodicity:

clc;
clear all;
close all;
x=[0 1 2 3];
N=length(x);
for k=0:1:3*(N-1)
sum=0;
for n=0:1:(N-1)
sum=sum+x(n+1)*exp(-(j*2*pi*n*(k+N))/N);
end;
M(k+1)=sum;
end;
k=0:1:3*(N-1)
subplot(1,2,1);
stem(k,abs(M));
title('magnitude spectrum');
xlabel('fork');
ylabel('amplitude');
subplot(1,2,2);
stem(k,angle(M));
title('phase spectrum');
xlabel('fork');
ylabel('phase');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

4.Circular Convolution:

clc;
clear all;
close all;
x1=[0 1 2 3];
x2=[0 1 2 3];
m=cconv(x1,x2,4);
P=length(x1);
Q=length(x2);
R=length(m);
for k=0:1:P-1
sum1=0;
for n=0:1:(P-1)
sum1=sum1+x1(n+1)*exp(-(j*2*pi*n*k)/P);
end;
X1(k+1)=sum1;
end;
for k=0:1:Q-1
sum2=0;
for n=0:1:(Q-1)
sum2=sum2+x2(n+1)*exp(-(j*2*pi*n*k)/Q);
end;
X2(k+1)=sum2;
end;
for k=0:1:R-1
sum3=0;
for n=0:1:(R-1)
sum3=sum3+m(n+1)*exp(-(j*2*pi*n*k)/R);
end;
M(k+1)=sum3;
end;
k=0:1:(P-1)
subplot(3,2,1);
stem(k,abs(X1));
title('magnitude spectrum for X1');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,2);
stem(k,angle(X1));
title('phase spectrum for X1');
xlabel('--> k');
ylabel('-->phase');
k=0:1:(Q-1)
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

subplot(3,2,3);
stem(k,abs(X2));
title('magnitude spectrum for X2');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,4);
stem(k,angle(X2));
title('phase spectrum for X2');
xlabel('--> k');
ylabel('-->phase');
k=0:1:(R-1)
subplot(3,2,5);
stem(k,abs(M));
title('magnitude spectrum for M');
xlabel('--> k');
ylabel('-->amplitude');
subplot(3,2,6);
stem(k,angle(M));
title('phase spectrum for M');
xlabel('--> k');
ylabel('-->phase');

SIMULATION RESULTS

DFT:

MAGNITUDE SPECTRUM OF DFT PHASE SPECTRUM OF DFT


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

LINEARITY:

PERIODICITY:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

CIRCULAR CONVOLUTION:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-2

FIR FILTER DESIGN

AIM:
To design a FIR filter without using built in functions by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.FIR LPF filter design:

clc;
close all;
clear all;
N=5;
wc=pi/6;
for n=-(N-1)/2:(N-1)/2
hd(n+1+(N-1)/2)=(1/(pi*(n+0.0001))*sin(wc*(n+0.0001)));
end;
w=0.5-0.5*cos(2*pi*n/(N-1));
h=hd.*w';
b=h;
a=[1];
[H w1]=freqz(b,a);
subplot(1,2,1);
plot(w1,abs(H));
title('magnitude spectrum for LPF');
xlabel('--> w1');
ylabel('-->amplitude');
subplot(1,2,2);
plot(w1,angle(H));
title('phase spectrum for LPF');
xlabel('--> w1');
ylabel('-->phase');

2.FIR HPF filter design:

clc;
close all;
clear all;
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

N=5;
wc=pi/6;
for n=-(N-1)/2:(N-1)/2
hd(n+1+((N-1)/2))=(1/(pi*(n+0.0001)))*(sin(pi*(n+0.0001))-sin(wc*(n+0.0001)));
end;
w=hamming(N);
hf=hd.*w';
b=hf;
a=[1];
[H w1]=freqz(b,a);
subplot(1,2,1);
plot(w1,abs(H));
title('magnitude spectrum for HPF');
xlabel('--> w1');
ylabel('-->amplitude');
subplot(1,2,2);
plot(w1,angle(H));
title('phase spectrum for HPF');
xlabel('--> w1');
ylabel('-->phase');

SIMULATION RESULTS

LOW PASS FILTER:


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

HIGH PASS FILTER:


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-3

IIR FILTER DESIGN

AIM:
To design a IIR filter without using built in functions by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.IIR LPF Butterworth filter design:

clc;
close all;
clear all;
wp=input('enter pass band edge frequency=');
ws=input('enter stop band edge frequency=');
ap=input('enter pass band attenuation=');
as=input('enter stop band attenuation=');
Ap=20*log10(ap);
As=20*log10(as);
Wp=2*tan(wp/2);
Ws=2*tan(ws/2);
k1=log10(((10^(-0.1*Ap))-1)/((10^(-0.1*As))-1));
k2=2*log10(Wp/Ws);
N=(k1/k2);
N=round(N);
N=N+1;
for l=1:1:2*N
s(l)=exp((j*((2*l)-1)*pi)/(2*N));
end;
c=1;
for l=1:1:2*N
if s(l)<0
p(c)=s(l);
c=c+1;
end;
end;
wc=0.743;
p=p*wc;
z=[];
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

[b a]=zp2tf(z,p,(wc^2));
dk=((wc)^2/((2-p(1))*(2-p(2))));
dz=[-1 -1];
dp=[((2+p(1))/(2-p(1))) ((2+p(2))/(2-p(2)))];
dzc=dz';
dpc=dp';
[bz az]=zp2tf(dzc,dpc,dk);
freqz(bz,az);

SIMULATION RESULTS

Magnitude response for Butterworth LPF Filter:

Phase response for Butterworth LPF Filter:


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-4

VERIFICATION OF VARIOUS TRANSFORMS (FT/DCT) ON A GIVEN IMAGE

A) AIM:
To verify Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform
(IDFT) on a given image by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.DFT of a 2*2 Matrix: (Without using built in functions)

clc;
close all;
clear all;
f=[1 2;3 4];
[M N]=size(f);
for u=0:M-1
for v=0:N-1
sum=0;
for x=0:M-1
for y=0:N-1
k1=exp((-j*2*pi*u*(x))/M);
k2=exp((-j*2*pi*v*(y))/N);
sum=sum+((1/(N))*(f(x+1,y+1)*k1*k2));
end;
end;
Z(u+1,v+1)=sum;
end;
end;

2.IDFT of a 2*2 Matrix: (Without using built in functions)

clc;
close all;
clear all;
f=[5 -1;-2 0];
[M N]=size(f);
for u=0:M-1
for v=0:N-1
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

sum=0;
for x=0:M-1
for y=0:N-1
k1=exp((j*2*pi*u*(x))/M);
k2=exp((j*2*pi*v*(y))/N);
sum=sum+((1/(N))*(f(x+1,y+1)*k1*k2));
end;
end;
Z(u+1,v+1)=sum;
end;
end;

3.DFTand IDFT on a Image: (Without using built in functions)

clc;
close all;
clear all;
f=imread('cameraman.tif');
f1=imresize(f,0.125);
[M N]=size(f1);
f2=im2double(f1);
subplot(1,2,1);
imshow(f2);
title('cameraman');
for u=0:M-1
for v=0:N-1
sum=0;
for x=0:M-1
for y=0:N-1
k1=exp((-j*2*pi*u*(x))/M);
k2=exp((-j*2*pi*v*(y))/N);
sum=sum+(f2(x+1,y+1)*k1*k2);
end;
end;
Z(u+1,v+1)=sum;
end;
end;
subplot(1,2,2);
imshow(Z);
title('dft image');
for u=0:M-1
for v=0:N-1
sum=0;
for x=0:M-1
for y=0:N-1
k1=exp((j*2*pi*u*(x))/M);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

k2=exp((j*2*pi*v*(y))/N);
sum=sum+((1/(N*N))*(Z(x+1,y+1)*k1*k2));
end;
end;
w(u+1,v+1)=sum;
end;
end;
figure,imshow(w);
title('idft image');

4.DFTand IDFT on a Image: (With using built in functions)

clc;
close all;
clear all;
f=imread('cameraman.tif');
[M N]=size(f);
imshow(f);
title('cameraman');
k=fft2(f);
k=fft2(f,M,N);
figure,imshow(k);
title('dft image');
imwrite(k,'dftimage.tif');
q=imread('dftimage.tif');
p=ifft2(q);
p=ifft2(q,M,N);
figure,imshow(q);
title('idft image');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

SIMULATION RESULTS
Input image:

DFT image:

IDFT image:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

B) AIM:
To verify Discrete Cosine Transform (DCT) and Inverse Discrete Cosine Transform
(IDCT) on a given image by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.DCT of a 2*2 Matrix: (Without using built in functions)

clc;
close all;
clear all;
f=[1 2;3 4];
[M N]=size(f);
for u=0:M-1
for v=0:N-1
if (u==0)
alphau=sqrt(1/M);
else
alphau=sqrt(2/M);
end;
if (v==0)
alphav=sqrt(1/N);
else
alphav=sqrt(2/N);
end;
sum=0;
for x=0:M-1
for y=0:N-1
k1=cos((pi*((2*x)+1)*u)/(2*M));
k2=cos((pi*((2*y)+1)*v)/(2*N));
sum=sum+(f(x+1,y+1)*k1*k2);
end;
end;
Z(u+1,v+1)=alphau*alphav*sum;
end;
end;

2.IDCT of a 2*2 Matrix: (Without using built in functions)

clc;
close all;
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

clear all;
f=[5 -1;-2 0];
[M N]=size(f);
for u=0:M-1
for v=0:N-1
if (u==0)
alphau=sqrt(1/M);
else
alphau=sqrt(2/M);
end;
if (v==0)
alphav=sqrt(1/N);
else
alphav=sqrt(2/N);
end;
sum=0;
for x=0:M-1
for y=0:N-1
k1=cos((pi*((2*x)+1)*u)/(2*M));
k2=cos((pi*((2*y)+1)*v)/(2*N));
sum=sum+(f(x+1,y+1)*k1*k2);
end;
end;
Z(u+1,v+1)=alphau*alphav*sum;
end;
end;

3.DCTand IDCT of an Image: (Without using built in functions)

clc;
close all;
clear all;
f=imread('cameraman.tif');
f1=imresize(f,0.125);
[M N]=size(f1);
subplot(1,2,1);
imshow(f1);
title('cameraman');
for u=0:M-1
for v=0:N-1
if (u==0)
alphau=sqrt(1/M);
else
alphau=sqrt(2/M);
end;
if (v==0)
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

alphav=sqrt(1/N);
else
alphav=sqrt(2/N);
end;
sum=0;
for x=0:M-1
for y=0:N-1
k1=cos((pi*((2*x)+1)*u)/(2*M));
k2=cos((pi*((2*y)+1)*v)/(2*N));
sum=sum+(f1(x+1,y+1)*k1*k2);
end;
end;
Z(u+1,v+1)=alphau*alphav*sum;
end;
end;
subplot(1,2,2);
imshow(Z);
title('dctimage');
imwrite(Z,'dctimage.tif');
for u=0:M-1
for v=0:N-1
if (u==0)
alphau=sqrt(1/M);
else
alphau=sqrt(2/M);
end;
if (v==0)
alphav=sqrt(1/N);
else
alphav=sqrt(2/N);
end;
sum=0;
for x=0:M-1
for y=0:N-1
k1=cos((pi*((2*x)+1)*u)/(2*M));
k2=cos((pi*((2*y)+1)*v)/(2*N));
sum=sum+(Z(x+1,y+1)*k1*k2);
end;
end;
w(u+1,v+1)=alphau*alphav*sum;
end;
end;
figure,imshow(w);
title('idctimage');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

4.DCTand IDCT of an Image:(With using built in functions)

clc;
close all;
clear all;
f=imread('cameraman.tif');
[M N]=size(f);
imshow(f);
title('cameramani');
k=dct2(f);
k=dct2(f,M,N);
figure,imshow(k);
title('dct image');
imwrite(k,'dctimage.tif');
q=imread('dctimage.tif');
p=idct2(q);
p=idct2(q,M,N);
figure,imshow(q);
title('cameramano');

SIMULATION RESULTS

Input image:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

DCT image:

IDCT image:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-5
POINT ,LINE AND EDGE DETECTION BY USING DERIVATIVE OPERATORS

AIM:
To detect point, line, and edges by using derivative operators in an image by using
MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1. Applying Mask on an Image:

clc;
close all;
clear all;
f=imread('cameraman.tif');
[x y]=size(f);
imshow(f);
w=[1 2 3;4 5 6;7 8 9];
[k l]=size(w);
for x=2:4
for y=2:4
sum=0;
for k=1:3
for l=1:3
sum=sum+(f(x+k-2,y+l-2)*(w(k,l)));
end;
end;
z(x-1,y-1)=sum;
end;
end;
figure,imshow(z);

2. Point Detection:

clc;
close all;
clear all;
f=imread('moon.tif');
subplot(1,2,1);
imshow(f);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

title('original image 14481D3807');


w=[-1 -1 -1;-1 8 -1;-1 -1 -1];
fp=imfilter(f,w);
subplot(1,2,2);
imshow(fp);
title('point edge mask 14481D3807');

3. Line Detection:

clc;
close all;
clear all;
f=imread('moon.tif');
subplot(2,3,1);
imshow(f);
title('original image 14481D3807');
w1=[-1 -1 -1;2 2 2;-1 -1 -1];
f1=imfilter(f,w1);
subplot(2,3,2);
imshow(f1);
title('horizantal filter 14481D3807');
w2=[-1 2 -1;-1 2 -1;-1 2 -1];
f2=imfilter(f,w2);
subplot(2,3,3);
imshow(f2);
title('vertical filter 14481D3807');
w3=[-1 -1 2;-1 2 -1;2 -1 -1];
f3=imfilter(f,w3);
subplot(2,3,4);
imshow(f3);
title('diogonal+45 filter 14481D3807');
w4=[2 -1 -1;-1 2 -1;-1 -1 2];
f4=imfilter(f,w4);
subplot(2,3,5);
imshow(f4);
title('diogonal-45 filter 14481D3807');

4. Edge Detection: (Without using built in functions)

clc;
close all;
clear all;
f=imread('cameraman.tif');
subplot(3,3,1);
imshow(f);
title('original image');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

w1=[-1 -1 -1;0 0 0;1 1 1];


f1=imfilter(f,w1);
subplot(3,3,2);
imshow(f1);
title('prewitt right filter');
w2=[-1 0 1;-1 0 1;-1 0 1];
f2=imfilter(f,w2);
subplot(3,3,3);
imshow(f2);
title('prewitt left filter');
w3=[-1 -2 -1;0 0 0;1 2 1];
f3=imfilter(f,w3);
subplot(3,3,4);
imshow(f3);
title('sobel right filter');
w4=[-1 0 -1;-2 0 2;-1 0 1];
f4=imfilter(f,w4);
subplot(3,3,5);
imshow(f4);
title('sobel left filter');
w5=[-1 0;0 1];
f5=imfilter(f,w5);
subplot(3,3,6);
imshow(f5);
title('roberts right filter');
w6=[0 -1;1 0];
f6=imfilter(f,w6);
subplot(3,3,7);
imshow(f6);
title('roberts left filter');

5. Edge Detection: (By using built in functions)

clc;
close all;
clear all;
f=imread('moon.tif');
subplot(2,2,1);
imshow(f);
title('original image 14481D3807');
f1=edge(f,'prewitt');
subplot(2,2,2);
imshow(f1);
title('prewitt mask 14481D3807');
f2=edge(f,'sobel');
subplot(2,2,3);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

imshow(f1);
title('sobel mask 14481D3807');
f3=edge(f,'roberts');
subplot(2,2,4);
imshow(f1);
title('roberts mask 14481D3807');

6. Point ,Line and Edge Detection: (By using built in functions)

clc;
close all;
clear all;
f=imread('moon.tif');
subplot(2,2,1);
imshow(f);
title('original image 14481D3807');
w1=[-1 -1 -1;-1 8 -1;-1 -1 -1];
fpoint=imfilter(f,w1);
subplot(2,2,2);
imshow(fpoint);
title('point mask 14481D3807');
w2=[-1 -1 -1;2 2 2;-1 -1 -1];
fline=imfilter(f,w2);
subplot(2,2,3);
imshow(fline);
title('line mask 14481D3807');

fedge=edge(f,'prewitt');
subplot(2,2,4);
imshow(fedge);
title('edge mask 14481D3807');
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

SIMULATION RESULTS

Point detection:

Line Detection:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

Edge Detection:
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-6
MEASUREMENT OF BIT ERROR RATE BY USING BINARY DATA

AIM:
To measure Bit Error Rate in Binary data by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1. Bit Error Rate:

clc;
close all;
clear all;
a=rand(1,8);
for i=1:length(a)

if (a(i)>0.5)
b(i)=1;
else
b(i)=0;
end

end
c=[b(1),b(2),0,b(4),b(5),1,b(7),b(7)];
b
er_bits=0;
for i=1:length(b)
if(c(i)~=b(i))
er_bits=er_bits+1;
else
;
end
end
c
z=er_bits;
berate=z/length(b);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-7
VERIFICATION OF MINIMUM DISTANCE IN HAMMING CODES

AIM:
To verify minimum distance in hamming codes by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1. Hamming codes:

clc;
close all;
clear all;
for m=0:15

a=dec2binvec(m,4);
u1=xor(a(4),a(3));
p1=xor(a(1),u1);
u2=xor(a(4),a(2));
p2=xor(u2,a(1));
u3=xor(a(3),a(2));
p3=xor(u3,a(1));

c(m+1,:)=[p1,p2,a(4),p3,a(3),a(2),a(1)];
z=c;
end
for n1=0:15
for n2=0:15
v(n1+1,n2+1)=ham_d(c(n1+1,:),z(n2+1,:));
end
end
sum=0;
for j=1:256
if v(j)>0
u(sum+1)=v(j);
sum=sum+1;
end
end
dmin=min(u);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

SUB PROGRAM:

function d=ham_d(a,b);
w=xor(a,b);
s=0;
for i=1:7
if(w(i)>0)
s=s+1;
end
end
d =s;
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-8
DETERMINATION OF OUTPUT OF CONVOLUTION ENCODER / DECODER FOR A
GIVEN SEQUENCE

AIM:
To determine output of convolution encoder / decoder for a given sequence by using
MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1. Convolution Encoder:

clc;
close all;
clear all;
m=input('enter m value');
a=dec2binvec(m,4);
d=[0,0,0,0];
for j=1:4
d1=d;
d(4)=a(j);
d(3)=d1(4);
d(2)=d1(3);
d(1)=d1(2);
c1(j)=xor(d(4),d(1));
c2(j)=d(4);
c3(j)=xor(d(2),d(3));
code(j,:)=[c1(j) c2(j) c3(j)]
end

2. Convolution Decoder:

clc;
close all;
clear all;
for i=0:15
a(i+1,:)=dec2binvec(i,4);
end;

for k=1:16
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

d(k,:)=[0,0,0,0];
for j=1:4
d1=d;
d(k,4)=a(k,j);
d(k,3)=d1(k,4);
d(k,2)=d1(k,3);
d(k,1)=d1(k,2);
c1(k,j)=xor(d(k,4),d(k,1));
c2(k,j)=d(k,4);
c3(k,j)=xor(d(k,2),d(k,3));
code(j,:)=[c1(k,j) c2(k,j) c3(k,j)]
end
p(k,:)=[code(1,:) code(2,:) code(3,:) code(4,:)];
t=[1 1 0 1 1 1 0 0 0 0 1 1];
q(k,:)=ham_d(p(k,:),t(1,:));
dmini=min(q);
if (dmini==q(k,:))
mes=a(k,:);
end

end
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-9
GENERATION OF DIRECTSEQUENCE SPREAD SPECTRUM

AIM:
To generate Discrete Sequence Spread Spectrum (DSSS) by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.Generation of DSSS:

clc;
close all;
clear all;
m=[1 0 1 0 1];
r1=rand(1,6);
for i=1:length(r1)
if(r1(i)>0.5)
p0(i)=1;
else
p0(i)=0;
end
end
r2=rand(1,6);

for i=1:length(r2)
if(r2(i)>0.5)
p1(i)=1;
else
p1(i)=0;
end
end

for i=1:5
if(m(i)==0)
en(i,:)=p0;
else
en(i,:)=p1;
end
end
p=[en(1,:) en(2,:) en(3,:) en(4,:) en(5,:)];
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

t=0:0.001:0.01;
c0=sin(2*pi*100*t+pi);
c1=sin(2*pi*100*t);
k=[];
for j=1:30
if(p(j)==0)
out=c0;
else
out=c1
end
k=[k,out];
end
g=1:330
h=1:30
subplot(2,1,1);
stem(h,p);
subplot(2,1,2);
plot(g,k);

SIMULATION RESULTS

1. Discrete Sequence Spread Spectrum (DSSS):


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

EXPERIMENT-10
GENERATION OF FREQUENCY HOPPING SPREAD SPECTRUM

AIM:
To generate Frequency Hopping Spread Spectrum (FHSS) by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.Generation of FHSS:

clc;
close all;
clear all;
m=[1 0 1 0 1 0 1 0];
t=0:0.0001:0.01;
c0=sin(2*pi*100*t+pi);
c1=sin(2*pi*100*t);
k=length(m);
for i=1:k
r=randi([0,7]);
switch r
case 0
fh=sin(2*pi*100*t);
case 1
fh=sin(2*pi*200*t);
case 2
fh=sin(2*pi*300*t
case 4
fh=sin(2*pi*400*t);
case 5
fh=sin(2*pi*600*t);
case 6
fh=sin(2*pi*700*t);
case 7
fh=sin(2*pi*800*t);
end
if(m(i)==0)
out(i,:)=c0.*fh;
else
out(i,:)=c1.*fh;
end
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

end
t1=1;
for i=1:k
for j=1:101
w(t1)=out(i,j);
t1=t1+1;
end
end
t2=0:0.0001:0.0807;
plot(t2,w);

SIMULATION RESULTS

1. Frequency Hopping Spread Spectrum (FHSS) :


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

DIGITAL SIGNAL PROCESSING-OPEN ENDED EXPERIMENT


ANALOG IIR BUTTER WORTH LPF

AIM:
To design analog IIR Butterworth LPF by using Code Compose (CC) Studiosoftware.

TOOLS REQUIRED:

1.CC Studio software


2.personal computer

PROGRAM:

1.CC studio program for Analog IIR Butterworth LPF:

#include<stdio.h>

#include<math.h>

#define pi 3.14

int n,N,i,k;

float A,Ap,As,Wp,Ws,W21,N1,Wc,b[10],bk;

void main()

printf("Enter Pass band frequency of LPF in rad/sec :");

scanf("%f",&Wp);

printf("Enter Stop band frequency of LPF in rad/sec:");

scanf("%f",&Ws);

printf("Enter the gain at Pass band frequency %f rad/sec :",Wp);

scanf("%f",&Ap);

printf("Enter the gain at Stop band frequency %f rad/sec:",Ws);

scanf("%f",&As);
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

printf("\nSelect the required transformation\n");

printf("1. Impulse Invariant Transformation\n");

printf("2. Bilinear Transformation\n");

printf("\nEnter 1 or 2: ");

scanf("%d",&i);

switch(i)

case 1 :

printf("\nYou are selected Impulse Invariant method");

W21=Ws/Wp;

A=(1/(As*As)-1)/(1/(Ap*Ap)-1);

N1=log(A)/(2.0*log(W21));

N=N1+1.0;

Wc=Wp/pow((1/(Ap*Ap)-1),1.0/(2.0*N));

break;

case 2 :

printf("\nYou are selected Bilinear Transformation");

W21=tan(Ws/2)/tan(Wp/2);

A=(1/(As*As)-1)/(1/(Ap*Ap)-1);

N1=log(A)/(2.0*log(W21));

N=N1+1.0;

Wc=2*tan(Wp/2)/pow((1/(Ap*Ap)-1),1.0/(2.0*N));

break;

default:

printf("Sorry, Your selection is wrong");


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

printf("\nInput Data for the BUTTERWORTH LPF\n");

printf("Pass Band Frequency\t\tWp = %f rad/sec.",Wp);

printf("\nStop Band Frequency\t\tWs = %f rad/sec.",Ws);

printf("\nGain at Pass Band Frequency\tAp = %f",Ap);

printf("\nGain at Stop Band Frequency\tAs = %f",As);

printf("\n\nRequired Results of BUTTERWORTH LPF");

printf("\nFrequency ratio\t\t\tW21\t=%f",W21);

printf("\nOrder of the Filter\t\tN\t=%d",N);

printf("\nAnalog cutoff frequency\t Wc\t=%f rad/sec.",Wc);

if(N%2==0)

printf("\nOrder of the BUTTERWORTH LPF is Even");

printf("\nTransfer function of BUTTERWORTH Filter is");

printf("\nHa(s)=PI(Wc*Wc/(s*s+bk*Wc*s+Wc*Wc))");

printf("\nWhere bk=2*sin((2k-1)pi/2N), k=1,2,...N/2\n");

for(k=1;k<=N/2;k++)

b[k]=2*sin((2*k-1)*pi/(2*N));

for(k=1;k<=N/2;k++)

printf("\nb%d=%f",k,b[k]);

if(N%2==1)

printf("\nOrder of the BUTTERWORTH LPF is Odd");


ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

printf("\nTransfer function of BUTTERWORTH Filter is");

printf("\nHa(s)=[Wc/(s+Wc)] PI[Wc*Wc/(s*s+bk*Wc*s+Wc*Wc)]");

printf("\nWhere bk=2*sin((2k-1)pi/2N), k=1,2,...(N-1)/2\n");

for(k=1;k<=(N-1)/2;k++)

b[k]=2*sin((2*k-1)*pi/(2*N));

for(k=1;k<=(N-1)/2;k++)

printf("\nb%d=%f",k,b[k]);

}
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

COMMUNICATIONS-OPEN ENDED EXPERIMENT


ERROR POSITION DETECTION IN HAMMING CODES

AIM:
To detect position of error in received hamming codeword by using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.Generation of FHSS:

clc;
close all;
clear all;
% Hamming encoding

for m=0:15
a=dec2binvec(m,4);
u1=xor(a(4),a(3));
p1=xor(a(1),u1);
u2=xor(a(4),a(2));
p2=xor(u2,a(1));
u3=xor(a(3),a(2));
p3=xor(u3,a(1));
c(m+1,:)=[p1,p2,a(4),p3,a(3),a(2),a(1)];
z=c;

% Hamming decoding

w(m+1,:)=[z(m+1,3),z(m+1,5),z(m+1,6),z(m+1,7) ];

% Hamming error position detection

c1(m+1,:)=[z(m+1,1),z(m+1,2),0,z(m+1,4),z(m+1,5),z(m+1,6),z(m+1,7)];
x1(m+1,:)=xor(c1(m+1,1),0);
x2(m+1,:)=xor(x1(m+1,:),c1(m+1,5));
e1=xor(x2(m+1,:),c1(m+1,7));
e11(m+1,:)=e1;
y1(m+1,:)=xor(c1(m+1,2),0);
y2(m+1,:)=xor(y1(m+1,:),c1(m+1,6));
e2=xor(y2(m+1,:),c1(m+1,7));
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

e22(m+1,:)=e2;
q1(m+1,:)=xor(c1(m+1,4),c1(m+1,5));
q2(m+1,:)=xor(q1(m+1,:),c1(m+1,6));
e3=xor(q2(m+1,:),c1(m+1,7));
e33(m+1,:)=e3;
s=[e1,e2,e3];
syn(m+1,:)=s;
e=s(1)*2^(0)+s(2)*2^(1)+s(3)*2^(2);
errorposi(m+1,:)=e;
end
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

IJERT PAPER
MATLAB IMPLEMENTATION OF WIRELESS SENSOR NETWORK(WSN) IN
PRECISION AGRICULTURE IN RURAL INDIA

AIM:
To implement Wireless Sensor Network(WSN) in precision agriculture in rural India by
using MATLAB software.

TOOLS REQUIRED:

1.MATLAB software
2.personal computer

PROGRAM:

1.MATLAB CODE:

clc;
close all;
clear all;
% step 1
s1=imread('cameraman.tif');
subplot(3,3,1);
imshow(s1);
title('reference image');
% step 2
s2=imread('capturedimage.tif');
subplot(3,3,2);
imshow(s2);
title('captured image');
% step 3
s3=imsubtract(s1,s2);
subplot(3,3,3);
imshow(s3);
title('subtracted image');
% step 4
s4=im2bw(s3);
[M N]=size(s4);
subplot(3,3,4);
imshow(s4);
title('BW image');
% step 5
subplot(3,3,5);
imhist(s4);
title('histogram of BW image');
% step 6
ADVANCED SIGNAL PROCESSING AND COMMUNICATION LAB

s5=bwlabel(s4);
subplot(3,3,6);
imshow(s5);
title('return the size of BW image');
% step 7
for i1=1:256
for j1=1:256
if (s3(i1,j1)>2)
t(i1,j1)=1;
else
t(i1,j1)=0;
end;
end;
end;
subplot(3,3,7);
imshow(t);
title('scaned image');

SIMULATION RESULTS

1. MATLAB IMPLEMENTATION OF (WSN) IN PRECISION AGRICULTURE IN


RURAL INDIA:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy