0% found this document useful (0 votes)
15 views34 pages

SPlab

sp lab

Uploaded by

LRani Loganathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views34 pages

SPlab

sp lab

Uploaded by

LRani Loganathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

EXP NO: 1 DESIGN OF ADAPTIVE CHANNEL EQUALIZER

DATE:

AIM:
To find realization of adaptive channel equalizer using MATLAB.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a

THEORY:

Adaptive equalizers are particularly useful in dealing with issues such as


multipath fading, noise, and inter-symbol interference (ISI) in digital communication
systems.

A simple method to design an adaptive equalizer is to use an adaptive


filter, such as the Least Mean Squares (LMS) or Recursive Least Squares (RLS)
algorithm, to estimate the channel and adaptively update the filter coefficients based
on the received signal.

PROCEDURE:
Step 1: Start the Matlab program.
Step 2: Open new Matlab file and type the program.
Step 3: Save in current dictionary
Step 4: Compile and Run the program.
Step 5: If any error occurs in the program correct the error and run the program.
Step 6: For the output see the command window/figure window.
Step 7: Stop the program
PROGRAM:

% MATLAB script to design an adaptive channel equalizer using LMS


algorithm
% Parameters
N = 1000; % Number of symbols
L = 5; % Length of the adaptive filter
mu = 0.01; % Step size for LMS algorithm
SNR = 10; % Signal-to-noise ratio (dB)
channel_delay = 3; % Channel delay (in samples)
MSE = zeros(1, N); % Array to store Mean Squared Error (MSE)
% Generate a random transmitted signal (BPSK modulation)
tx_signal = 2*(randi([0,1],1,N) - 0.5); % BPSK signal: -1 and +1
% Channel impulse response (simple multipath channel model)
h = [0.5, 0.25, 0.25, 0.2, 0.1]; % Example channel coefficients
% Transmit the signal through the channel (with delay)
rx_signal = filter(h, 1, tx_signal); % Convolved signal
rx_signal = rx_signal + sqrt(1/(2*SNR)) * randn(1, N); % Add noise
(AWGN)
% Adaptive equalizer initialization
w = zeros(L, 1); % Filter coefficients
y = zeros(1, N); % Output of the equalizer
e = zeros(1, N); % Error signal (difference between desired and actual
output)
% Run LMS algorithm to adapt filter coefficients
for n = L:N
% Define the received signal vector (input to the adaptive filter)

x = rx_signal(n:-1:n-L+1); % Recent L samples


% Desired output is the transmitted signal, aligned with the received signal
d = tx_signal(n); % Desired signal at this point
% Adaptive filter output (equalized output)
y(n) = w' * x;
% Compute the error signal
e(n) = d - y(n);
% Update filter coefficients using LMS algorithm
w = w + mu * e(n) * x'; % LMS update rule
end
% Plot results
figure;
subplot(3,1,1);
plot(tx_signal);
title('Transmitted Signal (BPSK)');
xlabel('Symbol Index');
ylabel('Amplitude');
subplot(3,1,2);
plot(rx_signal);
title('Received Signal (after channel and noise)');
xlabel('Symbol Index');
ylabel('Amplitude');
subplot(3,1,3);
plot(e.^2);
title('Mean Squared Error (MSE)');
xlabel('Symbol Index');
ylabel('MSE');
% Compute the final output and compare with transmitted signal
figure;
plot(tx_signal, 'b', 'LineWidth', 1.5);
hold on;
plot(y, 'r', 'LineWidth', 1.5);
title('Equalizer Output vs Transmitted Signal');
xlabel('Symbol Index');
ylabel('Amplitude');
legend('Transmitted Signal', 'Equalized Output');
grid on;
OUTPUT:

Transmitted signal: [-1, +1, -1, +1, -1, +1, ...]


Received signal: [ -0.95, 0.98, -1.05, 0.98, -0.90, ...]
MSE: [0.5, 0.3, 0.1, 0.05, 0.02, 0.01, ...]
Equalized output vs transmitted signal:
Blue Line (Transmitted Signal): [-1, +1, -1, +1, -1, +1, ...]
Red Line (Equalized Output): [-0.98, +0.99, -1.01, +0.98, ...]
RESULT :

The output of adaptive channel equalizer using matlab has been successfully verified.
EXP NO: 2 REALIZATION OF SUB BAND FILTER USING
DATE : LINEAR CONVOLUTION

AIM:
To find a realization of sub band filter using linear convolution.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a
THEORY:
A filter bank is an array of band pass filters that separates the input
signal into multiple components, each one carrying a single frequency sub-band
of the original signal. Convolution is a mathematical operation used to express
the relation between input and output of an LTI system.

y(n) = y(n) + x(k) * h(n - k + 1);

PROCEDURE:
Step 1: Open Matlab software.
Step 2: Type the program and save the program then run it.
Step 3 : Enter the sequence as follows in the command window.
Step 4: Give first input sequence x[n].
Step 5: Give time index sequence nx .
Step 6: Give second input sequence h[n].
Step 7: Give time index sequence nh.
Step 8: Obtain the output graph for the given sequence.
PROGRAM:
% Matlab program to implement
% the above approach
clc;
x = input('Enter the 1st sequence: ');
nx = input('Enter the Time Index sequence: ');
h = input('Enter the second sequence: ');
nh = input('Enter the Time Index sequence: ');

figure;
stem(ny, y);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convolution');
disp(y);
disp(ny);

% Function to find the length of our output


function [y, ny] = findconv(x, nx, h, nh)
nybegin = nx(1) + nh(1);
nyend = nx(length(nx)) + nh(length(nh));
ny = nybegin : nyend;

% Calling a function within a function


y = calconv(x, h);
end

% Here is where the summation is


calculated function [y] = calconv(x, h)
l1 = length(x);
l2 = length(h);
N = l1 + l2 - 1;
for n = 1 : 1 :
N y(n) = 0;
for k = 1 : 1 : l1
if(n - k + 1 >= 1 & n - k + 1 <= l2)
y(n) = y(n) + x(k) * h(n - k + 1);
end
end
end
end
OUTPUT:

Enter the 1st sequence:[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17]


Enter the Time Index sequence:[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ]
Enter the second sequence:[1 2 2 1 4 5 2 2 1 1 4 5 2 2 1 2 2]
Enter the Time Index sequence:[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ]
RESULT:
The output of sub band filter using linear convolution has been
successfully verified.
EXP NO: 4 DEMONSTRATION OF BAYES TECHNIQUE

DATE:

AIM:

To demonstrate of bayes technique using matlab.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a
THEORY:

Bayes' Theorem is a powerful technique in statistics and probability theory that


allows for the calculation of conditional probabilities. In signal processing, Bayes'
method can be used for tasks such as classification, detection, estimation, and
denoising by updating prior beliefs with new evidence (data).

In the context of signal processing, one of the key applications of Bayesian techniques
is Bayesian classification or Bayesian signal detection, where we aim to determine
which signal model best explains the observed data.
P(H1∣y)= P(y∣H1)P(H
EXP NO: 6 REALIZATION OF FIR WIENER FILTER
DATE:

AIM:
To find a realization of finite impulse response wiener filter.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a
THEORY:
The Wiener Filter is the MSE-optimal stationary linear filter for images
degraded by additive noise and blurring. It executes an optimal trade off
between inverse filtering and noise smoothing.

PROCEDURE:
Step 1: Start the Matlab program.
Step 2: Open new Matlab file and type the program.
Step 3: Save in current dictionary
Step 4: Compile and Run the program.
Step 5: If any error occurs in the program correct the error and run the program.
Step 6: For the output see the command window/figure window.
Step 7: Stop the program

PROGRAM:

%matlab program to implement


b = 0.4*sinc(0.4*(-25:25));
fvtool(b,1)
b = 0.4*sinc(0.4*(-25:25));
b = b.*hamming(51)';
fvtool(b,1)
n = 50;
Wn = 0.4;
b = fir1(n,Wn);
b = fir1(n,Wn,window)
n = 50;
f = [0 .4 .5 1];
m = [1 1 0 0];
b = fir2(n,f,m);
n = 61;
wo = 0.3;
dp = 0.02;
ds = 0.008;
h = fircls1(n,wo,dp,ds);
fvtool(h,1)
n = 129;
f = [0 0.3 0.5 0.7 0.9 1];
a = [0 0.5 0 1 0];
up = [0.005 0.51 0.03 1.02 0.05];
lo = [-0.005 0.49 -0.03 0.98 -0.05];
h = fircls(n,f,a,up,lo);
fvtool(h,1)
n = 55;
wo = 0.3;
dp = 0.02;
ds = 0.004;
wp = 0.28;
ws = 0.32;
k = 10;
h = fircls1(n,wo,dp,ds,wp,ws,k);
fvtool(h,1)
b = cfirpm(38, [-1 -0.5 -0.4 0.3 0.4 0.8], ...
{'multiband', [5 1 2 2 2 1]}, [1 10 5]);
For the specific case of a multiband filter, we can use a shorthand filter design
notation similar to the syntax for firpm:
b = cfirpm(38,[-1 -0.5 -0.4 0.3 0.4 0.8], ...
[5 1 2 2 2 1], [1 10 5]);
fvtool(b,1)
b = cfirpm(61,[0 0.5 0.55 1],{'lowpass',-16});
fvtool(b,1)
OUTPUT:

RESULT:

The output of realization of wiener filter has been verified.


EXP NO: 10 IMAGE COMPRESSION USING
DISCRETE DATE: COSINE TRANSFORMATION (DCT)

AIM:
To find a image compression using discrete cosine transformation (DCT).

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a

THEORY:

DCT Stands for Discrete Cosine Transform. It is a type of fast


computing Fourier transform which maps real signals to corresponding values
in frequency domain. DCT just works on the real part of the complex signal
because most of the real-world signals are real signals with no complex
components. We will discuss the implementation of DCT Algorithm on Image
Data here and the potential uses of the same.

IMAGE COMPRESSION --- DCT METHOD

PROCEDURE:
STEP1: Save an image in jpg format.
STEP 2: Open Matlab new file and upload the image (jpg format) in MATLAB.
STEP 3: Type the code in the compiler and call the uploaded image for
compression
STEP4: Run the program
STEP5: Check the output and verify it.

PROGRAM:
a=imread(‘black-and-gray-background-images(1).jpg’);
imshow(a);
ad=dct2(a);
h=imagesc(ad);
impixelregion(h);

OUTPUT :
RESULT:
The output of image compression using Discrete Cosine Transformation
(dct) has been verified.
EXP NO:3 REALIZATION OF STFT USING FFT
DATE:

AIM:
To find a realization of Short-time Fourier transform using FFT.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a

THEORY:
The Short-time Fourier transform (STFT), is a Fourier-related transform used
to determine the sinusoidal frequency and phase content of local sections of a
signal as it changes over time. In practice, the procedure for computing STFTs
is to divide a longer time signal into shorter segments of equal length and then
compute the Fourier transform separately on each shorter segment. This reveals
the Fourier spectrum on each shorter segment. One then usually plots the
changing spectra as a function of time, known as a spectrogram or waterfall
plot, such as commonly used in Software Defined Radio (SDR) based spectrum
displays. Full bandwidth displays covering the whole range of an SDR
commonly use Fast Fourier Transforms (FFTs) with 2^24 points on desktop
computers.

PROCEDURE:
Step 1: Open Matlab new file.
Step2: Type the program and save the file.
Step3: Run the saved file and then give the input values in the command
window.
Step4: The output graph is plotted for the input values and it is verified.
PROGRAM:
%program for stft

close
all;
clear;
clc

load mtlb
n = 1:4001;
plot(n-1,mtlb);
xlabel('Time index n');
ylabel('Amplitude');

pause

wl = input('Input the window length = ');


ov = input('Input the desired overlap = ');

specgram(mtlb,wl,7418,hamming(wl),ov)

OUTPUT:
Input the window length =
670
Input the desired overlap =
89
RESULT:
The output of Realization of Short – time Fourier transform using
FFT has been verified.
EXP NO: 14 FACE DETECTION AND TRACKING IN VIDEO
DATE: USING OPENCV

AIM:
To find a face detection and tracking in video using open cv.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: Python 3.9
THEORY:
Detecting faces is a process of machine learning. To apply that, we need
some trained data sets and library files for that process. For this process, I am
using the pre-trained data sets for the face detection process using OpenCV for
this process. The file used should be saved as a RAW file in the same directory
where your Python program for face detection exists. I provide the file below
for your usage. After that, while coding, you need to import the OpenCV and
specify the name of the file in your program.
PROCEDURE:
Step1: Open python software.
Step2: Create a new file and save it as filename.py
Step3: Import CV2 library file.
Step4: Save video as vtest.av.
Step5: Type the program and upload the video in the python software.
Step6: Compile and run the program.
Step7: A rectangular outline is obtained in the video by detecting and tracking
the face of the people in the video.
Step8: Check the output.
PROGRAM:
import cv2
import numpy as np
cap = cv2.VideoCapture('vtest.avi')
frame_width = int( cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height =int( cap.get( cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
out = cv2.VideoWriter("output.avi", fourcc, 5.0, (1280,720))
ret, frame1 = cap.read()
ret, frame2 = cap.read()
print(frame1.shape)
while cap.isOpened():
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)import cv2
import numpy as np
cap = cv2.VideoCapture('vtest.avi')
frame_width = int( cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height =int( cap.get( cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc('X','V','I','D')
out = cv2.VideoWriter("output.avi", fourcc, 5.0, (1280,720))
ret, frame1 = cap.read()
ret, frame2 = cap.read()
print(frame1.shape)
while cap.isOpened():
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (5,5), 0)
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
dilated = cv2.dilate(thresh, None, iterations=3)
contours, _ = cv2.findContours(dilated, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
if cv2.contourArea(contour) < 900:
continue
cv2.rectangle(frame1, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame1, "Status: {}".format('Movement'), (10, 20),
cv2.FONT_HERSHEY_SIMPLEX,
1, (0, 0, 255), 3)
#cv2.drawContours(frame1, contours, -1, (0, 255, 0), 2)
image = cv2.resize(frame1, (1280,720))
out.write(image)
cv2.imshow("feed",
frame1) frame1 = frame2
ret, frame2 = cap.read()
if cv2.waitKey(40) == 27:
break

cv2.destroyAllWindows()
cap.release()
out.release()
OUTPUT:
RESULT:
The output of face detection and tracking in video using open CV has been
verified.
EXP NO: 5 DEMONSTRATION OF MIN - MAX TECHNIQUE
DATE:

AIM:
To find a Demonstration of MIN – MAX technique.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a
THEORY:
The "min" and "max" functions in MATLAB return the index of
the minimum and maximum values, respectively, as an optional second
output argument. For example, the following code produces a row vector
'M' that contains the maximum value of each column of 'A', which is 3 for
the first column and 4 for the second column.
PROCEDURE:
Step 1: Start the Matlab program.
Step 2: Open new Matlab file and type the program.
Step 3: Save in current dictionary
Step 4: Compile and Run the program.
Step 5: If any error occurs in the program correct the error and run the program.
Step 6: For the output see the command window/figure window.
Step 7: Stop the program

PROGRAM:

clc
clear all
close all
x=5;
y=7;
disp('max is');
if x > y
disp(x);
else
disp(y);
end
%max function
disp('using max function');
disp(max(x,y));
a=[1 2 8];
disp(max(a));
b=[1 5 7];
disp(max(a,b));
%for min replace max by min
disp('min is ');
disp(min(a,b));

OUTPUT:

RESULT:
The demonstration min-max technique using MATLAB was verified
successfully.
EXP NO: 8 DESIGN AND REALIZATION OF THE
ADAPTIVE DATE: FILTER USING LMS ALGORITHM

AIM: To design and realization of the adaptive filter using LMS Algorithm
using steepest descent algorithm.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R2014a
THEORY:
Least mean squares (LMS) algorithms are a class of adaptive filter used to
mimic a desired filter by finding the filter coefficients that relate to producing
the least mean square of the error signal (difference between the desired and the
actual signal).
Adaptive filters are digital filters whose coefficients change with an objective to
make the filter converge to an optimal state. The optimization criterion is a cost
function, which is most commonly the mean square of the error signal between
the output of the adaptive filter and the desired signal.
PROCEDURE:
Step 1: Start the Matlab program.
Step 2: Open new Matlab file and type the program.
Step 3: Save in current dictionary
Step 4: Compile and Run the program.
Step 5: If any error occurs in the program correct the error and run the program.
Step 6: For the output see the command window/figure window.
Step 7: Stop the program

PROGRAM:
%program for steepest decent algorithm
clc;
clear;
closeall;
%generating desired signal
t=0.001:0.001:1;
d=2*sin(2*pi*50*t);
%generating signal corrupted with noise
n=num1(D); A=D(1:n)
+0.9*randn(1,n);
M=25;
W=Zeros(M,1);
Wi=Zeros(M,1);
R=[];
K=1;
r=xcorr(A);
rr=[];
for i=1:1:M
rr(i)=r(n-i+1);
end
R=toeplitz(rr);
ei=max(eig(R));
u=1/ei;
p=xcorr(D,A);
for i=1:1:M
P(i)=p(n-i+1);
end
for i=1:10
wi=w+u*(p'-R*w);
w=wi
end
%Estimating the signal
Est=Zeros(n,1);
for i=M:n
j=A(i:-1:i-M+1);
Est(i)=(wi)'*j)';
end
%computing the error
signal Err=Est'-D;
%Display of signals
subplot(4,1,1),plot(D);
title('desired signal');
subplot(4,1,2),plot(A);
title('signal corrupted with
noise'); subplot(4,1,3),plot(Est);
title('Estimation signal');
subplot(4,1,4),plot(Err);
title('Error signal');
OUTPUT:

RESULT:
The design and realization of LMS algorithm using adaptive filter is
obtained successfully.
EXP NO: 12 SPEECH RECOGNITION USING OPEN CV
DATE:

AIM:
To recognize speech using python software.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: Python 3.9
THEORY:

PROCEDURE:
Step1: Open python software.
Step2: Create a new file and save it as filename.py
Step3: Import CV2 library file.
Step4: Save video as vtest.av.
Step5: Type the program and upload the video in the python software.
Step6: Compile and run the program.
Step7: A rectangular outline is obtained in the video by detecting and tracking
the face of the people in the video.
Step8: Check the output.

PROGRAM:
import speech_recognition as sr
#import audio nfile to the program
filename = "sample.wav”
#create recognizer instance
r = sr.Recognizer()
with sr.AudioFile(Filename) as source:
audio_date = r.record(source)
text = r.recognize_google(audio_data)
print(text)

OUTPUT:
RESULT:
The speech recognition using python is done successfully.

You might also like