Page 1
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 1/44
LABORATORY MANUAL
SUBJECT: DIGITAL SIGNAL PROCESSING
STUDENT NAME : ……………………………………………………..
ROLL NUMBER :
…………………………………………………………
EXAM NUMBER : …………………………………………………………
SEMESTER : …………………………………………………………
YEAR : …………………………………………………………
Department of Electronics and Communication Engineering,
L.D.R.P. Institute of Technology and Research,
Gandhinagar,
Page 2
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 2/44
July – December 2009.
Page 3
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 3/44
CERTIFICATE
This is to certify that Shri....................................................................... Roll
no. ....................... of B.E. semester................................class has satisfactorily
completed the course in ........................................................................... within
four walls of L.D.R.P. Institute of Technology and Research, Gandhinagar.
Date: Staff-in-charge Head of the dept.
CERTIFICATE
This is to certify that the above term work of
Shri.............................................................. University Exam. No. .................... of
B.E. Semester................................ is assessed for University examination.
Date: Examiner
Page 4
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 4/44
INDEX
Sr.
No. Objective DatePage
No SignatureRemarks
1 Generation of Unit
Sample Sequence.
2 Generation of a complex
exponential sequence
3 Generation of a realexponential sequence
4 Generation of asinusoidal sequence
5 Signal Smoothing by
Averaging
6 Generation of amplitude
modulated sequence
7 Generation of a swept
frequency sinusoidalsequence
8 Generation of theensemble average
9 Generation of complexexponential sequence
10 Generation of realexponential sequence
11 Signal Smoothing by a
Moving-Average Filter
12 Illustration of Median
Filtering
13 Illustration of
Convolution
14 Computation of
Autocorrelation of a
Noise CorruptedSinusoidal Sequence
15 Illustration of Up-
Sampling by an IntegerFactor
16 Illustration of Down-
Sampling by an Integer
Factor
Page 5
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 5/44
Page 6
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 6/44
Practical: 1
Date: ________
Aim: Generation of Unit Sample Sequence.
Program Code:
% Generate a vector from -10 to 20n = -10:20;
% Generate the unit sample sequenceu = [zeros(1, 10) 1 zeros(1,20)];
% Plot the unit sample sequencestem(n,u);
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Unit Sample Sequence’);
axis([-10 20 0 1.2]);
Output:
-10 -5 0 5 10 15 200
0.2
0.4
0.6
0.8
1
Timeindexn
A m p l i t u d e
Unit SampleSequence
Page 7
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 7/44
Signature:__________
Practical: 2
Date:__________
Aim: Generation of a complex exponential sequence
Program Code:
c = -(1/12)+(pi/6)*i;
K = 2;n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel(’Time index n’);ylabel(’Amplitude’);title(’Real part’);
subplot(2,1,2);stem(n,imag(x));
xlabel(’Time index n’);ylabel(’Amplitude’);title(’Imaginary part’);
Output:
0 5 10 15 20 25 30 35 40-2
-1
0
1
2
Timeindexn
A m p l i t u d e
Real part
0 5 10 15 20 25 30 35 40-1
0
1
2
Timeindexn
A m p l i t u d e
Imaginarypart
Page 8
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 8/44
Signature:_________
Practical: 3
Date:_________
Aim: Generation of a real exponential sequence
Program Code:
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^+n;
stem(n,x);
xlabel(’Time index n’);ylabel(’Amplitude’);
Output:
0 5 10 15 20 25 30 350
20
40
60
80
100
120
Time index n
A m p l i t u d e
Signature:__________
Page 9
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 9/44
Practical: 4
Date:__________
Aim: Generation of a sinusoidal sequence
Program Code:
n = 0:40;f = 0.1;
phase = 0;A = 1.5;
arg = 2*pi*f*n - phase;x = A*cos(arg);
clf; % Clear old graphstem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);grid;
title(’Sinusoidal Sequence’);xlabel(’Time index n’);ylabel(’Amplitude’);axis;
Output:
Page 10
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 10/44
0 5 10 15 20 25 30 35 40-2
-1.5
-1
-0.5
0
0.5
1
1.5
2Sinusoidal Sequence
Timeindexn
A m p l i t u d e
Signature:__________
Practical: 5
Date:__________
Aim: Signal Smoothing by Averaging
Program Code:
R = 51;d = 0.8*(rand(R,1) - 0.5); % Generate random noise
m = 0:R-1;s = 2*m.*(0.9.^m); % Generate uncorrupted signal
x = s + d’; % Generate noise corrupted signalsubplot(2,1,1);
plot(m,d’,’r-’,m,s,’g--’,m,x,’b-.’);xlabel(’Time index n’);ylabel(’Amplitude’);
legend(’d[n] ’,’s[n] ’,’x[n] ’);x1 = [0 0 x];x2 = [0 x 0];x3 = [x 0 0];y = (x1 + x2 + x3)/3;
subplot(2,1,2);plot(m,y(2:R+1),’r-’,m,s,’g--’);
legend(’y[n] ’,’s[n] ’);
Page 11
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 11/44
xlabel(’Time index n’);ylabel(’Amplitude’);
Output:
0 5 10 15 20 25 30 35 40 45 50-5
0
5
10
Timeindexn
A m p l i t u d e
d[n]
s[n]x[n]
0 5 10 15 20 25 30 35 40 45 500
2
4
6
8
Timeindexn
A m p l i t u d e
y[n]
s[n]
Signature:_________
Practical: 6
Date:_________
Aim: Generation of amplitude modulated sequence
Program Code:
n = 0:100;m = 0.4;fH = 0.1; fL = 0.01;
xH = sin(2*pi*fH*n);xL = sin(2*pi*fL*n);
y = (1+m*xL).*xH;
stem(n,y);grid;xlabel(’Time index n’);ylabel(’Amplitude’);
Output:
Page 12
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 12/44
0 10 20 30 40 50 60 70 80 90 100-1.5
-1
-0.5
0
0.5
1
1.5
Time index n
A m p l i t u d e
Signature:________
Practical: 7
Date:__________
Aim: Generation of a swept frequency sinusoidal sequence
Program Code:
n = 0:100;a = pi/2/100;
b = 0;arg = a*n.*n + b*n;
x = cos(arg);clf;
stem(n, x);axis([0,100,-1.5,1.5]);
title(’Swept-Frequency Sinusoidal Signal’);xlabel(’Time index n’);
Page 13
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 13/44
Page 14
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 14/44
d = rand(R,1)-0.5;x = s + d';x1 = x1 + x;
end
x1 = x1/50;stem(m,x1);
xlabel('Time index n');ylabel('Amplitude'); title('Ensemble average');
Output:
0 5 10 15 20 25 30 35 40 45 50-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
Timeindexn
A m p l i t u
d e
Noise
Signature:________
Practical: 9
Date:__________
Aim: Generation of complex exponential sequence
Program Code:
a = input('Type in real exponent = ');b = input('Type in imaginary exponent = ');
c = a + b*i;
K = input('Type in the gain constant = ');N = input ('Type in length of sequence = ');n = 1:N;
x = K*exp(c*n); %Generate the sequence
stem(n,real(x)); %Plot the real part
Page 15
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 15/44
xlabel('Time index n');ylabel('Amplitude');title('Real part');
disp('PRESS RETURN for imaginary part');pause
stem(n,imag(x)); %Plot the imaginary partxlabel('Time index n');ylabel('Amplitude');title('Imaginary part');
Observation:
Type in real exponent = 5
Type in imaginary exponent = 6
Type in the gain constant = 67
Type in length of sequence = 68
Output:
Page 16
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 16/44
0 10 20 30 40 50 60 70-0.5
0
0.5
1
1.5
2
2.5
3x 10
149
Time index n
A m p l i t u d e
Real part
Signature:__________
Practical: 10
Date:__________
Page 17
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 17/44
Aim: Generation of real exponential sequence
Program Code:
a = input('Type in argument = ');K = input('Type in the gain constant = ');
N = input ('Type in length of sequence = ');
n = 0:N;x = K*a.^n;
stem(n,x);xlabel('Time index n');ylabel('Amplitude');title(['\alpha = ',num2str(a)]);
Observation:-
Type in argument = 3Type in the gain constant = 5Type in length of sequence = 6
Output:
0 1 2 3 4 5 60
0.5
1
1.5
2
2.5x10
4
Timeindexn
A m p l i t u d e
α= 4
Signature:__________
Practical: 11
Date:__________
Page 18
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 18/44
Aim: Signal Smoothing by a Moving-Average Filter
Program Code:
R = 50;
d = rand(R,1)-0.5;
m = 0:1:R-1;s = 2*m.*(0.9.^m);x = s + d';
plot(m,d,'r-',m,s,'b--',m,x,'g:')
xlabel('Time index n'); ylabel('Amplitude')legend('d[n]','s[n]','x[n]');
pause
M = input('Number of input samples = ');b = ones(M,1)/M;
y = filter(b,1,x);
plot(m,s,'r-',m,y,'b--')legend('s[n]','y[n]');
xlabel ('Time index n');ylabel('Amplitude')
Output:
0 5 10 15 20 25 30 35 40 45 50-1
0
1
2
3
4
5
6
7
8
Timeindexn
A m p l i t u d e
d[n]
s[n]
x[n]
Signature:_________
Practical: 12
Date:__________
Page 19
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 19/44
Aim: Illustration of Median Filtering
Program Code:
N = input('Median Filter Length = ');
R = 50; a = rand(1,R)-0.4;
b = round(a); % Generate impulse noisem = 0:R-1;s = 2*m.*(0.9.^m); % Generate signalx = s + b; % Impulse noise corrupted signaly = medfilt1(x,3); % Median filtering
subplot(2,1,1)
stem(m,x);axis([0 50 -1 8]);xlabel('n');ylabel('Amplitude');
title('Impulse Noise Corrupted Signal');
subplot(2,1,2)stem(m,y);xlabel('n');ylabel('Amplitude');title('Output of Median Filter');
Observation:
Number of input samples = 4
Median Filter Length = 5
Page 20
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 20/44
Output:
0 5 10 15 20 25 30 35 40 45 50
0
2
4
6
8
n
A m p l i t u d e
ImpulseNoiseCorruptedSignal
0 5 10 15 20 25 30 35 40 45 500
2
4
6
8
n
A m
p l i t u d e
Output of MedianFilter
Signature:__________
Page 21
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 21/44
Practical: 13
Date:__________
Aim: Illustration of Convolution
Program Code:
a = input('Type in the first sequence = ');
b = input('Type in the second sequence = ');
c = conv(a, b);M = length(c)-1;n = 0:1:M;
disp('output sequence =');disp(c)stem(n,c)
xlabel('Time index n'); ylabel('Amplitude');
Observation:
Type in the first sequence = 3
Type in the second sequence = 4output sequence = 12
Output:
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10
2
4
6
8
10
12
Timeindexn
A m p l i t u d e
Signature:__________
Page 22
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 22/44
Practical: 14
Date:__________
Aim: Computation of Autocorrelation of a Noise Corrupted Sinusoidal Sequence
Program Code:
N = 96;
n = 1:N;
x = cos(pi*0.25*n); % Generate the sinusoidal sequenced = rand(1,N) - 0.5; % Generate the noise sequence
y = x + d; % Generate the noise-corrupted sinusoidal sequence
r = conv(y, fliplr(y)); % Compute the correlation sequencek = -28:28;
stem(k, r(68:124));
xlabel('Lag index'); ylabel('Amplitude');
Output:
-30 -20 -10 0 10 20 30-60
-40
-20
0
20
40
60
Lagindex
A m p l i t u d e
Signature:__________
Page 23
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 23/44
Practical: 15
Date:__________
Aim: Illustration of Up-Sampling by an Integer Factor
Program Code:
N = input('Input length = ');L = input('Up-sampling Factor = ');
fo = input('Input signal frequency = ');
% Generate the input sinusoidal sequencen = 0:N-1;
x = sin(2*pi*fo*n);
% Generate the up-sampled sequencey = zeros(1, L*length(x));
y([1: L: length(y)]) = x;
% Plot the input and the output sequencessubplot(2,1,1)
stem(n,x);title('Input Sequence');
xlabel('Time index n');ylabel('Amplitude');
subplot(2,1,2)
stem(n,y(1:length(x)));
title(['Output sequence up-sampled by', num2str(L)]);
xlabel('Time index n');ylabel('Amplitude');
Observation:-
Input length = 4Up-sampling Factor = 5
Input signal frequency = 6
Page 24
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 24/44
Output:
0 0.5 1 1.5 2 2.5 3-6
-4
-2
0x10
-15 Input Sequence
Timeindexn
A m p l i t u d e
0 0.5 1 1.5 2 2.5 3-1
-0.5
0
0.5
1
Output sequenceup-sampledby5
Timeindexn
A m p l i t u d e
Signature:__________
Page 25
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 25/44
Practical: 16
Date:__________
Aim: Illustration of Down-Sampling by an Integer Factor
Program Code:
N = input('Output length = ');M = input('Down-sampling Factor = ');
fo = input('Input signal frequency = ');
% Generate the input sinusoidal sequencen = 0 : N-1;
m = 0 : N*M-1;
x = sin(2*pi*fo*m);
% Generate the down-sampled sequence
y = x([1 : M : length(x)]);
% Plot the input and the output sequencessubplot(2,1,1)
stem(n, x(1:N));title('Input Sequence');
xlabel('Time index n');ylabel('Amplitude');
subplot(2,1,2)
stem(n, y);
title(['Output sequence down-sampled by ',num2str(M)]);
ylabel('Amplitude');xlabel('Time index n');
Observation:
Input length = 4
Up-sampling Factor = 5Input signal frequency = 6Output length = 5Down-sampling Factor = 7
Input signal frequency = 8
Page 26
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 26/44
Output:
0 0.5 1 1.5 2 2.5 3 3.5 4-8
-6
-4
-2
0
x 10-15 Input Sequence
Time index n
A m p l i t u d e
0 0.5 1 1.5 2 2.5 3 3.5 4-6
-4
-2
0
2x 10
-14 Output sequence down-sampled by 7
A m p l i t u d e
Time index n
Signature:__________
Page 27
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 27/44
Practical: 17
Date:__________
Aim: Effect of Up-Sampling in the Frequency DomainUse fir2 to create a band limited input sequence
Program Code:
freq = [0 0.45 0.5 1];
mag = [0 1 0 0];x = fir2(99, freq, mag);
% Evaluate and plot the input spectrum[Xz, w] = freqz(x, 1, 512);
plot(w/pi, abs(Xz)); gridxlabel('\omega/\pi'); ylabel('Magnitude');title('Input spectrum');
pause
% Generate the up-sampled sequenceL = input('Type in the up-sampling factor = ');y = zeros(1, L*length(x));y([1: L: length(y)]) = x;
% Evaluate and plot the output spectrum
[Yz, w] = freqz(y, 1, 512);
plot(w/pi, abs(Yz)); gridxlabel('\omega/\pi'); ylabel('Magnitude');title('Output spectrum');
Page 28
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 28/44
Output:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
ω / π
M a g n i t u d e
Input spectrum
Signature:__________
Page 29
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 29/44
Practical: 18
Date:__________
Aim: Effect of Down-Sampling in the Frequency DomainUse fir2 to create a band limited input sequence
Program Code:
freq = [0 0.42 0.48 1];mag = [0 1 0 0];
x = fir2(101, freq, mag);
% Evaluate and plot the input spectrum
[Xz, w] = freqz(x, 1, 512);
plot(w/pi, abs(Xz)); grid
xlabel('\omega/\pi'); ylabel('Magnitude');title('Input spectrum');
pause
% Generate the down-sampled sequenceM = input('Type in the down-sampling factor = ');
y = x([1: M: length(x)]);
% Evaluate and plot the output spectrum
[Yz, w] = freqz(y, 1, 512);
plot(w/pi, abs(Yz)); gridxlabel('\omega/\pi'); ylabel('Magnitude');title('Output spectrum');
Page 30
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 30/44
Output:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
ω / π
M a g n i t u d e
Input spectrum
Signature:__________
Page 31
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 31/44
Practical: 19
Date:__________
Aim: Illustration of Interpolation Process
Program Code:
N = input('Length of input signal = ');L = input('Up-sampling factor = ');
f1 = input('Frequency of first sinusoid = ');f2 = input('Frequency of second sinusoid = ');
% Generate the input sequence
n = 0:N-1;
x = sin(2*pi*f1*n) + sin(2*pi*f2*n);
% Generate the interpolated output sequence
y = interp(x,L);
% Plot the input and the output sequencessubplot(2,1,1)
stem(n,x(1:N));title('Input sequence');
xlabel('Time index n'); ylabel('Amplitude');subplot(2,1,2)
m=0:N*L-1;stem(m,y(1:N*L));title('Output sequence');
xlabel('Time index n'); ylabel('Amplitude');
Observaton:
Length of input signal = 9Up-sampling factor = 9
Frequency of first sinusoid = 9Frequency of second sinusoid = 9
Page 32
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 32/44
Output:
0 1 2 3 4 5 6 7 8-6
-4
-2
0
2x 10
-14 Input sequence
Time index n
A m p l i t u d e
0 10 20 30 40 50 60 70 80-1
-0.5
0
0.5
1x 10
-13 Output sequence
Time index n
A m p l i t u d e
Signature:__________
Page 33
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 33/44
Practical: 20
Date:__________
Aim: Illustration of Sampling Rate Alteration by
a Ratio of Two Integers
Program Code:
N = input('Length of input signal = ');
L = input('Up-sampling factor = ');M = input('Down-sampling factor = ');
f1 = input('Frequency of first sinusoid = ');f2 = input('Frequency of second sinusoid = ');
% Generate the input sequence
n = 0:N-1;x = sin(2*pi*f1*n) + sin(2*pi*f2*n);
% Generate the resampled output sequence
y = resample(x,L,M);
% Plot the input and the output sequencessubplot(2,1,1)
stem(n,x(1:N));title('Input sequence');
xlabel('Time index n'); ylabel('Amplitude');subplot(2,1,2)
m=0:N*L/M-1;
stem(m,y(uint8(1:N*L/M)));title('Output sequence');xlabel('Time index n'); ylabel('Amplitude');
Observation:
Length of input signal = 9Up-sampling factor = 9
Down-sampling factor = 9Frequency of first sinusoid = 9
Frequency of second sinusoid = 9
Page 34
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 34/44
Output:
0 1 2 3 4 5 6 7 8-6
-4
-2
0
2x 10
-14 Input sequence
Time index n
A m p l i t u d e
0 1 2 3 4 5 6 7 8-6
-4
-2
0
2x 10
-14 Output sequence
Time index n
A m p l i t u d e
Signature:__________
Page 35
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 35/44
Practical: 21
Date:__________
Aim: Design of Lth Band FIR Filter Using theWindowed Fourier Series Approach
Program Code:
N = input('Type in the filter order = ');
L = input('Type in the value of L = ');n = -N/2:N/2;
% Generate the truncated impulse response of the ideal% lowpass filter
b = sinc(n/L)/L;
% Generate the window sequence
win = hamming(N+1);
% Generate the coefficients of the windowed filterc = b.*win';
% Plot the gain response of the windowed filter
[h,w] = freqz(c,1,512);
plot(w/pi,20*log10(abs(h)));grid
xlabel('\omega/\pi');ylabel('Gain, dB');title(['L-th band Nyquist Filter, L = ',num2str(L),]);
Observation:
Type in the filter order = 2
Type in the value of L = 3
Page 36
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 36/44
Output:
0 1 2 3 4 5 6 7 8-6
-4
-2
0
2x 10
-14 Input sequence
Time index n
A m p l i t u d e
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-11
-10
-9
-8
ω / π
G a i n ,
d B
L-th band Nyquist Filter, L = 3
Signature:__________
Page 37
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 37/44
Practical: 22
Date:__________
Aim: Frequency Responses of Johnston's QMF FiltersType in prototype lowpass filter coefficients
Program Code:
B1 = input('Filter coefficients = ');B1 = [B1 fliplr(B1)];
% Generate the complementary highpass filterL = length(B1);
for k = 1:LB2(k) = ((-1)^k)*B1(k);end
% Compute the gain responses of the two filters
[H1z, w] = freqz(B1, 1, 256);h1 = abs(H1z); g1 = 20*log10(h1);[H2z, w] = freqz(B2, 1, 256);h2 = abs(H2z); g2 = 20*log10(h2);
% Plot the gain responses of the two filters
plot(w/pi, g1,'-',w/pi, g2,'--');grid
xlabel('\omega/\pi'); ylabel('Gain, dB')pause
% Compute the sum of the squared-magnitude responsesfor i = 1:256,
sum(i) = (h1(i)*h1(i)) + (h2(i)*h2(i));end
d =10*log10(sum);
% Plot the amplitude distortion
plot(w/pi,d);grid;xlabel('\omega/\pi'); ylabel('Amplitude distortion, dB')
Observation:
Filter coefficients = 5
Page 38
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 38/44
Output:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-25
-20
-15
-10
-5
0
5
10
15
20
ω / π
G a i n ,
d B
Signature:__________
Page 39
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 39/44
Practical: 23
Date:__________
Aim: Spectrogram of a Speech Signal
Program Code:
load mtlb
n = 1:4001;
plot(n-1,mtlb);xlabel('Time index n');ylabel('Amplitude');pause
nfft = input('Type in the window length = ');ovlap = input('Type in the desired overlap = ');
specgram(mtlb,nfft,7418,hamming(nfft),ovlap)
Output:
0 500 1000 1500 2000 2500 3000 3500 4000-3
-2
-1
0
1
2
3
4
Time index n
A m p l i t u d e
Page 40
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 40/44
Signature:__________
Practical: 24
Date:__________
Aim: Power Spectrum Estimation Using Welch's Method
Program Code:
n = 0:1000;g = 2*sin(0.12*pi*n) + sin(0.28*pi*n) + randn(size(n));
nfft = input('Type in the fft size = ');window = hamming(256);noverlap =input('Type in the amount of overlap = ');
[Pxx, f] = psd(g,nfft,2,window,noverlap);
plot(f/2,10*log10(Pxx));grid
xlabel('\omega/\pi');ylabel('Power Spectrum, dB');title(['Overlap = ',num2str(noverlap),' samples']);
Output:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
0.2
0.4
0.6
0.8
1
1.2
1.4
ω / π
M a g n i t u d e
Page 41
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 41/44
Signature:__________
Practical: 25
Date:__________
Aim: Sigma-Delta Quantizer Operation
Program Code:
N = input('Type in the length of input sequence = ');n = 1:1:N;
m = n-1;
A = input('Type in the input amplitude = ');x = A*ones(1,N);
plot(m,x);axis([0 N-1 -1.2 1.2]);xlabel('Time'); ylabel('Amplitude');
title('Input analog signal');pause
y = zeros(1,N+1);
v0 = 0;for k = 2:1:N+1;
v1 = x(k-1) - y(k-1) + v0;y(k) = sign(v1);
v0 = v1;
endyn = y(2:N+1);axis([0 N-1 -1.2 1.2]);
stem(m, yn);xlabel('Time'); ylabel('Amplitude');
title('Output of sigma-delta modulator');
ave = sum(yn)/N;disp('Average value of output is = ');disp(ave);
Observation:
Type in the length of input sequence = 9
Type in the input amplitude = 6
Average value of output is =
Columns 1 through 7
11.1111 11.1111 11.1111 11.1111 11.1111 11.1111 11.1111
Page 42
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 42/44
Columns 8 through 9 11.1111 11.1111
Output:
0 1 2 3 4 5 6 7 80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time
A m p l i t u d e
Output of sigma-delta modulator
Signature:__________
Page 43
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 43/44
Practical: 26
Date:__________
Aim: Sigma-Delta A/D Converter Operation
Program Code:
wo = 2*pi*0.01;N = input('Type in the length of input sequence = ');n = 1:1:N;
m = n-1;
A = input('Type in the amplitude of the input = ');x = A*cos(wo*m);
axis([0 N-1 -1.2 1.2]);plot(m,x);xlabel('Time'); ylabel('Amplitude');title('Input analog signal');
pause
y = zeros(1,N+1);v0 = 0;
for k = 2:1:N+1;v1 = x(k-1) - y(k-1) + v0;
if v1 >= 0;
y(k) = 1;elsey(k) = -1;
endv0 = v1;
end
yn = y(2:N+1);axis([0 N-1 -1.2 1.2]);
stairs(m, yn);xlabel('Time'); ylabel('Amplitude');
title('Output of sigma-delta quantizer');
Y = fft(yn);pauseH = [1 1 0.5 zeros(1,N-5) 0.5 1];YF = Y.*H;
out = ifft(YF);axis([0 N-1 -1.2 1.2]);
plot(m,out);
Page 44
8/8/2019 Dsp Manual New
http://slidepdf.com/reader/full/dsp-manual-new 44/44
xlabel('Time'); ylabel('Amplitude');title('Lowpass filtered output');
Observation:
Type in the length of input sequence = 3
Type in the amplitude of the input = 2
Output:
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 21.984
1.986
1.988
1.99
1.992
1.994
1.996
1.998
2
2.002
Time
A m p l i t u d e
Input analog signal
Signature:__________