Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views42 pages

ADSP Lab Printout

The document is a laboratory record note for students at S. Veerasamy Chettiar College of Engineering and Technology, detailing experiments for the Advanced Digital Signal Processing Laboratory. It includes a bonafide certificate, contents of the experiments, and procedures for various signal processing tasks using MATLAB, such as autocorrelation, cross-correlation, multirate systems, and Wiener filtering. Each experiment outlines the aim, required apparatus, theory, algorithm, and expected results.

Uploaded by

karpagadevi
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)
7 views42 pages

ADSP Lab Printout

The document is a laboratory record note for students at S. Veerasamy Chettiar College of Engineering and Technology, detailing experiments for the Advanced Digital Signal Processing Laboratory. It includes a bonafide certificate, contents of the experiments, and procedures for various signal processing tasks using MATLAB, such as autocorrelation, cross-correlation, multirate systems, and Wiener filtering. Each experiment outlines the aim, required apparatus, theory, algorithm, and expected results.

Uploaded by

karpagadevi
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/ 42

SVCET

S.VEERASAMY CHETTIAR
COLLEGE OF ENGINEERING AND TECHNOLOGY
S.V .NAGAR, PULIANGUDI-627 855.

LABORATORY RECORD NOTE


STUDENT NAME :
...........................................................................

REGISTER NO :
...........................................................................

YEAR :
...........................................................................

SEMESTER :
...........................................................................

BRANCH :
...........................................................................
LABORATORY
:
NAME
...........................................................................
SVCET
S.VEERASAMY CHETTIAR COLLEGE OF ENGG
AND TECH
S.V.NAGAR, PULIANGUDI-627 855.

Name………………………………………………………………………………
………. Year/Sem:……………...……............
Dept :
…………………………………………………………………………………….

Reg No.

BONAFIDE CERTIFICATE

Certified that this record is the bonafide work of

the above Student in the CEC332 ADVANCED

DIGITAL SIGNAL PROCESSING Laboratory during

the academic year 2024-2025.

Staff in-charge
Head of the Dept.
Submitted for the Practical Examination held on
………………

Internal Examiner External


Examiner
CONTENTS

Exp
Page Mark Staff
t .N Date Name of the Experiment
No s Signature
o:
Study of autocorrelation and Cross Correlation of
1.
random signals

2. Design and Implementation of Multirate Systems.

3. Design and Implementation of Wiener Filter

Design and Implementation of FIR Linear


4.
Predictor.

5. Design of adaptive filters using LMS algorithm.

6.a Spectrum Estimation using Bartlett Methods.

6.b Spectrum Estimation using Welch Methods.

CONTENT BEYOND SYLLABUS

Implementation of RLS Filter For Noise


1.
Reduction
Common Procedure to all Programs in MATLAB

1. Start the MATLAB program.


2. Click on the ‘FILE’ Menu on menu bar.
3. Click on NEW M-File from the file Menu.
4. An editor window open, start typing commands.
5. Now SAVE the file in directory.
6. Compile and Run the program
7. If any error occurs in the program, correct the error and run it again
8. For the output see command window\ Figure window
9. Stop the program.
Cross Correlation (With Sysntax) Cross Correlation between the two signals (Without Syntax)
clc; x=input('Enter the sequence x(n)')
clear all; n1=input('Enter the time indices of x(n)')
x=input('enter input sequence'); y=input('Enter the sequence y(n)')
h=input('enter the impulse suquence'); n2=input('Enter the time indices of y(n)')
subplot(3,1,1); n22=-fliplr(n2);
stem(x); y1=fliplr(y);
xlabel('n'); n=min(n1)+min(n22):max(n1)+max(n22);
ylabel('x(n)'); A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
title('input signal'); if length(x)<length(y1)
subplot(3,1,2); for i=1:length(x)
stem(h); A(i,i:i+length(y1)-1)=y1(1,:);
xlabel('n'); A(i,:)=x(i).*A(i,:);
ylabel('h(n)'); end
title('impulse signal'); else
y=xcorr(x,h); for i=1:length(y1)
subplot(3,1,3); A(i,i:i+length(x)-1)=x(1,:);
stem(y); A(i,:)=y1(i).*A(i,:);
xlabel('n'); end
ylabel('y(n)'); end
disp('the resultant signal is'); c=zeros(1,length(x)+length(y1)-1);
disp(y); for i=1:min(length(x),length(y1))
title('correlation signal'); c(1,:)=c(1,:)+A(i,:);
end
disp('The Cross correlation between the given sequences is')
disp(c)
disp('The Time index of the Cross correlation is')
disp(n)
subplot(3,1,1)
stem(n1,x)
xlabel('time')
ylabel('amplitude')
grid
title('Given sequence x(n)')
subplot(3,1,2)
stem(n22,y1)
xlabel('time')
ylabel('amplitude')
grid
title(' sequence y(-n)')
subplot(3,1,3)
stem(n,c)
xlabel('time')
ylabel('amplitude')
grid
title('Cross correlation of x(n) and y(n)')
EXP NO: 1 STUDY OF AUTO CORRELATION AND CROSS CORRELATION OF
RANDOM SIGNALS
DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.
THEORY:
Both in signal and Systems analysis, the concept of autocorrelation and crosscorrelation play an
important role. The autocorrelation function of a random signal describes the general dependence of the
values of the samples at one time on the values of the samples at another time. Consider a random process
x(t) (i.e. continuous-time), its autocorrelation function is written as:
T
1
R xx ( τ )= lim
T→∞
∫ x ( t ) x ( t−τ ) dt
2 T −T

Where T is the period of observation.


R xx ( τ )is always real-valued and an even function with a maximum value at τ =0.
For sampled signal (i.e. sampled signal), the autocorrelation is defined as either biased or
unbiased defined as follows:
N−m +1
1
R xx ( m) =
N −|m|
∑ x ( n ) x ( n+m−1 ) [Biased Autocorrelation]
n=1

N −m +1
1
R xx ( m) =
N
∑ x ( n ) x ( n+m−1 )[Uniased Autocorrelation] for m=1,2,…,M+1
n=1

The cross correlation function however measures the dependence of the values of one signal on
another signal. For two WSS (Wide Sense Stationary) processes x(t) and y(t) it is described by:
T
1
R xy ( τ )= lim ∫ x ( t ) x ( t+ τ ) dt
T →∞ T −T

Where T is the observation time.


For sampled signals, it is defined as:
N −m+1
1
R xy ( m) =
N
∑ x ( n ) x ( n+m−1 )
n=1
m=1, 2,3,..,N+1
Where N is the record length (i.e. number of samples).

Output: Output:
enter the input sequence:1 2 3 4 5 1.Enter the sequence x(n)
enter the impulse sequence: 1 1 1 1 x =1 3 5 7
Enter the time indices of x(n)
0 1 2 3
Enter the sequence y(n)
y =5 7 1 3
Enter the time indices of y(n)
0 1 2 3
The Time index of the Cross correlation is
- 3. - 2. - 1. 0. 1. 2. 3.
The Cross correlation of the given sequences is
3 10 25 52 57 74 35
ALGORITHM:
% CROSS CORRELATION:
i. Start the program.
ii. Get the two input sequences.(x(n) & y (n))
iii. Calculate thelengths of input two sequences.
iv. Assign the length of resultant sequence (N) equal to length of first sequence(N1) + length of
second sequence(N2) –1 (N = N1+N2–1).

v. By adding zero padding in input x (n), and take time reversal of input y(n).
vi. Again adding zero padding in input y(n).
vii. Find the cross correlation using syntax “circshift”
viii. Find output from matrix multiplication of zero adding y(n) and shifting input sequence.
ix. Plot the input sequences and output sequence in discrete form corresponding to their lengths.
x. Label the x and y axes.
xi. Display the resultant sequence values.
xii. Terminate the process.
Auto correlation (Without Syntax) Auto Correlation between the two signals (Without Syntax)
clc; clc;
close all; x=input('Enter the sequence x(n)')
clear all; n1=input('Enter the time indices of x(n)')
x = [1,2,3,4,5]; y = [4,1,5,2,6]; y=input('Enter the sequence y(n)=x(n)')
subplot(3,1,1); n2=input('Enter the time indices of y(n)=n1')
stem(x); %y=x; n2=n1
xlabel('n'); n22=-fliplr(n2);
ylabel('x(n)'); y1=fliplr(y);
title('input signal'); n=min(n1)+min(n22):max(n1)+max(n22);
subplot(3,1,2); A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);
stem(y); if length(x)<length(y1)
xlabel('n'); for i=1:length(x)
ylabel('y(n)'); A(i,i:i+length(y1)-1)=y1(1,:);
title('input signal'); A(i,:)=x(i).*A(i,:);
z=xcorr(x,x); end
subplot(3,1,3); else
stem(z); for i=1:length(y1)
xlabel('n'); A(i,i:i+length(x)-1)=x(1,:);
ylabel('z(n)'); A(i,:)=y1(i).*A(i,:);
title('resultant signal signal'); end
end
c=zeros(1,length(x)+length(y1)-1);
for i=1:min(length(x),length(y1))
c(1,:)=c(1,:)+A(i,:);
end
disp('The Autocorrelation of the given sequence x(n) is')
disp(c)
disp('The Time index of Auto correlation is')
disp(n)
subplot(3,1,1)
stem(n1,x)
xlabel('time')
ylabel('amplitude')
grid
title('Given sequence x(n)')
subplot(3,1,2)
stem(n22,y1)
xlabel('time')
ylabel('amplitude')
grid
title(' sequence x(-n)')
subplot(3,1,3)
stem(n,c)
xlabel('time')
ylabel('amplitude')
grid
title('Auto correlation of x(n)')

%AUTO CORRELATION:
i. Start the program.
ii. Get the input sequences x(n) .
iii. Take time reversal of input x(n) and assign a x(-n)
iv. Find the auto correlation using syntax “circshift”
v. Find out the output from matrix multiplication
vi. Plot the input sequences and output sequence in discrete form corresponding to their lengths.
vii. Label the x and y axes.
viii. Display the resultant sequence values.
ix. Terminate the process.
Output : Output :

1.Enter the sequence x(n)


x =1 3 5 7
Enter the time indices of x(n)
0 1 2 3
Enter the sequence y(n)=x(n)
y=1 3 5 7
Enter the time indices of y(n)=n1
0 1 2 3
The Time index of the correlation is
- 3. - 2. - 1. 0. 1. 2. 3.
The Autocorrelation of the given sequence
x(n) is
7. 26. 53. 84. 53. 26. 7.
RESULT:
Program for Computing Multirate Systems

clc;
clear all;
close all;
L = 3; %Up-sampling factor
M = 2; %Down-sampling factor
n = 0:29;
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
x1=[zeros(1,L*30)];
n1=1:1:L*30;
j=1:L:L*30;
x1(j)=x;

x2= x(1:M:30);
n2=1:1:30/M;

y = resample(x,L,M);

subplot(4,1,1),stem(n,x(1:30));
xlabel('Time index n');
ylabel('Amplitude');
title('lnput Sequence');

subplot(4,1,2),stem(n1,x1);
xlabel('Time index n1');
ylabel('Amplitude x1');
title('upsampled Sequence');

subplot(4,1,3),stem(n2,x2);
xlabel('Time index n2');
ylabel('Amplitude x2');
title('Downsampled Sequence');

m = 0:(30*L/M)-1;
subp
lot(4,1,4),stem(m,y(1:30*L/M));
axis([0 (30*L/M)-1 -2.2 2.21])
xlabel('Time index n');
ylabel('Amplitude');
title('Resample Output Sequence');
EXP NO:2 DESIGN AND IMPLEMENTATION OF MULTIRATE SYSTEMS
DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.
THEORY:
In multirate digital signal processing the sampling rate of a signal is changed in order to increase
the efficiency of various signal processing operations. Decimation, or down-sampling, reduces the
sampling rate, whereas expansion, or up-sampling, followed by interpolation increases the sampling rate.
The two basic operations in multirate digital signal processing are decimation and interpolation.
These operations can be performed by building blocks known as decimators and expanders. An M -fold
decimator (Figure 1) that takes an input x(n) and produces the output sequence.
yD(n) = x(M n) (1)
Where M is an integer.

Decimation results in aliasing unless x(n) is band limited in a certain way. In general, however, it
may not be possible to recover x(n) from yD(n) because of loss of information.
An L-fold expander (Figure 2) takes an input x(n) and produces an output sequence.
yE (n) = x(n/L) (2)

In most applications, the decimator is preceded by a lowpass digital filter called the decimation
filter. This filter ensures that the signal being decimated is band limited. The exact band edges of the filter
depend on how much aliasing is permitted. For example, in QMF banks a certain degree of aliasing is
usually permitted because this can eventually be canceled off.
An interpolation filter is a digital filter that follows an expander. The typical purpose is to
suppress all the images. Typically interpolation filter is lowpass with cutoff frequency π/L.
Output
ALGORITHM:
i. Start the program
ii. Define up sampling factor, down sampling factor and input signal.
iii. Represent input sequence of input signal.
iv. Perform the interpolation, decimation and resample on input signal using MATLAB
program.
v. Plot the input and Decimation, interpolation and resample signal/sequence.
vi. Terminate the process

RESULT:
Program for Computing Wiener Filter

clc;
close all;
clear all;
t=0.001:0.001:1;
d=2*sin(2*pi*50*t);
figure;
plot(d);
N=numel(d);
x=d(1:N)+0.5*randn(1,N);
l=d-x;
rr=[ ];k=1;
r=xcorr(x);
M=25;
for i=1:1:M
rr(i)=r(N-i+1);
end
R=toeplitz(rr);
I=inv(R);
p=xcorr(d,x);
for i=1:1:M
P(i)=p(N-i+1);
end
W=(inv(R))*P';
k=1;
y=zeros(N,1);
for i=M:N
j=x(i:-1:i-M+1);
y(i)=(W)'*(j)';
ylim([-5 5])
end
e=y'-d;
subplot(4,1,1);
plot(d);
ylim([-5 5]);
title('desired signal');
subplot(4,1,2);
plot(x);
title('signal corrupted with noise');
subplot(4,1,3);
plot(y);
title('estimated signal');
subplot(4,1,4),plot(e);
ylim([-5 5]);
title('error signal');

EXP NO: 3 DESIGN AND IMPLEMENTATION OF WIENER FILTER


DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.

THEORY:
In signal processing, the Wiener filter is a filter used to produce an estimate of a desired or target
random process by linear time-invariant (LTI) filtering of an observed noisy process, assuming known
stationary signal and noise spectra, and additive noise. The Wiener filter minimizes the mean square error
between the estimated random process and the desired process.
The goal of the Wiener filter is to compute a statistical estimate of an unknown signal using a
related signal as an input and filtering that known signal to produce the estimate as an output. For
example, the known signal might consist of an unknown signal of interest that has been corrupted by
additive noise.
The Wiener filter can be used to filter out the noise from the corrupted signal to provide an
estimate of the underlying signal of interest. The Wiener filter is based on a statistical approach, and a
more statistical account of the theory is given in the minimum mean square error (MMSE) estimator
article.
Typical deterministic filters are designed for a desired frequency response. However, the design
of the Wiener filter takes a different approach. One is assumed to have knowledge of the spectral
properties of the original signal and the noise, and one seeks the linear time-invariant filter whose output
would come as close to the original signal as possible.
Wiener filters are characterized by the following:
1. Assumption: signal and (additive) noise are stationary linear stochastic processes with known
spectral characteristics or known autocorrelation and cross-correlation
2. Requirement: the filter must be physically realizable/causal (this requirement can be dropped,
resulting in a non-causal solution)
3. Performance criterion: minimum mean-square error (MMSE)

Output
ALGORITHM:
i. Start the program
ii. Generate the desired input signal and plot it.
iii. Set the filter length M=25.
iv. Compute the autocorrelation of input signal.
v. Form the autocorrelation matrix.
vi. Form the cross correlation vectors.
vii. Compute the Wiener filter coefficients and perform filtering.
viii. Plot the output wave form of estimated signal and error signal.
ix. Terminate the process.
RESULT:

Program for Computing FIR Linear Predictor

clc;
clear all;
close all;
noise = randn(50000,1);
x = filter(1,[1 1/2 1/3 1/4],noise);
x = x(end-4096+1:end);
a = lpc(x,3);
est_x = filter([0 -a(2:end)],1,x);
subplot(2,1,1);
plot(1:100,x(end-100+1:end),1:100,est_x(end-100+1:end),'--')
grid
xlabel('Sample Number')
ylabel('Amplitude')
legend('Original signal','LPC estimate')
e = x-est_x;
[acs,lags] = xcorr(e,'coeff');
subplot(2,1,2);
plot(lags,acs)
grid
xlabel('Lags')
ylabel('Normalized Autocorrelation')
ylim([-0.1 1.1])
EXP NO: 4 DESIGN AND IMPLEMENTATION OF FIR LINEAR PREDICTOR
DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.

THEORY:
Linear prediction is an important tool in the field of Signal Processing, but also in related
engineering fields. Linear prediction is the process where we attempt to predict the value of the next
sample, given a set of previous samples. The number of previous samples required depends on the type of
predictor that we employ.
A predictor is said to have an order of m if it has at most m taps in the forward or backward
direction. The forward direction, the feed forward elements are the zeros of the filter. The backward
direction, or the feedback elements are the poles of the filter. In other words, the filter has an order m if it
has m zeros or m poles, whichever is greater.
Forward Prediction
A forward linear predictor is a filter that attempts to predict the u(n) sample from the previous m
samples. Forward predictors are causal, which means they only act on previous results.
Backward Prediction
Backward prediction is similar to forward prediction, they are closely related mathematically.
Backward prediction is the process of trying to determine the u(n + M - 1) element of a signal given the
next M elements. In other words, the backward predictor is an attempt to "remember" what a past value
was, given later values.
Lattice Filters
Lattice filters are interesting tools to use because they can simultaneously calculate the forward
and backward filter coefficients given a set of special reflection coefficients. These reflection coefficients
can, in turn, be calculated from the forward or backward filter coefficients. Also, the reflection
coefficients can be calculated from other metrics, such as the signal power, or the autocorrelation
function.

Output
ALGORITHM:
i. Start the program
ii. Generate the signal data as the output of an autoregressive (AR) process driven by normalized
white Gaussian noise.
iii. Use the last 4096 samples of the AR process output.
iv. Compute the predictor coefficients and the estimated signal.
v. Compare the predicted signal to the original signal by plotting the last 100 samples of each.
vi. Compute the prediction error and the autocorrelation sequence of the prediction error.
vii. Plot the output wave form of autocorrelation.
viii. Terminate the process.

RESULT:
Program for Computing adaptive filters using LMS algorithms

clc;
clear all;
close all;

num = fir1(31,0.5);
fir = dsp.FIRFilter('Numerator',num);
iir = dsp.IIRFilter('Numerator',sqrt(0.75),...
'Denominator',[1 -0.5]);
x = iir(sign(randn(2000,25)));
n = 0.1*randn(size(x));
d = fir(x) + n;

l = 32;
mu = 0.008;
m = 5;

lms = dsp.LMSFilter('Length',l,'StepSize',mu);
[mmse,emse,meanW,mse,traceK] = msepred(lms,x,d,m);
[simmse,meanWsim,Wsim,traceKsim] = msesim(lms,x,d,m);

nn = m:m:size(x,1);
subplot(3,1,1);
semilogy(nn,simmse,[0 size(x,1)],[(emse+mmse)...
(emse+mmse)],nn,mse,[0 size(x,1)],[mmse mmse])
title('Mean Squared Error Performance');
axis([0 size(x,1) 0.001 10]);
legend('MSE (Sim.)','Final MSE','MSE','Min. MSE');
xlabel('Time Index');
ylabel('Squared Error Value');

subplot(3,1,2);
plot(nn,meanWsim(:,12),'b',nn,meanW(:,12),'r',nn,...
meanWsim(:,13:15),'b',nn,meanW(:,13:15),'r');
PlotTitle ={'Average Coefficient Trajectories for';...
'W(12), W(13), W(14), and W(15)'};
title(PlotTitle);
legend('Simulation','Theory');
xlabel('Time Index');
ylabel('Coefficient Value');

subplot(3,1,3);
semilogy(nn,traceKsim,nn,traceK,'r');
title('Sum-of-Squared Coefficient Errors');
axis([0 size(x,1) 0.0001 1]);
legend('Simulation','Theory');
xlabel('Time Index');
ylabel('Squared Error Value');

EXP NO: 5 DESIGN ADAPTIVE FILTERS USING LMS ALGORITHM


DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.

THEORY:
The Least Mean Square (LMS) algorithm, introduced by Widrow and Hoff in 1959 is an adaptive
algorithm, which uses a gradient-based method of steepest decent [10]. LMS algorithm uses the estimates
of the gradient vector from the available data. LMS incorporates an iterative procedure that makes
successive corrections to the weight vector in the direction of the negative of the gradient vector which
eventually leads to the minimum mean square error. Compared to other algorithms LMS algorithm is
relatively simple; it does not require correlation function calculation nor does it require matrix inversions.
LMS algorithm formulation
From the method of steepest descent, the weight vector equation is given by,

Where μ is the step-size parameter and controls the convergence characteristics of the LMS algorithm;
e2(n) is the mean square error between the beam former output y(n) and the reference signal which is
given by,
e2(n) = [d*(n) – whx(n)]2
The gradient vector in the above weight update equation can be computed as
∇ w (E{e2(n)}) = - 2r + 2Rw(n)
In the method of steepest descent the biggest problem is the computation involved in finding the
values r and R matrices in real time. The LMS algorithm on the other hand simplifies this by using the
instantaneous values of covariance matrices r and R instead of their actual values i.e.
R(n) = x(n)xh(n) and r(n) = d*(n)x(n)
Therefore the weight update can be given by the following equation,
w(n+1) = w(n) + μx(n)[d*(n) – xh(n)w(n) ] = w(n) + μx(n)e*(n)
The LMS algorithm is initiated with an arbitrary value w(0) for the weight vector at n=0. The successive
corrections of the weight vector eventually leads to the minimum value of the mean squared error.
Output
ALGORITHM:
i. Start the program
ii. Create a dsp.FIRFilter System object.
iii. Set the length of the adaptive filter to 32 taps,
iv. Set the step size to 0.008, and the decimation factor for analysis and simulation to 5
v. Perform the LMS filter.
vi. Plot the MSE results.
vii. Sum of squared coefficient errors and plot the output.
viii. Terminate the process.

RESULT:

Program for Computing Bartlett Methods


%%%% Periodogram Function Program
function px=periodagram(x,n1,n2)
x=x(:);
if margin==1
n1=1;
n2=length(x);
end
px=abs(fft(x(n1:n2),1024)).^2/(n2-n1+1);
px(1)=px(2);
end

%%% Bartlett Function Program


function px=bartlett(x,nsubseq)
L= floor(length(x)/ nsubseq);
px=0;
n1=1;
for i=1:nsubseq
px=px+periodogram(x(n1:n1+L-1))/nsubseq;
n1=n1+L;
end
end

%%% Main Program


clc;
close all;
clear all;

x=randn(1,50);
stem(x)

px=bartlett(x,3);

figure;
plot(10*log10(px))
EXP NO: 6a SPECTRUM ESTIMATION USING BARTLETT METHODS.
DATE:
AIM:

APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.

THEORY:
Spectral estimation in the random signal case means the estimation of power spectrum (or power
spectral density) of a random process (unlike in the deterministic signal case where a spectrum means the
Fourier transform of a signal itself). Spectral estimation provides us an effective means to analyze and
look into random signals from different angle, i.e., from the frequency domain point of view; for example,
for a random process,

consisting of ten harmonic processes with uniform random phases φ k we can easily distinguish the ten
harmonic components located at ωk in the frequency domain, but not in the time domain.
The general problem of spectral estimation in the present case is the one of determining the
spectral content of a wide-sense stationary random process based on a finite set of observations from that
random process.
In Bartlett's method, the single observation x(n) with a length of N is partitioned into K non-
overlapping sequences with such a length of L so that KL=N, as illustrated in Fig. 1. The K non-
overlapping sequences can be expressed as

For the mth sequence, the periodogram is calculated

The Bartlett spectrum estimate is then computed by averaging the K periodograms as follows
Output
ALGORITHM:
i. Start the program
ii. Write a function program of Periodogram and save as Periodogram.m
iii. Write the function program of Bartlett and save as Bartlett.m
iv. Then write the main program for power spectrum density using Bartlett method
v. Generate the discrete time random process and stem the output.
vi. To estimate the spectral using function Bartlett
vii. Plot the output in dB.
viii. Terminate the process.

RESULT:

Program for Computing Welch Methods

clc;
close all;
clear all;
% Generate the discerte time random process

n = 0:319;
x = cos(pi/4*n) + randn(size(n));
segmentLength = 100;
nfft = 640;
pxx = pwelch(x,segmentLength,[],nfft);

plot(10*log10(pxx))
xlabel('rad/sample')
ylabel('dB / (rad/sample)')

EXP NO: 6b SPECTRUM ESTIMATION USING BARTLETT METHODS.


DATE:
AIM:
APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.

THEORY:
In practice, many common random signals are not stationary. Thus, the power spectrum of such a
random process cannot be applied to the whole data record of the process. In this case, however, short
data segments from the long data record may be thought of as being locally stationary. Therefore, a
random signal that is available in practice usually is a segment of a single observation in a noisy
environment, that is, the signal has a finite set of noise-corrupted data. The theoretical power spectrum of
a random process is impossible to obtain. This brings up the general problem of spectral estimation, that
is, the problem of estimating the spectral content (the power spectrum) of a random process based on
noisy measurements of the process that have finite data sets.
The Welch’s method is the modified Bartlett's method. Two modifications are imposed in the
Welch’s method: the first is that the K sequences )(nxm for 10 −≤≤ Km are allowed to overlap, and the
second is that a general window w(n) is applied to each sequence, so as to produce a set of modified
periodograms that are to be averaged.
The mth sequence xm(n) partitioned from the entire N data points is given by

and the overlap between the adjacent sequences, xm(n) and xm+1(n) , is L–D points.
The Welch estimate is

and

Output
ALGORITHM:
i. Start the program.
ii. Set the signal is 320 samples in length.
iii. Create a sine wave with an angular frequency of π/4 rad/sample with additive N(0,1) white noise.
iv. Welch PSD estimate dividing the signal into segments 100 samples in length.
v. Default overlap value of 50% .
vi. The PSD estimate is one-sided and there are 640/2+points.
vii. Terminate the process.

RESULT:

Program for Computing RLS Filter


function [e,w] = RLSFilterIt(n,x,fs)
tic

% Generate data if no inputs provided


if nargin < 1
% Data Parameters
numPts = 1000; % number of points to generate
freq = 100; % frequency of fundamental tone
filtord = 4; % filter order
filt = rand(filtord, 1); % filter coefficients
nVar = 1; % white noise variance
SNR = -20; % signal to noise ratio of tone

% Generate the data!


[n,x,s,fs] = genData(numPts, freq, filt, nVar, SNR);

end

% Filter Parameters
p = 4; % filter order
lambda = 1.0; % forgetting factor
laminv = 1/lambda;
delta = 1.0; % initialization parameter
% Filter Initialization
w = zeros(p,1); % filter coefficients
P = delta*eye(p); % inverse correlation matrix
e = x*0; % error signal
for m = p:length(x)
% Acquire chunk of data
y = n(m:-1:m-p+1);
% Error signal equation
e(m) = x(m)-w'*y;

% Parameters for efficiency


Pi = P*y;

% Filter gain vector update


k = (Pi)/(lambda+y'*Pi);
% Inverse correlation matrix update
P = (P - k*y'*P)*laminv;
% Filter coefficients adaption
w = w + k*e(m);

end
toc
% Plot filter results
t = linspace(0,length(x)/fs,length(x));
figure;
plot(t,x,t,e);
title('Result of RLS Filter')
xlabel('Time (s)');
legend('Reference', 'Filtered', 'Location', 'NorthEast');
title('Comparison of Filtered Signal to Reference Input');

CONTENT BEYOND SYLLABUS


EXP NO: 1 IMPLEMENTATION OF RLS FILTER FOR NOISE REDUCTION
DATE:
AIM:

.
APPARATUS REQUIRED:
Personal Computer with MATLAB software installed.
THEORY:

[e,w]=RLSFilterIt(n,x,fs) is an implementation of the RLS filter for noise reduction. Argument n


is the interference signal, while x is the desired signal corrupted by the noise interference. Argument f s is
the sampling frequency of the inputs, n and x. Additionally, parameters e and w are the filtered signal
and filter coefficients, respectively. The program follows the notation used in Haykin's 'Adaptive Filter
Theory' from 2002.

The function includes a simple example that removes additive white noise from a sine tone, and the SNR
of the tone to the noise can be adjusted to examine the performance of the filter. Input signals can also be
provided.

% Plot comparison of results to original signal (only for generated data)


if nargin < 1
figure;
plot(t,s,t,e);
title('Result of RLS Filter')
xlabel('Time (s)');
legend('Signal', 'Filtered', 'Location', 'NorthEast');
title('Comparison of Filtered Signal to Original Signal');
end
% Calculate SNR improvement
SNRi = 10*log10(var(x)/var(e));
disp([num2str(SNRi) 'dB SNR Improvement'])
return
function [n,x,s,fs] = genData(numPts, freq, filt, nVar, SNR)
% Generate time values
t = linspace(0,1,numPts)';
fs = numPts;

% Generate tone
s = sin(2*pi*freq*t);

% Generate noise
n = sqrt(nVar)*randn(numPts,1);

% Filter noise
addnoise = filter(filt, 1, n);

% Plot filter
freqz(filt,1,1000)

% Adjust SNR of tone


s = s/sqrt(var(s)/(10^(SNR/10)*var(n)));
disp(['Calculated SNR = ' num2str(10*log10(var(s)/var(n)))])

% Add noise to signal


x = s + addnoise;

return

Output:

Calculated SNR = -20


Elapsed time is 42.222603 seconds.
17.232dB SNR Improvement
RESULT:

You might also like