adsp lab manual

advertisement
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
INDEX
S.NO.
Title of the program
1
Generation of Various signals
2
Generation of a Sinusoidal signal
3
FFT of Different signals
4
Program to verify decimation and
interpolation of given sequences.
5
Program to convert CD data into DVD
data
6
Generation of Dual Tone Multiple
frequency (DTMF) Signals
7
Power spectral density using Square
magnitude
and
Auto
correlation
method
8
Power spectral density estimation
using
periodogram
and
modified
periodogram
9
Power spectral density estimation
using Barlett method
10
Power spectral density estimation
using Welch method
11
PSD estimation using Blackmann and
Tukey method
12
Power
spectrum
estimation
using
Yule-walker method
13
Power spectrum estimation using Burg
method
1
Page no.
Marks
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
1. GENERATIONOF BASIC SIGNALS
( unit impulse, exponential, unit step, ramp )
AIM : To generate the Basic Signals like unit impulse, step, ramp, and exponential.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : In this program basic signals like unit impulse, unit step,
ramp, and exponential signals are to be generated based on the following definitions.
1. Unit impulse signal: This signal is having unit amplitude only at origin and else
where the amplitude zero. It is denoted by δ(t).
2. Unit step signal: This signal is having unit amplitude for all the positive values of
time axis and else where the amplitude zero. It is denoted by u (t). The sequence is
denoted by u[n].
3. Ramp signal: This signal is having amplitude values linearly increasing same as
the time axis values from origin to all the positive values and else where the
amplitude zero. It is denoted by r(t). The sequence is denoted by r[n].
4. Exponential signal: This signal is having the amplitudes exponentially increasing
with time. This is a plot of eat. Where ‘e’ denotes exponential function, ‘a’ is an
integer and ‘t’ is the time scale.
PROGRAM :
%Generation of various signals: impulse, exponential, step, ramp.
clc;
clear all;
clear all;
%impulse sequence
t=-2:1:2;
y1=[zeros(1,2) 1 zeros(1,2)];
subplot (2,2,1);
stem(t,y1);
grid
title ('Impulse Response');
xlabel ('no. of samples :n-->');
ylabel ('--> Amplitude');
%Exponential Sequence
n=input('enter the length of Exponential Sequence');
t=0:1:n;
a=input('Enter "a" value');
y2=exp(a*t);
subplot(2,2,2);
2
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
stem(t,y2);
grid
title ('Exponential Sequence');
xlabel ('no. of samples :n-->');
ylabel ('--> Amplitude');
%Step Sequence
s=input ('enter the length of step sequence');
t=-s:1:s;
y3=[zeros(1,s) ones(1,1) ones(1,s)];
subplot(2,2,3);
stem(t,y3);
grid
title ('Step Sequence');
xlabel ('no. of samples :n-->');
ylabel ('--> Amplitude');
%Ramp Sequence
x=input ('enter the length of Ramp sequence');
t=0:x;
subplot(2,2,4);
stem(t,t);
grid
title ('Ramp Response');
xlabel ('no. of samples :n-->');
ylabel ('--> Amplitude');
OUPUTS:
enter the length of Exponential Sequence: 5
Enter "a" value :2
enter the length of step sequence: 5
enter the length of Ramp sequence: 6
3
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS :
Impulse Response
3
--> Amplitude
--> Amplitude
1
0.5
0
-2
-1
0
1
no. of samples :n-->
Step Sequence
1
0
2
4
no. of samples :n-->
Ramp Response
6
0
2
4
no. of samples :n-->
6
6
--> Amplitude
--> Amplitude
1
0.5
0
-5
2
0
2
4
x 10 Exponential Sequence
0
no. of samples :n-->
4
2
0
5
INFERENCE : In the generation of the basic signals we have defined the signals along
time and amplitude axes for unit impulse, step, ramp and exponential signals and plotted
the graphs. For different values the graphs are plotted.
RESULT : The basic signals like unit impulse , unit step, ramp and exponential signals
are generated and the waveforms are plotted.
4
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
2. GENERATION OF BASIC SIGNALS
( Sinusoidal signal )
AIM : To Generate sinusoidal signal of frequency f Hz and phase phi
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : A sinusoidal signal is a continuous signal whose
amplitude varies between two fixed values on the positive and negative amplitude axes.
This is a plotted as a function of frequency, time and phase for different values. This signal
is represented as y(t)=A sin ( 2πft+φ ). Where A is amplitude, f is the frequency, t is time
and φ is phase.
PROGRAM :
% Generation of sinusoidal signal of f Hz and phase phi
clc;
clear all;
close all;
A=input('Enter the amplitude of the sinusoidal signal= ');
f = input('Enter the frequency of the sinusoid sequence f = ');
phi = input('Enter the phase of the sinusoid sequence phi = ');
fs = input('Enter the sampling frequency fs = ');
T = input('Enter the duration of the sequence T = ');
dt = 1/fs;
t = 0:dt:T;
y = A*sin(2*pi*f*t + phi);
plot(t,y);
title('Sinusoidal signal','fontsize',12);
xlabel('t -->');
ylabel('Amplitude -->');
OUTPUTS:
Enter the amplitude of the sinusoidal signal= 3
Enter the frequency of the sinusoid sequence f = 4
Enter the phase of the sinusoid sequence phi = 10
Enter the sampling frequency fs = 1000
Enter the duration of the sequence T = 2
5
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS :
Sinusoidal signal
3
2
Amplitude -->
1
0
-1
-2
-3
0
0.2
0.4
0.6
0.8
1
t -->
1.2
1.4
1.6
1.8
2
INFERENCE : The frequency ‘ f ’ indicates the no. of cycles in one second i.e., in this
program 4 cycles in one second as f = 4. Similarly duration indicates the total signal which
is to be displayed, here duration is 2, means from 0 to 2 sec. the signal is plotted.
RESULT : For a particular frequency f Hz and phase phi, the sinusoidal signal is generated
and plotted.
6
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
3. FINDING THE FFT OF DIFFERENT SIGNALS
AIM : To find the FFT of different signals like impulse, step, ramp and exponential.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : In this program using the command FFT for impulse, step,
ramp and exponential sequences the FFT is generated. In the process of finding the FFT the
length of the FFT is taken as N. The FFT consists of two parts: MAGNITUDE PLOT and
PHASE PLOT. The magnitude plot is the absolute value of magnitude versus the samples
and the phase plot is the phase angle versus the samples.
PROGRAM :
% FFT of the impulse sequence : magnitude and phase response
clc;
clear all;
close all;
%impulse sequence
t=-2:1:2;
y=[zeros(1,2) 1 zeros(1,2)];
subplot (3,1,1);
stem(t,y);
grid;
input('y=');
disp(y);
title ('Impulse Response');
xlabel ('time -->');
ylabel ('--> Amplitude');
xn=y;
N=input('enter the length of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid;
xlabel('k');
ylabel('|x(k)|');
subplot(3,1,3);
stem(k,angxk);
disp(xk);
grid;
xlabel('k');
ylabel('arg(x(k))');
7
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
OUTPUTS:
y=
0
0
1
0
0
enter the length of the FFT sequence: 10
1.0000
1.0000
0.3090 - 0.9511i
0.3090 - 0.9511i
-0.8090 - 0.5878i
-0.8090 - 0.5878i
-0.8090 + 0.5878i 0.3090 + 0.9511i
-0.8090 + 0.5878i 0.3090 + 0.9511i
GRAPHS:
--> Amplitude
Impulse Response
1
0.5
0
-2
-1.5
-1
-0.5
0
time -->
0.5
1
1.5
2
|x(k)|
1
0.5
0
0
1
2
3
4
5
6
7
8
9
5
6
7
8
9
k
arg(x(k))
5
0
-5
0
1
2
3
4
k
8
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
% FFT of the step sequence : magnitude and phase response
clc;
clear all;
close all;
%Step Sequence
s=input ('enter the length of step sequence');
t=-s:1:s;
y=[zeros(1,s) ones(1,1) ones(1,s)];
subplot(3,1,1);
stem(t,y);
grid
input('y=');
disp(y);
title ('Step Sequence');
xlabel ('time -->');
ylabel ('--> Amplitude');
xn=y;
N=input('enter the length of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid
xlabel('k');
ylabel('|x(k)|');
subplot(3,1,3);
stem(k,angxk);
disp(xk);
grid
xlabel('k');
ylabel('arg(x(k))');
OUTPUTS:
enter the length of step sequence: 5
y= 0 0 0 0 0 1 1 1
1
1
1
enter the length of the FFT sequence: 10
5.0000 -1.0000 + 3.0777i 0
-1.0000 + 0.7265i
-1.0000 - 0.7265i
0
-1.0000 - 3.0777i
9
0
-1.0000
0
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS:
--> Amplitude
Step Sequence
1
0.5
0
-5
-4
-1
-2
-3
3
2
1
0
time -->
4
5
|x(k)|
5
0
0
1
2
3
4
5
6
7
8
9
5
6
7
8
9
k
arg(x(k))
5
0
-5
0
1
2
3
4
k
10
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
% FFT of the Ramp sequence: magnitude and phase response
clc;
clear all;
close all;
%Ramp Sequence
s=input ('enter the length of Ramp sequence: ');
t=0:s;
y=t
subplot(3,1,1);
stem(t,y);
grid
input('y=');
disp(y);
title ('ramp Sequence');
xlabel ('time -->');
ylabel ('--> Amplitude');
xn=y;
N=input('enter the legth of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid
xlabel('k');
ylabel('|x(k)|');
subplot(3,1,3);
stem(k,angxk);
disp(xk);
grid
xlabel('k');
ylabel('arg(x(k))');
OUTPUTS:
enter the length of Ramp sequence: 5
y= 0 1 2 3 4 5
enter the length of the FFT sequence: 10
15.0000 -7.7361 - 7.6942i 2.5000 + 3.4410i
-3.0000 2.5000 - 0.8123i
-3.2639 + 1.8164i
11
-3.2639 - 1.8164i
2.5000 - 3.4410i
2.5000 + 0.8123i
-7.7361 + 7.6942i
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS:
--> Amplitude
ramp Sequence
5
0
0
0.5
0
1
1
1.5
2
2.5
time -->
3
3.5
4
4.5
5
|x(k)|
20
10
0
2
3
4
5
6
7
8
9
5
6
7
8
9
k
arg(x(k))
5
0
-5
0
1
2
3
4
k
12
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
% FFT of the Exponential Sequence : magnitude and phase response
clc;
clear all;
close all;
%exponential sequence
n=input('enter the length of exponential sequence: ');
t=0:1:n;
a=input('enter "a" value: ');
y=exp(a*t);
input('y=')
disp(y);
subplot(3,1,1);
stem(t,y);
grid;
title('exponential response');
xlabel('time');
ylabel('amplitude');
disp(y);
xn=y;
N=input('enter the length of the FFT sequence: ');
xk=fft(xn,N);
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
subplot(3,1,2);
stem(k,magxk);
grid;
xlabel('k');
ylabel('|x(k)|');
subplot(3,1,3);
stem(k,angxk);
grid;
disp(xk);
xlabel('k');
ylabel('arg(x(k))');
OUTPUTS:
enter the length of exponential sequence: 5
enter "a" value: 0.8
y= 1.0000 2.2255
4.9530 11.0232 24.5325 54.5982
enter the length of the FFT sequence: 10
13
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
98.3324
-73.5207 -30.9223i 50.9418 +24.7831i -41.7941 -16.0579i
38.8873 + 7.3387i
-37.3613
38.8873 - 7.3387i
-41.7941 +16.0579i
50.9418 -24.7831i
-73.5207 +30.9223i
GRAPHS :
exponential response
amplitude
100
50
0
0
0.5
0
1
1
1.5
2
2.5
time
3
3.5
4
4.5
5
|x(k)|
100
50
0
2
3
4
5
6
7
8
9
5
6
7
8
9
k
arg(x(k))
5
0
-5
0
1
2
3
4
k
INFERENCE : The FFT for impulse, step, ramp and exponential sequences is generated
using the FFT command. The magnitude plot is the absolute value of magnitude versus the
samples and the phase plot is the phase angle versus the samples is plotted for different
signals for different values. This program is very simple and requires defining the signal
and finding FFT and plotting.
RESULT : The FFT of different signals like impulse, step, ramp and exponential is found
and the magnitude and phase plots of the same is plotted.
14
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
4. PROGRAM TO VERIFY DECIMATION AND INTERPOLATION
AIM : To verify Decimation and Interpolation of a given Sequences
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The sampling rate alteration that is employed to generate
a new sequence with a sampling rate higher or lower than that of a given sequence. Thus, if
x[n] is a sequence with a sampling rate of FT Hz and it is used to generate another sequence
y[n] with a desired sampling rate of FT' Hz, then the sampling rate alteration ratio is given
by FT' / FT = R.
If R > 1, the process is called interpolation and results in a sequence with a higher
sampling rate.
If R < 1, the sampling rate is decreased by a process called decimation and it results in a
sequence with a lower sampling rate.
The decimation and interpolation can be carried out by using the pre-defined commands
decimate and interp respectively.
PROGRAMS:
% DECIMATION
clc;
clear all;
close all;
disp('Let us take a sinusoidal sequence which has to be decimated: ');
fm=input('Enter the signal frequency fm: ');
fs=input('Enetr the sampling frequnecy fs: ');
T=input('Enter the duration of the signal in seconds T: ');
dt=1/fs;
t=dt:dt:T
M=length(t);
m=cos(2*pi*fm*t);
r=input('Enter the factor by which the sampling frequency has to be
reduced r: ');
md=decimate(m,r);
figure(1);
subplot(3,1,1);
plot(t,m);
grid;
xlabel('t-->');
ylabel('Amplitude-->');
title('Sinusoidal signal before sampling');
subplot(3,1,2);
stem(m);
grid;
xlabel('n-->');
ylabel('Amplitudes of m -->');
15
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
title('Sinusoidal signal after sampling before decimation');
subplot(3,1,3);
stem(md);
grid;
title('Sinusoidal after decimation');
xlabel('n/r-->');
ylabel('Amplitude of md-->');
% INTERPOLATION
clc;
clear all;
close all;
disp('Let us take a sinusoidal sequence which has to be interpolated: ');
fm=input('Enter the signal frequency fm: ');
fs=input('Enetr the sampling frequnecy fs: ');
T=input('Enter the duration of the signal in seconds T: ');
dt=1/fs;
t=dt:dt:T
M=length(t);
m=cos(2*pi*fm*t);
r=input('Enter the factor by which the sampling frequency has to be
increased r: ');
md=interp(m,r);
figure(1);
subplot(3,1,1);
plot(t,m);
grid;
xlabel('t-->');
ylabel('Amplitude-->');
title('Sinusoidal signal before sampling');
subplot(3,1,2);
stem(m);
grid;
xlabel('n-->');
ylabel('Amplitudes of m -->');
title('Sinusoidal signal after sampling before interpolation');
subplot(3,1,3);
stem(md);
grid;
title('Sinusoidal after interpolation');
xlabel('n x r-->');
ylabel('Amplitude of md-->');
16
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS:
Amplitude of md-->
Amplitudes of m -->
Amplitude-->
Sinusoidal signal before sampling
1
0
-1
0
0.1
0.2
0.3
0.4
0
0
0.5
0.6
0.7
0.8
t-->
Sinusoidal signal after sampling before decimation
10
20
30
40
5
10
15
0.9
1
80
90
100
40
45
50
1
0
-1
50
60
70
n-->
Sinusoidal after decimation
1
0
-1
20
25
n/r-->
17
30
35
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
Amplitude of md-->
Amplitudes of m -->
Amplitude-->
Sinusoidal signal before sampling
1
0
-1
0
0.1
0.2
0.3
0.4
0
0
0.5
0.6
0.7
0.8
t-->
Sinusoidal signal after sampling before interpolation
10
20
30
40
20
40
60
80
0.9
1
80
90
100
160
180
200
1
0
-1
50
60
70
n-->
Sinusoidal after interpolation
2
0
-2
100
n x r-->
120
140
INFERENCE : The only constraint about the program is that the factors of decimation or
interpolation should be an integers. If we want to change the sampling frequency by a
factor which is not an integer it can be done by using the command resample by which we
can change the sampling rate by a factor I / D. For this we have to interpolate by an integer
factor I and then decimate by an integer factor D
RESULT : The Decimation and Interpolation of given sequences is verified and graphs
are plotted.
18
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
5. PROGRAM TO CONVERT CD DATA INTO DVD DATA
AIM : To convert the CD data into DVD data.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : In this program the CD data is converted into DVD data
by using the command “resample”. Here the CD data is of the sampling frequency 44.1
kHz and the DVD data is of the sampling frequency 96.0 kHz. This is also one kind of
sampling rate conversion by a factor. In this program first we generate the CD signal and
from that we generate the decimated version by downsampling it and upsampling results in
DVD data in a sampled version. Then plot the CD data and DVD data signals.
PROGRAM :
clc;
clear all;
close all;
fm=input('enter the signal frequency fm:');
fs=input('enter the sampling frequency fs:');
T=input('enter the duration of the signal in seconds:');
dt=1/fs;
t=0:pi/100:pi
m=sin(2*pi*fm*t);
subplot(411);
plot(m);
xlabel('time-->');
ylabel('amplitude-->');
subplot(412);
stem(m);
xlabel('time-->');
ylabel('amplitude-->');
y=resample(m,96,44);
subplot(413)
stem(y);
xlabel('time-->');
ylabel('amplitude-->');
subplot(414)
plot(y);
xlabel('time-->');
ylabel('amplitude-->');
OUTPUTS:
enter the signal frequency fm:2
enter the sampling frequency fs:100
enter the duration of the signal in seconds:1
19
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
amplitude-->
amplitude-->
amplitude-->
amplitude-->
GRAPHS :
1
0
-1
0
20
40
60
time-->
80
100
120
0
20
40
60
time-->
80
100
120
1
0
-1
2
0
-2
0
50
100
150
200
250
150
200
250
time-->
2
0
-2
0
50
100
time-->
INFERENCE : This program is similar to resampling of the signal by a factor of
96000/41000. Since CD data is of the frequency 44.1 kHz and DVD data is of 96 kHz. We
have to use the resample command only to carryout this experiment. Another way of doing
this is to Interpolate the given signal by a factor of 96000 and then decimate by 44100.
RESULT : Hence the CD data is converted into DVD data and the graphs are plotted.
20
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
6. GENERATION OF DUAL TONE MULTIPLE FREQUENCY (DTMF) SIGNALS
AIM: To generation of dual tone multiple frequency ( DTMF ) signals.
SOFTWARE REQUIRED: MAT LAB 7.0
PROGRAM DESCRIPTION: In this program the Dual tone multiple frequency signal
which is used in telephone systems is generated. A DTMF signal consists of a sum of two
tones, with frequencies taken from two mutually exclusive groups of preassigned
frequencies. Each pair of such tones represents a unique number or a symbol. Decoding of
a DTMF signal thus involves identifying the two tones in that signal and determining their
corresponding number or symbol.
PROGRAM:
clc;
clear all;
close all;
number=input('enter a phone number with no spaces:','s');
fs=8192;
T=0.5;
x=2*pi*[697 770 852 941];
y=2*pi*[1209 1336 1477 1602];
t=[0:1/fs:T]';
tx=[sin(x(1)*t),sin(x(2)*t),sin(x(3)*t),sin(x(4)*t)]/2;
ty=[sin(y(1)*t),sin(y(2)*t),sin(y(3)*t),sin(y(4)*t)]/2;
for k=1:length(number)
switch number(k)
case'1'
tone=tx(:,1)+ty(:,1);
sound(tone);
plot(tone);
case'2'
tone=tx(:,1)+ty(:,2);
sound(tone);
plot(tone);
case'3'
tone=tx(:,1)+ty(:,3);
sound(tone);
plot(tone);
21
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
case'A'
tone=tx(:,1)+ty(:,4);
sound(tone);
plot(tone);
case'4'
tone=tx(:,2)+ty(:,1);
sound(tone);
plot(tone);
case'5'
tone=tx(:,2)+ty(:,2);
sound(tone);
plot(tone);
case'6'
tone=tx(:,2)+ty(:,3);
sound(tone);
plot(tone);
case'B'
tone=tx(:,2)+ty(:,4);
sound(tone);
plot(tone);
case'7'
tone=tx(:,3)+ty(:,1);
sound(tone);
plot(tone);
case'8'
tone=tx(:,3)+ty(:,2);
sound(tone);
plot(tone);
case'9'
tone=tx(:,3)+ty(:,3);
sound(tone);
plot(tone);
case'C'
tone=tx(:,3)+ty(:,4);
sound(tone);
plot(tone);
case'#'
tone=tx(:,4)+ty(:,1);
sound(tone);
plot(tone);
case'0'
tone=tx(:,4)+ty(:,2);
22
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
sound(tone);
plot(tone);
case'*'
tone=tx(:,4)+ty(:,3);
sound(tone);
plot(tone);
case'D'
tone=tx(:,4)+ty(:,4);
sound(tone);
plot(tone);
otherwise
disp('invalid number');
end;
pause(0.75);
end;
OUTPUT:
enter a phone number with no spaces: 936
GRAPHS:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
500
1000
1500
2000
2500
23
3000
3500
4000
4500
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
500
1000
1500
2000
2500
3000
3500
4000
4500
0
500
1000
1500
2000
2500
3000
3500
4000
4500
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
24
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
INFERENCE: In this program the two frequencies which are going to produce the dual
tone when we press any button, that is why it is called Dual Tone Multiple Frequency
(DTMF). The only constraint is if the number we pressed is not there in the list then it will
generate the output as invalid number. But here the frequencies are fixed. If we want to
generate different tone we have to change the frequencies every time.
RESULT: Hence Dual Tone Multiple Frequency (DTMF) signals are generated and the
output is verified.
25
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
7. POWER SPECTRAL DENSITY USING SQUARE MAGNITUDE AND
AUTOCORRELATION
AIM : To compute the Power Spectral Density of given signals using square magnitude
and autocorrelation
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The stationary random processes do not have finite energy
and hence do not processes a Fourier Transform. Such signals have finite average power
and hence are characterized by a Power Density Spectrum or Power Spectral Density
(PSD). In this program we have used the property of PSD that it can be calculated from its
autocorrelation function by taking the time average. In the Square magnitude method after
taking the FFT by taking the absolute value we get the PSD.
PROGRAM :
clc;
clear all;
close all;
f1=input('Enter the frequency of first sequence in Hz: ');
f2=input('Enter the frequency of the second sequence in Hz: ');
fs=input('Enter the sampling frequency in Hz: ');
t=0:1/fs:1
x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t));
px1=abs(fft(x).^2)
px2=abs(fft(xcorr(x),length(t)));
subplot(211)
plot(t*fs,10*log10(px1));%square magnitude
grid;
xlabel('Freq.in Hz-->');
ylabel('Magnitude in dB-->');
title('PSD using square magnitude method');
subplot(212)
plot(t*fs,10*log10(px2));%autocorrelation
grid;
xlabel('Freq.in Hz-->');
ylabel('Magnitude in dB-->');
title('PSD using auto correlation method');
OUTPUTS:
Enter the frequency of first sequence in Hz: 200
Enter the frequency of the second sequence in Hz: 400
Enter the sampling frequency in Hz: 1000
26
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPHS :
PSD using square magnitude method
Magnitude in dB-->
100
50
0
-50
0
100
200
0
100
200
300
400
500
600
700
Freq.in Hz-->
PSD using auto correlation method
800
900
1000
800
900
1000
Magnitude in dB-->
60
50
40
30
300
400
500
600
Freq.in Hz-->
700
INFERENCE : The only constraint is to take the two frequencies must be two time lesser
than the sampling frequencies.
RESULT : Hence the PSD is computed using the square magnitude and Autocorrealtion
and graph is plotted.
27
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
8. POWER SPECTRAL DENSITY USING PERIODOGRAM
AIM : To compute the Power Spectral Density of given signals using Periodoram
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The stationary random processes do not have finite energy
and hence do not processes a Fourier Transform. Such signals have finite average power
and hence are characterized by a Power Density Spectrum or Power Spectral Density
(PSD). The property of PSD that it can be calculated from its autocorrelation function by
taking the time average. In the Square magnitude method after taking the FFT by taking the
absolute value we get the PSD. Here we used the command periodogram to estimate the
PSD of the given signal of 200 Hz frequency.
PROGRAM :
clc;
clear all;
close all;
Fs=1000;
t=0:1/Fs:0.3
x=cos(2*pi*t*200)+0.1*randn(size(t));
periodogram(x,[ ],'twosided',512,Fs);
GRAPHS:
Periodogram Power Spectral Density Estimate
-10
Power/frequency (dB/Hz)
-20
-30
-40
-50
-60
-70
0
100
200
300
400
500
600
Frequency (Hz)
700
800
900
INFERENCE : In the computation of the PSD here we are using the command
periodogram so it very simple to generate the PSD of the given signal and the output is
verified and can be compared with the other PSD generation methods.
RESULT : Hence the PSD is computed using the periodogram and graph is plotted.
28
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
9. POWER SPECTRAL DENSITY ESTIMATION USING PERIODOGRAM AND
MODIFEIED PERIODOGRAM
AIM : To compute the Power Spectral Density of given signals using Periodogram and
Modified periodogram
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The stationary random processes do not have finite energy
and hence do not processes a Fourier Transform. Such signals have finite average power
and hence are characterized by a Power Density Spectrum or Power Spectral Density
(PSD). The property of PSD that it can be calculated from its autocorrelation function by
taking the time average. In the Square magnitude method after taking the FFT by taking the
absolute value we get the PSD. The same can be calculated using periododram and
modified periodogram methods.
PROGRAM :
%% clearing screen
clc;
close all;
clear all;
%% psd calculation using fft
t = 0:1023;
x = sin(2*pi*50/1000*t)+sin(2*pi*120/1000*t);
y = x+randn(size(t));
N=length(y);
f1=1000*(0:N/2-1)/N;
p=abs(fft(y).^2)/N;
subplot(221);
plot(f1,10*log10(p(1:512)));
grid;
xlabel('frequency-->');
ylabel('Power in dB-->');
title(' PSD estimation using fft')
%% psd calculation using periodogram
[Pxx,w]=periodogram(y);
subplot(222);
plot(1000*w/(2*pi),10*log10(Pxx));
grid;
xlabel('frequency-->');
ylabel('Power in dB-->');
title('PSD using periodogram');
%% psd calculation using modified periodogram
w=hanning(N);
[Pxx,w]=periodogram(y,w);
subplot(223);
plot(1000*w/(2*pi),10*log10(Pxx));
grid;
xlabel('frequency-->');
ylabel('Power in dB-->');
title('Modified periodogram');
%% psd calculation using auto correlation and fft
29
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
z=xcorr(y);
m=length(z);
g1=abs(fft(z));
n2=1000*(0:(m/2)-1)/m;
subplot(224);
plot(n2,10*log10(g1(1:1023)));
grid;
xlabel('frequency-->');
ylabel('Power in dB-->');
title('PSD estimate by auto correlation and fft')
GRAPHS :
PSD estimation using fft
PSD using periodogram
20
Power in dB-->
Power in dB-->
40
20
0
-20
-40
0
200
400
frequency-->
Modified periodogram
200
400
600
frequency-->
PSD estimate by auto correlation and fft
60
Power in dB-->
Power in dB-->
20
-20
-40
-60
0
200
400
frequency-->
600
-20
-40
600
0
0
0
40
20
0
-20
0
200
400
frequency-->
600
INFERENCE : In the computation of the PSD here we are using the command
periodogram and modified periodogram is estimated by using the hanning window. So it
very simple to generate the PSD of the given signal and the output is verified and it is
compared with the other PSD generation methods.
RESULT : Hence the PSD is estimated and compared with different methods.
30
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
10. POWER SPECTRAL DENSITY ESTIMATION USING BARLETT METHOD
AIM : To estimate the Power Spectral Density using Barlett method
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation
function of a signal by taking its the Fourier transform, called the periodogram. In general
the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus
“The periodogram is not a consistent estimate of the true power density spectrum”
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum
suffers from the smoothing effects and the leakage embodied in the Barlett window. The
smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The
methods Barlett along with Blackman Tukey and Welch are classical methods and make no
assumption about how the data were generated and hence called nonparametric methods.
In this method for reducing the variance in the periodogram involves three steps:
1. First the N-point sequence is subdivided into K nonoverlapping segments, where
segment has length M.
2. For each segment we compute the periodogram.
3. Finally, we average the periodograms for the K segments to obtain the Barlett
power spectrum estimate.
Thus Barlett method is called as Averaging Periodograms.
PROGRAM:
clc;
close all;
clear all;
t=0:1023
x=sin(2*pi*50/1000*t)+sin(2*pi*120/1000*t);
y=x+randn(size(t));
N=length(y);
k=4;
M=N/k;
x1=y(1:M);
x2=y(M+1:2*M);
x3=y(2*M+1:3*M);
x4=y(3*M+1:4*M);
px41=(1/M)*((abs(fft(x1))).^2);
px42=(1/M)*((abs(fft(x2))).^2);
px43=(1/M)*((abs(fft(x3))).^2);
px44=(1/M)*((abs(fft(x4))).^2);
px5=(px41+px42+px43+px44)/k;
n1=1000*(0:M/2)/M;
plot(n1,px5(1:M/2+1));
grid;
xlabel('Normalized frequency in Hz -->');
ylabel('-->Power Spectrum in dB');
title('PSD ESTIMATION USING BARLETT METHOD');
31
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPH:
PSD ESTIMATION USING BARLETT METHOD
60
-->Power Spectrum in dB
50
40
30
20
10
0
0
50
100
350
300
250
200
150
Normalized frequency in Hz -->
400
450
500
INFERENCE : Estimation of Power Spectral Density using Barlett method is observed
from the graph.
RESULT : Hence the PSD is estimated using Barlett method.
32
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
11. POWER SPECTRAL DENSITY ESTIMATION USING WELCH METHOD
AIM : To estimate the Power Spectral Density using Welch method
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation
function of a signal by taking its the Fourier transform, called the periodogram. In general
the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus
“The periodogram is not a consistent estimate of the true power density spectrum”
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum
suffers from the smoothing effects and the leakage embodied in the Barlett window. The
smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The
methods Barlett along with Blackman Tukey and Welch are classical methods and make no
assumption about how the data were generated and hence called nonparametric methods.
Welch made two modifications to the Barlett method.
1. First, he allowed the data sequence to overlap.
2. The second modification made by Welch to the Barlett method is to window the
data segments prior to computing the periogram.
Thus Welch method is called as Modified Periodogram.
PROGRAM:
clc;
close all;
clear all;
fs=1024;
f1=200;
f2=400;
M=128;
t=0:1/fs:1;
x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+rand(size(t));
L=length(x);
K=L/M;
wi=hann(M+1);
m=0;
su=[];
for i=1:M/2:L-M+1
y=wi'.*x(i:M+i);
w2=abs(fft(y).^2);
su=[su;w2];
end;
su1=sum(su);
su2=sum(wi.^2);
w1=su1/su2;
w12=10*log(w1);
fs1=(fs/K)+2;
t1=((1:fs1)/fs1);
33
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
plot(t1,w12);
grid;
xlabel('Normalized frequency -->');
ylabel('-->Power Spectrum in dB');
title('Welch method of Power Spectrum Estimation');
GRAPH:
Welch method of Power Spectrum Estimation
60
-->Power Spectrum in dB
50
40
30
20
10
0
-10
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized frequency -->
0.8
0.9
1
INFERENCE : Estimation of Power Spectral Density using Welch method is observed
from the graph.
RESULT : Hence the PSD is estimated using Welch method.
34
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
12. PSD ESTIMATION USING BLACKMAN AND TUKEY METHOD
AIM : To estimate the Power Spectral Density using Blackman and Tukey method.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The PSD can be calculated from the autocorrelation
function of a signal by taking its the Fourier transform, called the periodogram. In general
the variance of the estimate Pxx ( f ) does not decay to zero as N tends to infinity. Thus
“The periodogram is not a consistent estimate of the true power density spectrum”
i.e., it does not converge to the true power density spectrum. Thus the estimated spectrum
suffers from the smoothing effects and the leakage embodied in the Barlett window. The
smoothing and leakage ultimately limit our ability to resolve closely spaced spectra. The
methods Barlett along with Blackman Tukey and Welch are classical methods and make no
assumption about how the data were generated and hence called nonparametric methods.
Blackman and Tukey proposed and analyzed the method in which the sample
autocorrelation sequence is windowed first and then Fourier transformed to yield the
estimate of the power spectrum.
PROGRAM:
clc;
close all;
clear all;
fs=1024;
f1=200;
f2=400;
M=128;
t=0:1/fs:1;
x=sin(2*pi*f1*t)+sin(2*pi*f2*t)+rand(size(t));
L=length(x);
y=xcorr(x);
wi=hann(length(y));
y1=wi'.*y;
i=length(y);
b=abs(fft(xcorr(y1)))/L;
i1=length(b);
t1=(1:i1)/i1;
b1=10*log(b);
plot(t1,b1);
grid;
xlabel('Normalized frequency -->');
ylabel('-->Power Spectrum in dB');
title('Blackman and Tukey method of Power Spectrum Estimation');
35
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPH:
Blackman and Tukey method of Power Spectrum Estimation
200
-->Power Spectrum in dB
150
100
50
0
-50
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized frequency -->
0.8
0.9
1
INFERENCE : Estimation of Power Spectral Density using Blackman and Tukey method
is observed from the graph.
RESULT : Hence the PSD is estimated using Blackman and Tukey method.
36
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
13. POWER SPECTRUM ESTIMATION USING YULE-WALKER METHOD
(PARAMETRIC METHOD)
AIM : To estimate the Power Spectral Density using Yule-Walker method.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The Power Spectral Density can be calculated by Barlett
along with Blackman Tukey and Welch are the classical methods and make no assumption
about how the data were generated and hence called nonparametric methods. The
nonparametric power spectrum estimation methods require the availability of long data
records in order to obtain the necessary frequency resolution required in many applications.
The limitations of nonparametric methods:
1. The inherent assumption that the auto correlation estimate is zero for m >= N.
2. Another inherent assumption is that in the periodogram estimate the data are
periodic with period N.
Neither one of these assumptions is realistic.
The modeling approach eliminates the need for window functions and the assumption that
the auto correlation is zero for |m| >= N. As a consequence, Parametric ( model-based )
power spectrum estimation methods avoid the problem of leakage and provide better
resolution than do the FFT based, nonparametric methods. The Yule-Walker and Burg
methods are called Parametric methods of Power Spectrum Estimation.
Yule-Walker method: The Yule-walker method estimates simply the auto correlation
from the data and use the estimates to solve for the AR model parameters.The result is a
stable AR model.
PROGRAM:
clc;
close all;
clear all;
a=[1 -2.2137 2.9408 -2.1697 0.9609]; % AR filter coefficients
randn('state',1);
x=filter(1,a,randn(256,1));
% AR system output
pyulear(x,4);
% Fourth-order estimate
xlabel('Normalized frequency -->');
ylabel('-->Power Spectrum in dB');
title('Yule-Walker method of Power Spectrum Estimation');
37
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPH:
Yule-Walker method of Power Spectrum Estimation
30
-->Power Spectrum in dB
20
10
0
-10
-20
-30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized frequency -->
0.8
0.9
1
INFERENCE : Estimation of Power Spectral Density using Yule-Walker method is
observed from the graph.
RESULT : Hence the PSD is estimated using Yule-Walker method.
38
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
14. POWER SPECTRUM ESTIMATION USING BURG METHOD
(PARAMETRIC METHOD)
AIM : To estimate the Power Spectral Density using Burg method.
SOFTWARE REQUIRED : MAT LAB 7.0
PROGRAM DESCRIPTION : The Power Spectral Density can be calculated by Barlett
along with Blackman Tukey and Welch are the classical methods and make no assumption
about how the data were generated and hence called nonparametric methods. The
nonparametric power spectrum estimation methods require the availability of long data
records in order to obtain the necessary frequency resolution required in many applications.
The limitations of nonparametric methods:
3. The inherent assumption that the auto correlation estimate is zero for m >= N.
4. Another inherent assumption is that in the periodogram estimate the data are
periodic with period N.
Neither one of these assumptions is realistic.
The modeling approach eliminates the need for window functions and the assumption that
the auto correlation is zero for |m| >= N. As a consequence, Parametric ( model-based )
power spectrum estimation methods avoid the problem of leakage and provide better
resolution than do the FFT based, nonparametric methods. The Yule-Walker and Burg
methods are called Parametric methods of Power Spectrum Estimation.
Burg method: The method devised by Burg for estimating the AR parameters can be
viewed as an order recursive least squares lattice method, based on the minimization of the
forward and backward errors in linear predictors, with the constraint that the AR
parameters satisfy the Levinson-Durbin recursion.
PROGRAM:
clc;
close all;
clear all;
a=[1 -2.2137 2.9408 -2.1697 0.9609]; % AR filter coefficients
randn('state',1);
x=filter(1,a,randn(256,1));
% AR system output
pburg(x,4);
% Fourth-order estimate
xlabel('Normalized frequency -->');
ylabel('-->Power Spectrum in dB');
title('Burg method of Power Spectrum Estimation');
39
ACTS,DEPT. OF ECE
ADSP LAB MANUAL
GRAPH:
Burg method of Power Spectrum Estimation
30
-->Power Spectrum in dB
20
10
0
-10
-20
-30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized frequency -->
0.8
0.9
1
INFERENCE : Estimation of Power Spectral Density using Burg method is observed from
the graph.
RESULT : Hence the PSD is estimated using Burg method.
40
Download