8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 1/12
PROJECT REPORT-1
DIGITAL SIGNAL PROCESSING
ELEN 5316/4304
Instructor: Dr.Gleb Tcheslavski
10/13/2010
Submitted by:
Md. Khairuzzaman-L20258945
Adhitya Govardhanam-L20238253
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 2/12
1. Implement one clock-cycle of the Fundamental form of the Signal Flow Graph as a
stand alone Matlab module/function. Your module should be able to implement an
arbitrary SOS: compute the output and the next states for the given input,
states, and filter’s coefficients.
Solution:
For the Fundamental Direct form SFG (for SOS):
[] = +
Output
The MATLAB coding for Fundamental Direct form SFG:
1. function [y,Sn] = SFG(x,a,b,S1,S2,S3,S4)
% Function for a Fundamental Direct form SFG for SOS
% inputs:
% x = input signal % a = [a0,a1,a2] b = [b0,b1,b2] % S1, S2, S3, S4 = initial states of the system
% outputs: % y = output signal % Sn = Matrix for next states of the system
2. a = a/a(1); % normalization of the coefficients b = b/a(1);
3. if nargin < 7, S4 = 0; end % set S1, S2, S3, S4 if not designated if nargin < 6, S3 = 0; end if nargin < 5, S2 = 0; end if nargin < 4, S1 = 0; end
4. N = length(x); % length of input vector
5. y = zeros(N,1); % pre-allocating y
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 3/12
6. Sn = [S1; S2; S3; S4]; % Set initial value of states
7. % State-Space Description
A = [0 0 0 0; 1 0 0 0; b(2) b(3) -a(2) -a(3); 0 0 1 0]; B = [1; 0; b(1); 0]; Ct = [b(2) b(3) -a(2) -a(3)]; D = b(1);
8. for n = 1:N
y(n) = Ct*Sn + D*x(n); % calculates the nth element of y
Sn = A*Sn + B*x(n); % calculates the next states end
Description of above steps:
In step -1, SFG is a MATLAB function whose inputs are x, a, b, S1, S2, S3, S4
and the outputs are y, Sn (here Sn is a matrix contains next states of the system)
respectively. x contains values of input signal, whereas S1, S2, S3 & S4 are the
initial states of the system. a and b are three element vectors with elements
a0,a1,a2 and b0, b1, b2. The output y contains values of output signal and Sn
matrix contains next states of the system.
In step-2, the function does normalization of the coefficients. In step-3, the function sets the values of S1, S2, S3 and S4 to 0, if the are not
given by the user when the function is called.
In step-4, the length of the input vector x, is measured by the function and saved
in the variable N. This allows to know how many iterations the program must take
and the size the vector made to pre-allocate memory for the output needs to be.
In step-5, the function pre allocates the vector y as zeroes.
In step-6, the function sets initial values of S1, S2, S3, S4 into output Sn.
In step-7, the function calculates 4 vectors for state-space description (A, B, Ct,
D). In step-8, the function calculates the value of y and Sn.
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 4/12
2. Test your module to verify its correct functionality. Hint : remember that t he SFG is
an implementation of LCCDE.
Solution:
In this part, we load coefficient from P1_coeff.mat to obtain the values of a and b. Now,we randomly select three values for x as [1 17 36] and we calculate the output using the
function SFG( ) assuming S1, S2, S3, S4 are zero. So now, we recalculate the values
manually using the formulas listed below:
MATLAB Calculations:
>> load P1_coeff.mat
>> x = [1 17 36];
>> [y, Sn] = SFG(x, a, b)
y =
0.1497
2.7849
9.7209
>> Sn
Sn =
36.0000
17.0000
9.7209
2.7849
>> a
a = 1.0000 -1.2944 0.6400
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 5/12
>> b
b = 0.1497 0.0462 0.0374
Formulas :
Here, a0 = 1; a1 = -1.2944; a2 = 0.64; b0 = 0.1479; b1 = 0.0462; b2 = 0.0374
Clock-cycle 1
x1 = 1; S1,1 = 0; S2,1 = 0; S3,1 = 0; S4,1 = 0;
y1 = 0.0462*0 + 0.0374*0 – (-1.2944)*0 – 0.64*0 + 0.1479*1 = 0.1479
S1,2 = x1 = 1
S2,2 = S1,1 = 0
S3,2 = 0.0462*0 + 0.0374*0 – (-1.2944)*0 – 0.64*0 + 0.1479*1 = 0.1479
S4,2 = S3,1 = 0
Clock-cycle 2
x2 = 17; S1,2 = 1; S2,2 = 0; S3,2 = 0.1479; S4,2 = 0;
y2 = 0.0462*1 + 0.0374*0 – (-1.2944)*0.1479 – 0.64*0 + 0.1479*17 = 2.7520
S1,3 = x2 = 17
S2,3 = S1,2 = 1
S3,3 = 0.0462*1 + 0.0374*0 – (-1.2944)*0.1479 – 0.64*0 + 0.1479*17 = 2.7520
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 6/12
S4,3 = S3,2 = 0.1479
Clock-cycle 3
x3 = 36; S1,3 = 17; S2,3 = 1; S3,3 = 2.7520; S4,3 = 0.1479;
y3 = 0.0462*17 + 0.0374*1 – (-1.2944)*2.7520 – 0.64*0.1479 + 0.1479*36 = 9.6147
S1,4 = x3 = 36
S2,4 = S1,3 = 17
S3,4 = 0.0462*17 + 0.0374*1 – (-1.2944)*2.7520 – 0.64*0.1479 + 0.1479*36 = 9.6147
S4,4 = S3,3 = 2.7520
3. Load the f ilter coefficients from the file P1_coe ff .mat by the command:
“load P1_coe ff .mat ”. Inspect the given coefficients. What wil l yo u
conclude about the resulting filter’s stability in BIBO sense? Verify by
appropriate tests.
Solution
Coefficient Stability Test:
The coefficients loaded from "P1_coeff.mat" are
a = [1, -1.2944, 0.64] = [a0, a1, a2], and
b = [0.1497, 0.0462, 0.0374] = [b0, b1, b2].
The tests for BIBO stability of a SOS are
|a1| < 1 + a2, and
|a2| < 1.
We tested for BIBO stability using the above equations and acquired
|a1| = |-1.2944| = 1.2944 < 1 + 0.64 = 1.64, and
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 7/12
|a2| = 0.64 < 1.
Since the system meets these requirements the system is BIBO stable.
MATLAB Stability Test code
>> load P1_coeff.mat
>> x = rand (1000, 1);
>> [y, Sn] = SFG(x, a, b);
>> plot(y)
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 8/12
Conclusions:
Also we tested the stability by inputting a vector of 1000 randomly generated numbers
and graphed the output of the function in the above graph. Then we checked the graph of
the output to see if the function remains stable. Since the plot of the output does not
shout up towards infinity at any point on the graph we conclude that the system is stable.
4. Load the P1.wav file to your workspace by the command “wavread” . The
command “whos” will show you which variables you have in your workspace.
You can play the loaded sound by the command “ sound ” . Next, filter the signal
you loaded from the wav- file by the SOS of the system you have implemented
with the coeff icients given in vectors a and b. Hint : SFG represent one clock cycle…Play the filtered signal by the command sound . What are your observations?
Hint : you may save your filtered signal in another wav-f ile and play it later on
another computer by any multimed ia player. You would need to use the command
“wavwr it e” in this case. Note: depending on a CPU, t he filter ing may take
several minutes!
Solution:
>> load P1_coeff.mat
>> x1 = wavread('P1.wav');
>> whos
Name Size Bytes Class Attributes
a 1x3 24 double
b 1x3 24 double
x1 91781x1 734248 double
>> sound(x1)
>> [y1, Sn] = SFG(x1, a, b);
>> sound(y1)
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 9/12
Steps:
We first loaded the system coefficients from the "P1_coeff.mat" file.
Next we have loaded the "P1.wav" file using the "wavread" command and
saved it under the variable x1.
Next we played the original sound from x1 using the sound command. Then we filtered x1 and played the output, y1, using the sound command.
The difference from the original sound to the filtered sound was that the
noises have mostly been filtered out and the volume i.e. amplitude
attenuated also.
Conclusions:
This filter eliminates noises and attenuates the amplitude of the input signal.
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 10/12
5. Simulate a cascade of two identical SOS with the same coefficients and repeat
the filtering in 4. What are your observations?
Solution:
>> [y2, Sn] = SFG(y1,a,b);>> sound(y2)
Procedure:
We ran the output signal from question 4, y1, though the function a second time
using the same a, b, Sn parameters as we used in question 4.
Our observation is that the difference from the original sound to the filtered
sound was that the noises had been mostly filtered out.
6. (Graduate Students only) finally, determine whether any state and/or coefficient
scaling is needed to implement your module in hardware. Modify your SOS to implement
necessary scaling. Illustrate by an appropriate block diagram. Note: State and/or
coefficient scaling is not reall y required for a Matlab model: it ’ s important for the
hardware implementations. There f ore, the assignment DOES NOT ask you to perform
scaling; just make your module ready f or it
Solution: To verify the requirement of the state scaling, we need to check the condition
∑
And
Here,
8/4/2019 DSP Project 01
http://slidepdf.com/reader/full/dsp-project-01 11/12
MATLAB CODING:
function [h3_sum, hn] = sum_h(a, b, cs, n)
ct = [0 0 1 0]; A = [0 0 0 0; 1 0 0 0; cs*b(2) cs*b(1) -a(2) -a(3); 0 0 1 0]; b = [0; 0; cs*b(1); 0];
h3_sum = 0;
for i = 1:n hn = ct * A^(i-1) * b;
h3_sum = h3_sum + hn;end
Output:
>> [h3_sum, hn] = sum_h(a, b, 1, 10000)
h3_sum =
0.4332
hn =
0
Since the above condition is satisfied we do not need state scaling.
To verify the requirement of the coefficient scaling, we need to check the condition
From the stability triangle: || ||
And the coefficient value from P1_coeff.mat file is
Top Related