You are on page 1of 48

Solutions Manual for

Digital Communications
in Practice
Aldebaro - UFPA
September 13th , 2014

Contents
Listings
1 Analog and Digital Signals
1.1 Review Exercises . . . . . .
1.2 Exercises . . . . . . . . . .
1.3 Solutions: Review Exercises
1.4 Solutions: Exercises . . . .

iii
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

1
1
3
9
11

2 Transforms and Signal Representation


17
2.1 Review Exercises . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Analog and Digital Systems
3.1 Exercises . . . . . . . . . . . . . . .
3.2 Extra Exercises . . . . . . . . . . . .
3.3 Solutions: Exercises . . . . . . . . .
3.4 Solutions: Extra Exercises . . . . . .
3.5 Solutions: Exercises not in the book

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

23
23
28
30
38
39

Listings
1.1
1.2
1.3
1.4
1.5

1.7
1.8
1.9

MatlabOctaveCodeSnippets/snip_signals_2Drandom.m
3
MatlabOctaveCodeSnippets/snip_signals_sampling_inequality.m
Matlab/Octave code for this dB exercise . . . . . . . . .
9
Matlab/Octave code this dBm exercise . . . . . . . . . . 10
Matlab/Octave code for this exercise about digital interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Matlab/Octave code for this exercise about signal generation and analysis . . . . . . . . . . . . . . . . . . . . . 12
Matlab/Octave code this uniform quantization exercise . 13
Matlab/Octave code for this quantization exercise . . . 14
Matlab/Octave code for this sampling theorem exercise
15

2.1

MatlabOctaveCodeSnippets/snip_transforms_KLT.m .

19

3.1

MatlabOctaveCodeSnippets/snip_systems_buttord.m .

28

1.6

1 Analog and Digital Signals


1.1 Review Exercises
If you are familiar with the material, you probably want to skip this
section and check the exercises in Section 1.2.
One has a discrete-time sinusoid with amplitude A = 10 Volts
and wants to generate discrete-time AWGN with power P such that
the SNR equals 30 dB. What is the value of P in Watts? What are the
Matlab/Octave commands to generate both signals?

1.1.

Calculate by hand and plot the signal x[n] = Cean for n =


0, 1, . . . , 3, where C = 3 + j4 and a = 2 + j.

1.2.

What is the amplitude of a sinusoid x(t) with 30 dBm of power?


And the amplitude of another sinusoid y(t) with 30 dB more power
than x(t)? Is it correct to say that a signal has 30 dB of power? You
may want to read Appendix ?? for a discussion about dB.

1.3.

Assume that X is a discrete random variable (r.v.) with V distinct


values. Explain how to calculate its mean E[X] from

1.4.

E[X] =

V
X

p i xi ,

i=1

where pi is the probability of the i-th possible value xi . Compare this


procedure with the alternative calculation that sums N values and
divides by N . Interpret the equation E[X] when X R, i. e., X is a
continuous r.v.
To review the alternatives to represent complex numbers, let
a = 4ej0 and b = 3ej/2 be two complex numbers and calculate: c = ab,
d = a + b, |c| and c. Note that the following two forms of representing
complex numbers in the polar notation are equivalent: mej and m.

1.5.

Describe in details the header and summarize the contents (list


all the information you could extract from the header such as num-

1.6.

1 Analog and Digital Signals

ber of samples, sampling frequency, etc.) of the following companion files: tidigits_saa7.wav, timit_testdr8mpam0sx199.raw and
timit_testdr8mpam0sx199.wav. These are files that store speech waveforms (TIDIGITS and TIMIT are famous corpora distributed by LDC
[url1ldc]). Choose one of these files and analyze the corresponding
signal via plots (i. e., show the waveform with the abscissa and ordinate
properly labeled, and other graphs of interest such as the histogram
and PSD).
Using your favorite programming language, list the code for reading raw (without header) files storing two kinds of data: a) floats (4
bytes) in little-endian format and b) shorts (2 bytes) in big-endian
format.

1.7.

1.8.

Assume the random vector


X = [3; 2; 3; 2; 2; 0; 1; 0; 0; 3; 0; 2; 3; 2; 2; 3; 3; 0; 3; 2; 0].

a) Calculate its histogram. b) Estimate its probability mass function


(PMF). c) Calculate the moments: mean E[X], variance E[(X x )2 ]
and E[X2 ]. Estimate its entropy H = E[Ii ], where Ii = 1/pi is the
information associated to the i-th distinct value and pi the probability
P
of this value. Note that H = i pi Ii .
For calculating the variance using its definition E[(X x )2 ] one
has to go twice over the data samples. The first loop obtains the
mean x and the second loop calculates E[(X x )2 ]. Show a code
that uses only one pass over the data by adopting the expression
E[(X x )2 ] = E[X2 ] 2x .

1.9.

1.10. a) Generate a realization (one waveform) of a Gaussian random

process with 100 i.i.d. (independent and identically distributed) samples


of a Gaussian with mean 4 and variance 3, that is, N (4, 3). b) Generate
a waveform with independent but not identically distributed samples:
the samples with odd indexes are draw from N (4, 3), while the samples
with even indexes are draw from a uniform distribution U(5, 7) with
support [5, 7].

1.11. Practice the generation of two-dimensional random vectors drawn

from a PDF fX1 ,X2 (x1 , x2 ) with mean = (2, 3)T . Use the Matlab/Octaves function mvnrnd or, if you do not have Matlabs Statistics Toolbox

1.2 Exercises

installed, use the companion octave_mvnrnd instead. An example follows:


Listing 1.1: MatlabOctaveCodeSnippets/snip_signals_2Drandom.m

10

N = 100000; % number of 2 - d vectors


mu =[2 3]; % mean
C =[1 0.5 ; 0.5 10]; % covariance matrix
r = octave_mvnrnd ( mu ,C , N ) ; % octave_mvnrnd or mvnrnd
numbiny = 30; numbinx = 30; % number of bins for
histogram
Cest = cov ( r ) % check estimated covariance matrix ( should
be close to C )
mu_est = mean ( r ) % estimated mean
R = C + mu '* mu % theoretical correlation matrix
Rest = Cest + mu_est '* mu_est % estimated correlation matrix
[n , xaxis , yaxis ]= ak_hist2d ( r (: ,1) ,r (: ,2) , numbinx , numbiny )
; % histogram
mesh ( xaxis , yaxis , n ) ; pause % plot histogram
contour ( xaxis , yaxis , n ) ; xlabel ( ' x1 ') ; ylabel ( ' x2 ') ; % and
its countour

The task is to "compare#the graphs for the following


"
# covariance
" matrices:
#
2

0
0.5
0
1
0.5
a) C = 2 I =
, 2 = 0.5. b) C =
. c) C =
.
0 2
0 4
0.5 1

1.2 Exercises
Unless specified otherwise, assume that the signals are in Volts and
were obtained over a resistor of 1 Ohm. Always indicate the units in
your answers and graphs.
Depict in plots the even and odd parts of x[n] = n2 (u[n 3]
u[n 7]).

1.1.

You do not know much about a signal x[n], but it is given that
x[0] = 3. Can x[n] be an odd signal? Why?

1.2.

Let [3, 4, 5] be the amplitudes of the three samples (n = 0, 1 and


2, respectively) of a discrete-time x[n] obtained by sampling a speech
signal. a) What is the value of x[n] at n = 1.5? b) Describe the result
of a D/C conversion of x[n] to a sampled signal xs (t) with sampling
period Ts = 4 s and draw the graph of xs (t) specifying the abscissa in
seconds. c) What are the amplitude values of xs (t) at t = 1.5 and 8 s?

1.3.

1 Analog and Digital Signals

a) Manually (do not use a computer) draw the graph of the


P
k
sampled signal xs (t) =
k=0 (1) (t k) indicating values at both
abscissa and ordinate.

1.4.

Given x(t) as depicted in Figure 1.1, clearly draw the graphs of a)


x(t 3), b) x(4t) and c) x(t/2).

1.5.

2.5

x(t) (V)

1.5

0.5

0
2

2
t (s)

Figure 1.1: Example of continuous-time signal.

a) Manually draw the graph of x[n] = [n+2]+[n+1]+[n]+[n


1] + [n 2] + 0.4[n + 3]. b) Do the same for the signals: y[n] = x[n + 1],
z[n] = x[n + 1][n 2] and w[n] = 3x[n2 ]. c) Convert x[n] to a sampled
signal xs (t) adopting Fs = 2 kHz and draw the graph of xs (t).

1.6.

Practice choosing commercial ADCs and DACs. Some companies


of interest are Analog Devices, Maxim and Texas Instruments. Assume
you have to choose chips for three projects with distinct requirements: 1)
the fastest ADC and DAC with at least 16 bits per sample, 2) Low cost
chips with 8 bits per sample to work with Fs up to 10 kHz and 3) high
precision chips to work with Fs around 100 Hz in medical applications.
In your comparison, indicate at least resolution, speed, price, power
consumption, supply current and if the data bus is serial or parallel
and inform the interface (e. g., SPI). Extra parameters you may include
are full scale range (FSR), total harmonic distortion (THD), effective
number of bits (ENOB) and offset error.

1.7.

Get familiar with digitizing systems and boards, which are sometimes called DAQ (data acquisition) boards. Calculate the storage space
and transfer rate for digitized signals (visit [url1bww] for extra information). a) Calculate the total space in megabytes (MB) for storing 30

1.8.

1.2 Exercises

minutes of a signal sampled at the maximum rate of the following data


transfer technologies:

PCI: 2133 Mbit/s (266.7 MB/s)


Serial ATA (SATA-300): 3000 Mbit/s (375 MB/s)
USB 2.0: 480 Mbit/s (60 MB/s)
Serial RS-232 (max): 0.2304 Mbit/s (0.0288 MB/s)

b) Assume you need to use a 16-bits A/D process to achieve the desired
SNR, what is the maximum sampling rate that needs to be supported
for each interface above? c) Describe in high-level a digitizer system
to sustain a sampling rate of 40 MHz and store 3 hours of a signal.
Choose the data transfer technology, total hard disk space, etc.). d)
Considering you must use USB 2.0: what is the maximum sampling
rate the system could achieve in this case? e) Evaluate a Signatec
[url1sig] waveform recording product and indicate what is the maximum
throughput that Signatec offers (indicate sampling rate and number of
bits per sample) for recording some hours of signal into a hard disk.
Note that when operating at maximum sampling rate, most acquisition
boards and digital oscilloscopes store the ADC samples in a limited
amount of onboard RAM, which is typically capable of storing only
few seconds of signal. The discussed recording system must take into
account the data transfer from onboard RAM to hard disk.
For the following signals, calculate the energy E and power
P . Do they have a finite total energy or a finite average power? a)
x(t) = 5 cos(2300t + /4), b) x(t) = 3e2t u(t) and c) x(t) = t.

1.9.

1.10. What can be said about the total energy and average power of

any periodic signal?

1.11. For each of the following signals, determine if it is periodic and

its fundamental period N0 if positive: a) x[n] = u[n] + u[n 1], b)


11
x[n] = cos( 8 n), c) x[n] = cos( 128
n + /3) and d) x[n] = cos((/4)n2 )?

1.12. Classify the following signals as power or energy signals and

calculate their autocorrelation R( ), using the proper definition. Assume


that t is in seconds and indicate the unit of : a) x(t) = cos(2100t)
and b) x(t) = exp(t)u(t).

1.13. The following commands were used to estimate the autocorrelation

of a cosine: N=16; n=0:5*N-1; x=cos(2*pi/N*n); R=xcorr(x,biased);


However, the result did not match the theoretical expression. Can you

1 Analog and Digital Signals

explain the reason? How could you obtain the proper result? Compare
this result with Application ??. Why in this case autocorrelation seems
to be periodic and match the theoretical result?
1.14. A sinc function sinc( ) (see Section ??) centered in = 0 can

be an autocorrelation? What if it was centered in = 3 seconds?


What is the interpretation to the fact that the autocorrelation achieves
its maximum at = 0? What is the interpretation for sinc(0) (the
autocorrelation at origin) if the adopted definition were: a) for energy
signals and b) for random or power signals?

1.15. A signal x[n] was obtained using the randn function in Matlab/Oc-

tave, such that it has zero mean and unity variance. What is the power
of this signal? How x[n] can be transformed in a signal y[n] with mean
equal to four and variance equal to nine? What is the Matlab/Octave
command to generate 100 samples of y[n] using randn? What is the
average power of y[n]? Plot the following graphs: autocorrelation and
probability density function of both x[n] and y[n].

1.16. The goal is to design a uniform scalar quantizer for a discrete-time

signal x[n]. It is given that x[n] is approximately uniformly distributed


with mean equal to 2 and standard deviation equal to 3. a) Describe a
3-bits quantizer that minimizes the quantization error, explaining your
design decisions. b) Calculate the signal to noise ratio (in dB) for the
case of a 8 bits quantizer operating with the same input signal.

1.17. A 3-bits uniform quantizer has a step size = 2 V. The input is x

and the output xq . Its minimum output value is xq = 8. Assume four


input values [20, 0.7, 5.4, 6.1] V and inform: a) the graph (stairs)
showing xq x for this quantizer, b) the quantization error eq for each
of these input values and c) the power in Watts of eq considering only
the four corresponding samples.

1.18. Assuming the input signal of a quantizer can be modeled by a

Gaussian FDP with variance 4 W and mean 2 V. Design a 2-bits uniform


quantizer that tries to minimize the quantization error. a) Draw the
output versus input for this quantizer and b) calculate the quantization
SNRdB assuming only errors in the granular region and that the linear
model for quantization is valid.

1.19. In case you have access to the required equipments, estimate and

describe in details the quantizer used by the sound system of some

1.2 Exercises

personal computer (describe the stairs: dynamic range and step size).
Try to model the DC offset.
1.20. Consider you want to quantize a sinusoid with peak amplitude

equals to 10 Volts using b = 10 bits. Find general expressions for the


quantization SNR in terms of b, using both linear and dB scales. If
instead of a sinusoid your signal (to be quantized) had a Gaussian PDF
with mean = 3 and standard deviation = 2, find similar expressions
for the SNR assuming the signal dynamic range is 6 around the mean.

1.21. The sampling theorem is a strict inequality Fs > 2fmax but some

people state it as a non strict inequality, i. e., Fs 2fmax , which is


incorrect. Provide an example where sampling a sinusoid of 30 Hz with
Fs = 60 Hz leads to a signal where all samples are zero. For inspiration,
take a look at a different approach: assume a cosine
x(t) = A cos (2f0 t + ) ,

(1.1)

where A = 1/ cos(). The sampling frequency is chosen as Fs = 2f0


such that x(n) = cos(n) = (1)n and x(t) cannot be recovered from
x[n] (which is the same for any phase ), as illustrated by Listing 1.2.
Listing 1.2: MatlabOctaveCodeSnippets/snip_signals_sampling_inequality.m

10

Fs =20; Ts =1/ Fs ; % sampling frequency Fs in Hz and period


Ts in sec .
f0 = Fs /2; % key thing : Fs should be greater than 2 f0
t =0: Ts :1; % discrete - time axis , from 0 to 1 second
theta1 = pi /4 % define an arbitrary angle
A1 =1/ cos ( theta1 ) ; % amplitude
x1 = A1 * cos (2* pi * f0 * t + theta1 ) ; % not obeying sampling
theorem
theta2 =0 % define any value distinct from theta1
A2 =1/ cos ( theta2 ) ; % amplitude
x2 = A2 * cos (2* pi * f0 * t + theta2 ) ; % not obeying sampling
theorem
plot (t , x1 , ' rx ' ,t , x2 , 'o - b ') ; title ( ' Cannot distinguish 2
signals ! ')

This ambiguity demonstrates the need for a strict inequality.


1.22. Learn how to manipulate wav files obtained from an audio CD

and evaluate their histograms. Were the signals properly digitized? All
(or most) quantizer levels were used? In case you find a CDA file, note

1 Analog and Digital Signals

that these files (of just 44 bytes) are not the actual audio files. They
are just pointers to the audio data (similar to shortcut files). In order
to copy the files, you need to use a rip software such as, e. g. [url1rip].

1.3 Solutions: Review Exercises

1.3 Solutions: Review Exercises


1.1.

See Listing 1.3.


Listing 1.3: Matlab/Octave code for this dB exercise

% % global configs
size_x = 1000; % samples
samp_freq = 100; % samples per second
t = [0: size_x -1] '/ samp_freq ; % column - vector of time
indices
5

10

% % obtain s [ n ] , the signal


A = 10; % amplitude in Volts
frequency = 1; % Hz
omega = 2* pi * frequency ; % rad / s
theta = 0; % rad
s = A * cos ( omega * t + theta ) ; % volts

15

% power of the sinusoid


power_s = 1/ size_x * sum ( s .^2) ; % watts
% % calculate the power P for AWGN r [ n ]
SNR = 30; % dB

20

25

30

35

% Since SNR = 10* log10 ( power_s / P ) ,


% we have :
disp ( ' Power P ( in watts ) for the AWGN : ') ;
P = power_s / 10^( SNR /10) % watts
% % obtain r [ n ] , the AWGN
% The variance of r is its AC power .
% Hence , just like Exercise 21 ( Chapter 1) :
r = randn ( size_x ,1) * sqrt ( P ) ; % zero mean and P
variance
% % obtain x [ n ] , the noisy signal
x = s + r;
% % plot signal , noise , and both
subplot (311) , plot (t , s , t , r )
title ( ' Signal and noise ')
xlabel ( ' Time ( s ) ')
ylabel ( ' Amplitude ( V ) ') ;
subplot (312) , plot (t , r )

10

1 Analog and Digital Signals


title ( ' AWGN ')
xlabel ( ' Time ( s ) ')
ylabel ( ' Amplitude ( V ) ') ;

40

45

subplot (313) , plot (t , x )


title ( ' Noisy signal ')
xlabel ( ' Time ( s ) ')
ylabel ( ' Amplitude ( V ) ') ;

1.2.

To be done.

1.3.

See Listing 1.4.


Listing 1.4: Matlab/Octave code this dBm exercise

% % obtain the amplitude of the sinusoid


% Formula :
% q dBm = 10* log10 ( Power_in_watts / one_milliwatt )
% P watts = ( A ^2) /2 , A in volts
dBm_power_x = 30; % sinusoid power in dBm
disp ( ' Power : ')
power_x = 10^( dBm_power_x / 10) / 10^3 % watts
disp ( ' ') ;

10

disp ( ' Amplitude : ')


A = sqrt (2* power_x ) % volts
disp ( ' ') ;

1.4.

To be done.

1.5.

To be done.

1.6.

To be done.

1.7.

To be done.

1.8.

To be done.

1.9.

To be done.

1.10. To be done.
1.11. To be done.
1.12. To be done.

1.4 Solutions: Exercises

1.4 Solutions: Exercises


1.1.

To be done.

1.2.

To be done.

1.3.

To be done.

1.4.

To be done.

1.5.

To be done.

1.6.

To be done.

1.7.

To be done.

1.8.

See Listing 1.5.

Listing 1.5: Matlab/Octave code for this exercise about digital interfaces
% global configs
bandwidths = [2133 3000 480 0.2304]; % Mbits / s
interfaces = { ' pci ' , ' sata ' , ' usb2 .0 ' , ' rs232 ' };
record_time = 30; % minutes
5

10

15

disp ( ' Listing total space ( in MBytes ) and maximum ')


disp ( ' sampling rate ( in samples / s ) required for ') ;
disp ( record_time ) ;
disp ( ' minutes : ') ;
disp ( ' ') ;
for i = 1: length ( bandwidths )
disp ( interfaces { i }) ;
total_space = bandwidths ( i ) * record_time *60/8
max_samp_rate = bandwidths ( i ) /16*1000
disp ( ' ') ;
end

1.9.

To be done.

1.10. To be done.
1.11. To be done.
1.12. To be done.
1.13. To be done.

11

12

1 Analog and Digital Signals

1.14. To be done.
1.15. See Listing 1.6.
Listing 1.6: Matlab/Octave code for this exercise about signal generation and
analysis
% % global configs
size_x = 100; % samples
bins = 500; % bins for histogram
5

10

% % obtaining x [ n ] , the signal


x = randn ( size_x ,1) ;
% % obtaining y [ n ] , the new signal
newmean = 4; % mean of y
newvar = 9; % variance of y
y = x * sqrt ( newvar ) + newmean ;
% y can also be obtained by :
% y = normrnd ( mean , std , rows , cols ) ;

15

% % calculating power of x [ n ] and y [ n ]


power_x = 1/ size_x * sum ( x .^2) ; % watts
power_y = 1/ size_x * sum ( y .^2) ; % watts
20

25

% % plot autocorrelations
% DEPENDS on MATLAB ' s Signal Processing Toolbox
% DEPENDS on Octave - Forge ' s packages
plot ( xcorr ( x ) ) , title ( ' Autocorrelation of x ') ;
figure ;
plot ( xcorr ( y ) ) , title ( ' Autocorrelation of y ') ;
figure ;

30

% % plot probability density functions


[ counts_x , bins_x ] = hist (x , bins ) ;
bar ( bins_x , counts_x ) , title ( ' Histogram of x ') ;
35

figure ;
[ counts_y , bins_y ] = hist (y , bins ) ;
bar ( bins_y , counts_y ) , title ( ' Histogram of y ') ;

40

% % display info
disp ( ' Power : ') ;

1.4 Solutions: Exercises


power_x
power_y
disp ( ' ') ;
45

disp ( ' Mean : ') ;


mean_x = mean ( x )
mean_y = mean ( y )
disp ( ' ') ;
50

disp ( ' Variance : ') ;


var_x = var ( x )
var_y = var ( y )
disp ( ' ') ;

1.16. See Listing 1.7.


Listing 1.7: Matlab/Octave code this uniform quantization exercise
% % global configs
mean_x = 2;
std_x = 3;
5

10

15

20

25

% % obtain variance of the signal


var_x = std_x ^2;
% % calculate range of the signal
% Formula :
% For the uniform distribution ,
% Variance = delta ^2 / 12
range = sqrt ( var_x *12) ;
max_x = mean_x + range /2;
min_x = mean_x - range /2;
% % calculate snr for 3 and 8 bits :
% Formula :
% SNR = power_signal / power_noise
% SNR_dB = 10* log10 ( SNR )
for i = [3 8] % number of bits
% % calculate the quantizer ' s delta
% the quantizer will try to be as accurate as
possible
% by sweeping the entire range of the signal
delta = ( max_x - min_x ) / 2^ i ;
disp ( ' Number of bits : ') ;

13

14

30

1 Analog and Digital Signals


disp ( i ) ;
snr = var_x / ( delta ^2/12)
snr_dB = 10* log10 ( snr )
disp ( ' ') ;
end

1.17. To be done.
1.18. To be done.
1.19. To be done.
1.20. See Listing 1.8.
Listing 1.8: Matlab/Octave code for this quantization exercise
% % global configs
b = 10; % bits

% the signal is a sinusoid


disp ( ' sine wave ')
% configs
amplitude_x1 = 10; % volts

10

15

20

25

% % calculating power for the signal


% since it is a sinusoid , power = amplitude ^ 2 / 2
% ( normalized to 1 ohm )
power_x1 = amplitude_x1 ^2 / 2 % watts
% % calculating the SNR = power_x / power_noise
% the zero - mean sinusoid has max = abs ( amplitude ) and
min = - max
max_x1 = abs ( amplitude_x1 ) ;
min_x1 = - max_x1 ;
% quantizer delta
delta = ( max_x1 - min_x1 ) /2^ b
% quantization noise is the variance of
% the quantization error ( which is uniformly
distributed )
power_noise = delta ^2 / 12
% signal - to - noise ratio
snr = power_x1 / power_noise
snr_db = 10* log10 ( snr )

1.4 Solutions: Exercises

15

30

disp ( ' ')


% the signal is random with gaussian pdf
disp ( ' gaussian signal ')
35

% configs
mean_x2 = 3;
std_x2 = 2;
40

45

50

% % calculating power for the signal


% AC power is variance
power_x2 = std_x2 ^2;
% % calculating the SNR = power_x / power_noise
% this particular gaussian has 6* std_x2 dynamic range
dr = 6* std_x2 ;
max_x2 = mean_x2 + dr ;
min_x2 = mean_x2 - dr ;
% quantizer delta
delta = ( max_x2 - min_x2 ) /2^ b
power_noise = delta ^2 / 12

55

% signal - to - noise ratio


snr = power_x2 / power_noise
snr_db = 10* log10 ( snr )

1.21. See Listing 1.9.


Listing 1.9: Matlab/Octave code for this sampling theorem exercise
% % global configs
size_x = 120; % samples
samp_freq = 60; % samples per second
t = [0: size_x -1] '/ samp_freq ; % column - vector of time
indices
5

10

% obtain x [ n ] , the signal


A = 1; % amplitude in volts
frequency = 30; % Hz
omega = 2* pi * frequency ; % rad / s
theta = 0; % rad
x = A * cos ( omega * t + theta ) ;
plot (t , x ) , hold on , stem (t , x ) , hold off ;

16

1.22. To be done.

1 Analog and Digital Signals

2 Transforms and Signal Representation


2.1 Review Exercises
Given two vectors [4, 3] and [5, 2], find their norms, inner product
and angle between them.

2.1.

Given two vectors x = [4, 0] and y = [5, 2], find the projections
pyx and pxy and the respective error vectors eyx and exy .

2.2.

"

1 5
2.3. Is the matrix A =
unitary? Design a unitary matrix B
3 4
that is similar to A in the sense that its first basis (column) is a vector
in the same direction as [1, 3]T .
Assume a 2-d vector space has non orthogonal basis given by
i = [2, 1] and j = [0, 3]. Find the coefficients and that allow to
represent the vector x = [4, 1] as the linear combination x = i + j.

2.4.

Assuming a 2-d vector space with orthonormal basis vectors i and


j, prove that inner products can be used to find the coefficients and
that allow to represent a vector x = [x1 , x2 ] as the linear combination
x = i + j.

2.5.

Find the inner product between the signals: a) u(t) and e0.9t , b)
cos(0.5n) and [n], c) u[n 1] and u[n].

2.6.

2.2 Exercises
A segment of an ECG signal x[n] with six samples
[1, 0.6, 0.5, 1, 2.5, 2] must be encoded using a 3-points DCT (i. e.,
using two frames with three samples each). Find the DCT coefficients
of these two vectors. Then, reconstruct an approximation of the two
vectors assuming that only the first coefficient can be used while
the other two are discarded (assumed to be zero). Confirm Eq. (??)
calculating the norms of both error vectors et and ef .

2.1.

A segment of an ECG signal with four samples [0.5, 1, 2.5, 2] must


be encoded using a 2-points DCT (i. e., using two frames with two

2.2.

18

2 Transforms and Signal Representation

samples each). The coefficients at the DCT domain must be quantized


with 4 bits per frame, with the first coefficient (DC) being quantized
with 3 bits and the other one with 1 bit. Both quantizers have a step
of = 0.5 and their first output level is 0.25. a) What is the decoded
signal (after coding and decoding)? b) What is the mean squared-error?
c) What is the SNR in dB? d) What is the bit rate in bps assuming
Fs = 150 Hz? e) What is the bit rate and SNR if the second coefficient
is discarded (no bits are allocated for it and its value is assumed to be
zero during decoding)?

120 140 139

2.3. Consider that a block of pixels C = 124 220 120 was ex114 130 122
tracted from an image. Calculate the bi-dimensional DCT and DFT
first processing each row and organizing the result of this intermediate
step as a matrix T, then apply the transforms to each column of T to
generate the final matrix. Follow this procedure to obtain a matrix with
the DCT coefficients and then repeat it to obtain the DFT coefficients.
Design a DCT-based image coding system that is capable of
handling 24 bits/pixel color images and 8 bits/pixel black and white
(B&W, also called gray) images, all with a size of 512 512 pixels. The
system should operate using: a) 3 bits/pixel, b) 1 bit/pixel or c) 0.25
bit/pixel. For the three cases, provide the average peak SNR (PSNR),
i. e., the SNR when assuming the signal in the numerator is an image
with all pixels at the peak value of 255 and the denominator is the
mean squared-error. The test sequence should be the colorful and B&W
versions of the images Lenna, Peppers, Baboon, Splash and Tiffany,
available from [url2us2]. Do not download B&W versions of the five
mentioned images, but make the conversion from color to B&W yourself
and describe the conversion method you used. Hence, the test set will
have 5 images. You can use as many images you want to compose your
training set (distinct from the test set images). Provide the source code
and a short report of your results that includes the average PSNR.
2.4.

Use the Gram-Schmidt procedure to find an orthonormal basis to


represent the vectors in the set C = {[001], [010], [008], [050], [412], [003]}.
Show also that any vector in C can be written as a linear combination
of the obtained basis vectors.

2.5.

2.6.

PCA assumes the signal is zero mean. This exercise uses this fact

2.2 Exercises

19

to exemplify the importance of following an assumed model. KLT (or


PCA) is the optimal linear transform for coding but it does assume a
model. Design a coding system for the data x below.
Listing 2.1: MatlabOctaveCodeSnippets/snip_transforms_KLT.m

N =100; % number of vectors


K =4;
% vector dimension
line =1: N * K ; % straight line
noisePower =2; % noise power in Watts
temp = transpose ( reshape ( line ,K , N ) ) ; % block signal
x = temp + sqrt ( noisePower ) * randn ( size ( temp ) ) ; % add (
AWGN ) noise
z = transpose ( x ) ; plot ( z (:) ) % prepare for plot

Note that the KLT does not have info about the mean. Therefore, in
practice, one needs to keep the mean and, eventually, normalize the
variances to be unitary (this normalization is called in statistics to
z-transform the data, but this term should not be confused with the
Z transform).
Generate N = 10, 000 samples from a bidimensional Gaussian
= (30, 20)T and covariance matrix
fX1 ,X"2 (x1 , x2 ) with
mean
#

2.7.

10 0.99
. Obtain two transforms: Ag using Gram-Schmidt
0.99 40
orthonormalization and Ap using PCA. You can remove means if useful.
Using each transform, project the data into the new space and compute
the variance of the coefficients in each dimension. Which transform you
expect to lead to smaller variances of the transformed vectors?
C=

Following a scheme similar to the one presented in Application


?? - ECG Coding, compare the performance of KLT and DCT using
a test set of at least 50 ECT records from the MIT-BIH Arrhythmia
Database. Note that for performing any preparation / training you
should use a training set, disjoint of the test set. Otherwise your results
can be biased by the fact that you already knew what should be coded.

2.8.

Calculate manually the DFT of the sequence x[n] = [2, 0, 2, 0].


Then use the fft function in Matlab/Octave and compare the results.

2.9.

2.10. What are the forward A and inverse AH matrices for a 3-points

orthonormal DFT?

20

2 Transforms and Signal Representation

2.11. Consider that s[n] was obtained by sampling with Fs = 100 kHz

an analog and periodic signal s(t). The sampling theorem was obeyed.
The 8-DFT of s[n] was calculated in Matlab/Octave with fft(s)/N and
is shown in Figure 2.1. The value N was chosen to be an exact multiple
of the fundamental period of s(t) such that the problem of spurious
components illustrated in Figure ?? did not occur. a) What is the
frequency of each component of s(t)? What is the resolution f in Hz
of this DFT? c) Find a reasonable expression for s(t).

Figure 2.1: DFT with N = 8 points of a signal sampled at Fs = 100 kHz.


2.12. Given that X = [8, 0, 0, 0] was obtained with a 4-points orthonor-

mal DFT, find its inverse x. For the same spectrum, assuming that
Fs = 10 Hz, to which frequencies correspond the elements of X?

2.13. Consider that a periodic x(t) was sampled with Fs = 20 Hz,

obeying the sampling theorem. A 128-points FFT was calculated using


Matlab/Octave and the output X was normalized by N = 128. The
only non-zero coefficients were k = 0, 3 and 125, corresponding to the
elements of X[1] = 12, X[4] = 3 + j4 and X[126] = 3 j4, respectively.
a) What is the frequency in Hz of the component with largest power of
x(t)? b) what is the average (DC) value of x(t)? c) what is the spacing
in Hz between neighboring elements of X? d) what is the maximum
frequency found in x(t)?

2.14. Using the orthogonality condition of the basis functions derive the

pair of Fourier series equations.

2.15. What are the Fourier series coefficients for the signal x(t) =

2 + 3 cos(2100t) + 8 sin(2300t + ) + cos(250t )?

2.16. The bilateral Fourier series of a signal x(t) with period T0 = 0.01 s

21

2.2 Exercises

has non-zero coefficients c0 = 3, c1 = 2ej4 , c4 = 5, c1 = 2ej4 and


c4 = 5. What is the expression for x(t)?
2.17. Prove the expressions: a) for the DTFT of x[n] = 0.9n u[n] +

0.8n u[n] and b) for its Z transform, indicating the ROC.

2.18. Given that the DTFT H(ej ) of a signal in the range ], ] is 1

when c c and 0 otherwise (i. e., an ideal low-pass filter), find


its inverse DTFT h[n].

2.19. Prove that X(ej ) =

0 + 2k) is the DTFT of


x[n] =
and indicate when the impulse sifting property is used.
Using the result, carefully draw the graph of the real part of the DTFT
of y[n] = 3 + 4ejn for the range 3 3.
ej0 n

k= 2(

2.20. Prove the cited properties of the Fourier tools for the case of the

Fourier transform.

2.21. Prove the cited Fourier pairs for the case of the DTFT.
2.22. A right-sided signal has Laplace transform X(s) = 5/(s2 +2s+10),

with ROC > 1. Calculate: a) X(s)|s=2 , b) the corresponding Fourier


transform X() if it exists and c) if X() exists, |X()| for = 3 rad/s.

2.23. A signal x(t) has Laplace transform X(s) = (3s+2)/((s1)(s3)),

with ROC < 1. Find x(t).

2.24. A signal x[n] has Z transform X(z) = (5z 2 + 4z + 3)/((z 0.7)(z

0.8)), with ROC |z| > 0.8. Find x[n].

2.25. Find the Z transform and associated ROC of the signal x[n] =

3n u[n 1]. Does this signal have a DTFT?

2.26. What is the Z transform X(z) of the signal x[n] = 4[n]+5[n11]?

What are the values of X(z) for z = 0, 1 and z = 8ej ? If the DTFT
of x[n] exists, what are its values for = 0, and 2 rad?

3 Analog and Digital Systems


3.1 Exercises
When the input x1 [n] = [n]+[n1] is applied to a linear system,
the observed output is y1 [n] = 4[n 1] + [n 2]. Inform the expression
of the output y2 [n] when the input is x2 [n] = 3[n] + 3[n 1].

3.1.

When the input x1 [n] = [n] is applied to a LTI system, the output
is y1 [n] = 3[n] + 2[n 1] + [n 2]. What is the output y2 [n] when
the input is x2 [n] = 5[n] + 2[n 1]?

3.2.

When the input x1 [n] = [n] is applied to a system, the output is


y1 [n] = 3[n]+2[n1]+[n2], and when the input is x2 [n] = 2[n1],
the output is y2 [n] = 6[n 1] + 2[n 2] + 2[n 3]. Can this system
be LTI?

3.3.

A time-invariant system has output y1 (t) = (t 1) (t 4)


when the input is x1 (t) = (t). Inform the expression of the output
y2 (t) when the input is x2 (t) = (t 3).

3.4.

The input-output relations that describe three given systems are:


a) y[n] = C(x[n])2 , where C = 2ej/2 , b) y[n] = (n 1)x[n] and c)
y[n] = 3x[n 1] + 2 x[n 3]. Classify whether or not these systems
are: a) causal, b) linear, c) memoryless, d) stable in BIBO sense.

3.5.

A discrete-time LTI is characterized by the difference equation


y[n + 2] = 5x[n + 2] + 2x[n + n0 ], where x[n] and y[n] are the input
and output signals, respectively. Inform a value for n0 that makes the
system causal.

3.6.

What is the convolution matrix H for an impulse response h[n] =


3[n] + 2[n 1] + [n 2] when the input signals are: a) column vectors
of dimension 3, b) row vectors of dimension 4?

3.7.

Four continuous-time signals: x1 (t) = ej4t , x2 (t) = ej4t , x3 (t) =


cos(4t) and x4 (t) = e(1+j4)t , are individually transmitted over the
1
system H(s) = s+10
. What are the respective outputs y1 (t), . . . , y4 (t)?

3.8.

24

3 Analog and Digital Systems

Four discrete-time signals: x1 [n] = 5ej2n , x2 [n] = ej2n ,


n
x3 [n] = cos(2n) and x4 [n] = 3ej2 , are individually transmitted
1
over the system H(ej ) = 10.6e
j . What are the respective outputs
y1 [n], . . . , y4 [n]?

3.9.

3.10. What is the result of the periodic convolution between a pulse

train with pulses with duty cycle of 2 s, amplitude of 5 V and a period


of 10 s with itself?

3.11. The following commands were used to calculate y1 and y2:


N =3; M =4; x =1: M ; h =[0.4 , -0.1]; y1 = conv (x , h ) ; y2 = ifft ( fft (x , N )
.* fft (h , N ) ) ;

a) What is the minimum value of N to make y1 and y2 coincide? b)


Generalize the previous answer for an arbitrary value of M and length(h).
3.12. A band-limited signal x(t) was sampled obeying the sampling

theorem with Fs = 10 Hz and the result is xs (t) = 4(t) + 3(t 0.1)


2(t 0.4). Provide the exact expression of x(t). Hint: this expression
is given in terms of scaled and shifted sincs.

3.13. An AM radio signal has a bandwidth of 10 kHz and is centered at

600 MHz. Use undersampling to obtain a baseband version of this signal


via lowpass filtering with the minimum sampling frequency. Describe
the whole scheme, informing the filter, etc.

3.14. A band-limited even and real-valued discrete-time signal x[n]

has the spectrum X(ej ) described in Figure 3.1 with 1 = /4 and


2 = /2 rad. It is converted to a continuous-time signal x(t) using the
scheme depicted in Block (??) with Fs = 1 kHz and a ZOH modeled by
h(t) = u(t)u(tTs ). a) Carefully draw |X(f )|, where X(f ) = F{x(t)}
in the range 3 to 3 kHz. b) Calculate X(f ) (magnitude and phase)
at f = 0, 100 and 1200 Hz. c) Repeat the calculation in b) but now
considering that x[n] is a critically sampled signal with 1 = /4 but
2 = rad.

3.15. Assume the DUT in the circuit of Figure ?? is the SAW filter

described in Table ?? (assume its typical parameters). Both the source


ZS and load ZL impedances are 100 . a) If the input signal x(t)
(denoted as Vs in Figure ??) is a sinusoid of frequency 70 MHz and power
4 dBm, what is the power over the load and a reasonable expression
for the output signal y(t)? b) If x(t) = 3 cos(1 t) + 6 cos(2 t) with

3.1 Exercises

25

Figure 3.1: Spectrum of a band-limited even and real-valued signal x[n].

1 = 270 and 2 = 276.5 Mrad/s, what is a reasonable expression


for the output y(t)?
3.16. If the input to the filter characterized by Table ?? is x(t) =

4 cos(2f1 t + /4) + 8 cos(2f2 t), where f1 = 455 and f2 = 500 kHz,


what is a reasonable expression for the output y(t)?

3.17. A non-causal analog lowpass filter has an ideal magnitude with

unitary gain for frequencies 5 to 5 rad/s and zero otherwise. The


phase of this filter is linear and given by ej8 . What is the output of
P
k
this filter when the input is x(t) =
k=0 0.5 sin(1.5kt)?

3.18. A FIR filter with linear phase has an impulse response h[n] =

3[n] 5[n 1] + 7[n 2] 5[n 3] + 3[n 4]. Find its system


function H(z) and draw a realization of this filter with the minimum
number of multipliers.

3.19. A filter H(s), as described by Eq. (??), must have a damping

factor = 0.707 (such filter could be used by, e. g., the PLL discussed in
Section ??). a) find H(s) when the settling time must be approximately
3 ms (you may use Table ??). b) Perform a similar project but for the
SOS described by Eq. (??). c) Show the graphs of the outputs of both
systems to the step function u(t).

3.20. For the filter H(z) obtained with [b, a]=butter(3,1/3): a) find

the values of H(z) for z = 0.5 + 0.5j, 3 + 2j, 0, 1, 3 and 0.5 + 0.5j. b)
Using freqz.m, find the maximum value of the magnitude response and
in which frequency this maximum occurs. c) What are the first five
samples of the impulse response h[n]? d) Is this a FIR or IIR? e) Is
this a lowpass or highpass?

3.21. For

100

the filter H(s)


=
(obtained with
s2 +10 2s+100
[Bs,As]=butter(2,10,s)); a) what are the values in Hertz of its natural
and cutoff frequencies? Now consider that H(s) is the anti-aliasing filter

26

3 Analog and Digital Systems

of a DSP system operating with a sampling frequency of Fs = 4 Hz


and there is a strong interferer tone with 1 dBm at 6 Hz. b) At
what frequency and power this interferer will appear within the band
[0, Fs /[? c) And what if the interferer has the same power of 1 dBm
but frequency of 60 Hz?
3.22. a) Using syntax and structure similar to Listing ??, list the algo-

rithm of a digital filter implementing the system function H(z) provided


by [Bz,Az]=butter(3,0.2). b) When H(z) is used in the canonical system
of Figure ?? with Fs = 44.1 kHz and ideal analog filters, what is the
corresponding cutoff frequency in Hertz of the overall system?

3.23. The filter H(s) = s3 +2s21+2s+1 was obtained with the command [b,

a]=butter(3,1,s) and has cutoff frequency of 1 rad/s. Obtain a filter


G(s) that corresponds to a scaled version of H(s) with a new cutoff
frequency of 1200 rad/s such that both have the same gain at DC. a)
Inform the linear gains |H()| and |G()| for both filters at frequencies
= 0, 1, 1200 and 2000 rad/s. b) What are these gains in dB?

3.24. A filter H(s) = s3 +10s2125


has a cutoff frequency of 5 rad/s.
+50s+125

Obtain a filter G(s) that corresponds to a version of H(s) scaled in


frequency with a cutoff frequency of 3 rad/s. G(s) should also have a
gain of 3 dB at DC.

3.25. a) Use the six methods of Table ?? to convert H(s) = 0.13/(s2

0.4s + 0.13) into H(z) assuming Ts = 0.1 s and compare their frequency
responses with the original one (in continuous-time) b) Repeat the
procedure for Ts = 1 s. c) Discuss what methods were most impacted
by the increase of Ts .

3.26. Given a filter H(s) = (0.1s2 + 71)/(s2 + 11s + 71) and assuming

Fs = 50 Hz, a) find H(z) using the bilinear transform, b) compare the


frequency responses of H(s) and H(z) after D/C conversion using the
same abscissa in rad/s, c) can you find a frequency m > 0 in rad/s for
which the values of H(s) and H(z) are the same?

3.27. A filter H(s) = (0.1s2 + 71)/(s2 + 11s + 71) should be converted

to H(z) using the bilinear. The value of H(s) at s = j8.24 is g


0.708ej1.5366 . Use pre-warping to find H(z) that when implemented in
a hardware using Fs = 50 Hz: a) leads to the same value g at 8.24 rad/s,
b) leads to the same value g at 5 rad/s.

3.1 Exercises

27

3.28. The filter Hs (s) = (0.1s2 + 71)/(s2 + 11s + 71) should be converted

to Hz (z) using the bilinear such that the value of Hs (j) at = 10 rad/s
is the same value Hz (ej ) will have at = /4 rad. a) find the
value of Fs that allows to directly convert Hs (s) into Hz (z) without
the traditional pre-warping step, b) assuming an arbitrary value of
Fs0 = 0.5 Hz, find the pre-warped version of Hs (s) that will generate
the correct Hz (z) via bilinear with Fs0 .

3.29. A product adopted an analog filter H(s) = s3 +2s21+2s+1 , with a

cutoff frequency of 1 rad/s, which should be substituted by a digital


filter. The anti-aliasing and reconstruction filters are ideal. The ADC
and DAC converters operate at 100 Hz. Design a digital filter H(z)
that works as similar as H(s) as possible.

3.30. Design a causal FIR H(z) using the windowing method. The

filter must have 5 coefficients, cutoff frequency /6 rad and the adopted
window must be Hanns. The gain at DC must be unitary. The
command hanning(5) in Matlab/Octave, returns [0.25, 0.75, 1.00, 0.75,
0.25].

3.31. A filter was obtained with [b, a]=butter(3,1/3). a) Draw the block

diagram representation for realizations using direct form I, direct form


II, transposed direct form II, cascade of SOS and parallel using SOS.
b) Using any programming language, implement the direct form II.
Assume that there is a function called readAD() that reads a sample
from the ADC and another writeDA() that writes a sample to the DAC,
and that the processing loop is correctly invoked according to the chosen
sampling frequency. In other words, complete the following code (this
example is in C):

10

main ( ) {
int x , y ;
...
while (1) { // eternal loop
x = readAD ( ) ;
...
writeDA ( y ) ;
}
...
}

28

3 Analog and Digital Systems

3.2 Extra Exercises


Develop and list the source code of a Matlab/Octave routine
that implements the overlap-save method using a structure similar to
Listing ??.

3.1.

Using FilterPro as in Section ?? or similar software, design a


second-order lowpass Butterworth filter H1 (s) with passband frequency
of 5 kHz. Show the schematics. Adopt commercial components with
10% of tolerance. What is the exact value of the passband frequency?
Does it coincide with 5 kHz? After that, execute another design to
obtain H2 (s), trying to improve the attenuation using an approximation
other than Butterworths. Comparing H1 (s) and H2 (s), what can you
say on how good are their magnitudes and phases?

3.2.

Design a digital Butterworth filter H(z) using the bilinear transform. The cutoff and rejection filters are /4 and 2/3, respectively.
The linear gain at DC should be 1 and the minimum gain at the passband should be 0.95. The maximum gain at the rejection band is 0.01.
This filter can be obtained with the commands:

3.3.

Listing 3.1: MatlabOctaveCodeSnippets/snip_systems_buttord.m

Gs =20* log10 (0.01)


Gp =20* log10 (0.95)
Wp =1/4
Ws =2/3
[n , Wc ] = buttord ( Wp , Ws , -Gp , - Gs )
[b , a ]= butter (n , Wc )

a) What are the gain and phase at frequencies /4 and 2/3 rad? b)
What is the difference equation that corresponds to H(z)?
The bilinear transform Eq. (??) was obtained by expanding the
numerator and denominator of z = esTs /2 /esTs using a first order
Taylor expansion. Compare it with the expansion of z = esTs 1 + sTs .
What are the reasons for using the former expansion? An alternative
point of view is to calculate the series expansion of ln z for the matched
Z-transform s = ln(z)/Ts . Check the expansion for x > 0 at [url3iit].

3.4.

Study the algorithm used to design [b, a]=butter(2,1/4) including


the pre-warping stage.

3.5.

3.2 Extra Exercises

29

Using the function fir1, compare the FIR filters with cutoff frequency /4 rad for the windows Hamming, Hann and rectangular. The
commands can be

3.6.

bham = fir1 (30 ,1/3 , hamming (31) ) ;


bhan = fir1 (30 ,1/3 , hanning (31) ) ;
bret = fir1 (30 ,1/3 , rectwin (31) ) ;

and freqz can help. How do they compare with respect to: attenuation,
decay, side lobe and width of the main lobe.
Observe that fir1 in Matlab uses a modified cutoff frequency fc .
Instead of fc being the frequency of half the power at passband, for
fir1 fc is the frequency of half the gain at passband. In other words,
considering a filter with gain |H(0)| = G at DC, fir1 provides a filter
with gain |H(fc )| 0.5G (which corresponds to 20 log10 0.5
6 dB),
instead of the commonly adopted 3 dB value of |H(fc )| G/ 2. For
the Hamming window, design an alternative to fir1 that allows theuser
to specify the cutoff frequency as the one in which |H(fc )| G/ 2.

3.7.

The Kaiser window is very flexible. Study the project below


that uses Fs = 11025 Hz, passband [0, 1000] Hz, and rejection band
[1200, Fs /2]. The minimum attenuation at rejection band is 40 dB and
the maximum ripple at the passband is 5% (i. e., the filter can go from
1 to 0.95 at the passband).

3.8.

[n ,w , beta , ftype ]= kaiserord


([1000 ,1200] ,[1 ,0] ,[0.05 ,0.01] ,11025) ;
freqz ( fir1 (n ,w , ftype , kaiser ( n +1 , beta ) , ' noscale ')
,1 ,[] ,11025) ;

Design an IIR Butterworth that meets the requirements and compare


the order with the Kaiser FIR filter.
Generate realizations (waveforms) of a Gauss-Markov process.
Recall that a first-order Gauss-Markov process obeys s[n] = as[n 1] +
[n], n 0, where [n] is an i. i. d. Gaussian noise. Generate realizations
of s[n] with N = 100 samples each, using [n] with unitary power, and
for the following values of a: 0, .1, .9, .99, .5, 2, 3. Provide a qualitative
description of the difference between |a| < 1 and |a| > 1. Calculate the
autocorrelation of s[n] in terms of a (or obtain it from references such
as [?] or the Web).

3.9.

30

3 Analog and Digital Systems

3.10. Study the anti-aliasing filters at [url3min].


3.11. Using FilterPro, execute the project of a stopband using default

options, which should lead to an order 6 and cutoff frequency of 1 kHz.


a) What does it mean Min GBW reqd. in the end of the Schematic?
b) how to interpret the Group Delay plot? c) Why each stage of SOS
has f0, BW and Q? d) Use Edit to re-do the project using Chebyshev
with a maximum of 1 dB ripple in the passband instead of Bessel. How
did that impact the Group delay?

3.12. Study the advantages and disadvantages when comparing Butter-

worth, Chebyshev and Bessel responses.

3.13. When cascading the 2nd order stages, why the stages with lower

quality factor Q are placed first by Filter Pro?

3.14. Compare the MFB and Sallen-Key topologies. Can you find a

more sophisticated topology in the literature? If yes, describe it.

3.15. Briefly explain what sensitivity means.

3.3 Solutions: Exercises


3.1.

To be done. 1

3.2.

To be done. 2

3.3.

To be done. 3

3.4.

To be done. 4

3.5.

To be done. 5

3.6.

To be done. 6

3.7.

To be done. 7

3.8.

To be done. 8

3.9.

To be done. 9

3.10. To be done. 10
3.11. To be done. 11
3.12. To be done. 12

3.3 Solutions: Exercises

31

3.13. To be done. 13
3.14. To be done. 14
3.15. To be done. 15
3.16. In this case, f1 coincides with the nominal frequency fn = 455 kHz.

As the table indicates the actual center frequency fc of this device may
vary but it is assumed here that fc = fn and the gain is 0 dB (see the
figure associated to the table) or 1, in linear scale. The group delay at
this frequency is assumed to be 50 s, which corresponds to a phase of
6
ej5010 . Hence, the frequency response value H(1 ) at 1 = 2f1 is
3
6
1ej245510 5010 1ej142.9 (angle in rad). Converting the phase
to the range [, [ leads to H(1 ) = 1ej1.5708 .

In contrast, f2 fn = 45 kHz indicates that f2 is outsise the filters


passband. And according to Table ??, an attenuation of at least 27 dB
is guaranteed within 455 100 kHz. Looking at the associated figure,
it is assumed here that the attenuation is 32 dB, which corresponds to
a gain of 32 dB. Converting it to a linear gain g leads to
20 log10 g = 32 g = 1032/20 = 0.0251.
The group delay is not specified at f2 , so the corresponding phase is
assumed here to be 2 . Under these assumptions, the filter output is
y(t) = 1 4 cos(2f1 t + /4 + 1.5708) + 0.0251 8 cos(2f2 t + 2 )
= 4 cos(2455000t + 2.3562) + 0.2 cos(2500000t + 2 ).
when the input is x(t).
3.17. Obs: this question command had a typo. The phase is ej8

instead of ej8t .

As amplitudes das componentes que compoem $x(t)$ e nao


sao eliminadas pelo filtro (estao dentro da banda de
passagem) sao:
para k=0 => parcela 0
k=1 => 0.5 sin(3/2t), ou seja, w=1.5 rad/s
k=2 => 0.25 sin(3t), ou seja, w=3 rad/s
k=3 => 1/8 sin(4.5t), w=4.5 rad/s
e para as outras frequencias o filtro (ideal) elimina

32

3 Analog and Digital Systems

as componentes.
A magnitude das componentes dentro da banda de passagem
nao muda e soh a fase altera:
k=1 => w=1.5 rad/s => phase = -12 rad
k=2 => w=3 rad/s => phase = -24 rad
k=3 => w=4.5 rad/s => phase = -36 rad
Assim, a saida eh dada pela soma das parcelas acima:
y(t) = 0.5 sin(3/2t - 12) + 0.25 sin(3t - 24)
+ 1/8 sin(4.5t - 36)
3.18. A FIR filter with linear phase has an impulse response h[n] =

3[n] 5[n 1] + 7[n 2] 5[n 3] + 3[n 4]. Find its

The system function H(z) = {h[n]} is the Z transform of h[n] and it


is given by H(z) = 3 5z 1 + 7z 2 5z 3 + 3z 4 . Given the filters
impulse response has symmetry, the realization with the minimum
number of multipliers is obtained from the original difference equation
y[n] = 3x[n] 5x[n 1] + 7x[n 2] 5x[n 3] + 3x[n 4]
by arranging the coefficients with the same values:
y[n] = 3(x[n] + x[n 4]) 5(x[n 1] + x[n 3]) + 7x[n 2],
such that the realization has only three multipliers.
3.19. To be done. 19
3.20.

10

%a)
% Bz =[0.063856 0.191568 0.191568 0.063856];
% Az =[1 -0.96578 + 0.58264 -0.10602];
[ Bz , Az ]= butter (3 ,1/3) ;
z =[0.5+0.5* j 3+2* j 0 -1 3 0.5+0.5* j ]
Hz = polyval ( Bz , z ) ./ polyval ( Az , z )
magHz = abs ( Hz )

%b)
[H , w ]= freqz ( Bz , Az ) ;
% plot (w , abs ( H ) ) ;
indexMax = find ( abs ( H ) == max ( abs ( H ) ) )
freq_max = w ( indexMax )

3.3 Solutions: Exercises

15

33

%c)
h = impz ( Bz , Az , 5)
%d)
IIR

20

%e
freqz ( Bz , Az ) ; % lowpass

3.21. a) The cutoff frequency is 10 rad/s, as indicated by the com-

mand
[Bs,As]=butter(2,10,s). The pair of poles (roots of As) are
(10/ 2)(1 j), which have a natural frequency n = 10 rad/s. See
the details after the solution.

b) The interferer at 6 Hz, after sampled at 4 Hz, shows up at 2 Hz.


But before being digitized the interferer is filtered by H(s). Using
Matlab/Octave to obtain the attenuation imposed by H(s) at 6 Hz
leads to

[ Bs , As ]= butter (2 ,10 , 's ') % get filter H ( s ) = B ( s ) / A ( s )


f =6; w =2* pi * f ; s =1 j * w % frequency of interest at s plane
H = polyval ( Bs , s ) / polyval ( As , s )
mag = abs ( H ) , phase = angle ( H )
magdB =20* log10 ( mag )

which indicates that magdB = -23 dB. Hence, the interferer has power
-22 dBm, corresponding to 1 dBm attenuated by 23 dB.
c)

[ Bs , As ]= butter (2 ,10 , 's ') % get filter H ( s ) = B ( s ) / A ( s )


f =60; w =2* pi * f ; s =1 j * w % frequency of interest at s plane
H = polyval ( Bs , s ) / polyval ( As , s )
mag = abs ( H ) , phase = angle ( H )
magdB =20* log10 ( mag )

Using the previous commands, H(s) has an attenuation of 63 dB at


60 Hz, and the the interferer has power -62 dBm.
Details: Their natural frequency coincide with the filters cutoff frequency because all poles of a Butterworth filter have natural frequencies
coinciding with the filters cutoff frequency. In contrast, the poles of a
Chebyshev do not have this property. To see that, compare the results
of:

34

3 Analog and Digital Systems

[B , A ]= butter (5 ,10 , 's ')


wn = abs ( roots ( A ) )
[B , A ]= cheby1 (5 ,0.1 ,10 , 's ')
wn = abs ( roots ( A ) )

3.22. a) The difference equation is

y[n] = 0.0181x[n] + 0.0543x[n 1] + 0.0543x[n 2] + 0.0181x[n 3] +


1.7600y[n 1] 1.1829y[n 2] + 0.2781y[n 3],
and a direct form I implementation corresponds to:

10

15

20

25

main ( ) {
int x , y ;
int xnm1 , xnm2 , xnm3 , ynm1 , ynm2 , ynm3 ;
// initialize filter memory with zeros :
xnm1 =0;
xnm2 =0;
xnm3 =0;
ynm1 =0;
ynm2 =0;
ynm3 =0;
while (1) { // infinite loop
x = readAD ( ) ;
// implement zeros
y = 0.0181* x + 0.0543* xnm1 + 0.0543* xnm2 + 0.0181*
xnm3 ;
// implement poles
y = y + 1.7600* ynm1 - 1.1829* ynm2 + 0.2781* ynm3 ;
writeDA ( y ) ;
ymn3 = ynm2 ; % update for next iteration . Note order of
...
ynm2 = ynm1 ; % updates : avoid overwriting a value ...
ynm1 = yn ;
% that should be used later
xnm3 = xnm2 ;
xnm2 = xnm1 ;
xnm1 = xn ;
}
}

b) The digital frequency is mapped to an analog one via = Fs . In


this case Fs = 44100 Hz and c = 0.2 rad such that c = 8820 rad/s.
This can be converted to Hertz using c = 2fc , which leads to fc =
22050 0.2 = 4410 Hz.

3.3 Solutions: Exercises

35

3.23. It is possible to scale a filter to obtain a different cutoff frequency.

The operation is similar to using x(2t) to double the speed of a song


represented by x(t). For example, if H(s) has a cutoff of c rad/s, the
transformation s s/k moves this cutoff frequency to kc rad/s.

To obtain G(s) with new cutoff frequency of 1200 one can algebraically
do:
s
G(s) = H(s)|s 1200
and simplify the expression. Another alternative is to use Matlab/Octave:
[ bg , ag ]= butter (3 ,1200* pi , 's ') % obtain the filter
W = linspace (0 ,2000 ,100) ;
freqs ( bg , ag , W ) ;

To get the gains, one can calculate manually or use Matlab/Octave:

[b , a ]= butter (3 ,1 , 's ') % obtain the filter with cutoff 1


rad / s
[ bg , ag ]= butter (3 ,1200* pi , 's ') % obtain the filter with
cutoff 1200 pi rad / s
W =[0 1 2000 1200* pi ]; % note 1200 pi is greater than 2000
rad / s
H = freqs (b ,a , W )
G = freqs ( bg , ag , W )
magH = abs ( H )
magG = abs ( G )
magHdB =20* log10 ( abs ( H ) )
magGdB =20* log10 ( abs ( G ) )

Note that the cutoff frequencies have a linear gain of 0.70711, which
correspond to 3.01030 in dB.
3.24. It is convenient to first obtain a filter P (s) with cutoff frequency of

1 rad/s. The original 5 rad/s can be converted to 1 rad/s by substituting


s in H(s) by 5s, such that P (s) = H(s)|s=5s = 1/(s3 + 2s2 + 2s + 1).
Now, to move the cutoff frequency at 1 rad/s of P (s) to 3 rad/s one
can use G(s) = P (s)|s=s/3 = 27/(s3 + 6s2 + 18s + 27).

3.25. To be done. 25

36

3 Analog and Digital Systems

3.26. The bilinear is obtained by H(z) = H(s)s=2Fs z1 that leads to


z+1

0.1(100(z 1)/(z + 1))2 + 71


(100(z 1)/(z + 1))2 + 11(100(z 1)/(z + 1)) + 71
103 (z 1)2 + 71(z + 1)2
= 4
10 (z 1)2 + 1100(z 1)(z + 1)) + 71(z + 1)2
103 (z 2 2z + 1) + 71(z 2 + 2z + 1)
= 4 2
10 (z 2z + 1) + 1100(z 2 1) + 71(z 2 + 2z + 1)
1071z 2 1858z + 1071
=
.
11171z 2 19858z + 8971

H(z) =

For convenience, normalize by 11171 such that the denominator coefficient of highest order is 1:
H(z) =

0.0959z 2 0.1663z + 0.0959


.
1z 2 1.7776z + 0.8031

Now, check the gain at DC making H(z)|z=1 = (0.0959 0.1663 +


0.0959)/(1 1.7776 + 0.8031) = 1. There is no need to change it. This
filter could be obtained with Matlab commands and itens b) and c)
observed from them:

10

15

Bs =[0.1 0 71]
As =[1 11 71]
Fs =50 % in Hz
N =20000; % number of points for freqs / freqz
[ Bz , Az ]= bilinear ( Bs , As , Fs )
[ Hz , Wd ]= freqz ( Bz , Az , N ) ;
w = Wd * Fs ; % from rad to rad / s
Hs = freqs ( Bs , As , w ) ; % H ( s ) at frequencies w
subplot (211)
plot (w ,20* log10 ( abs ( Hz ) ) )
hold on , plot (w ,20* log10 ( abs ( Hs ) ) , 'r ')
legend ( 'H ( z ) ' , 'H ( s ) ')
subplot (212)
magError = abs ( Hz ) - abs ( Hs ) ; % error
plot (w , magError ) , ylabel ( ' Error in magnitude ')
xlabel ( 'w ( rad / s ) ') ;
[m , i ]= min ( abs ( magError ) ) % find minimum
minFreq = w ( i ) % frequency of minimum abs error

By zooming the top plot, it can be seen that H(z) and H(s) have the
same magnitude ( 52.4 dB) for m 26.3 rad/s (besides at DC).

37

3.3 Solutions: Exercises


3.27. To be done.
3.28. To be done. 28

3.29. One can simply use the bilinear transform to get the digital filter

H(z) = B(z)/A(z). The commands define the H(s) filter:


Fs =100; % sampling frequency
Bs =1; % numerator
As =[1 2 2 1]; % denominator

Note that Matlab and Octave differ in the command:


[ Bz , Az ]= bilinear ( Bs , As , Fs ) ; % using Matlab
[ Bz , Az ]= bilinear ( Bs , As ,1/ Fs ) ; % using Octave

We could improve the design using pre-warping, such that the gains
at the cutoff frequencies of H(s) and H(z) match. From the previous
question, the cutoff frequency of H(s) is 1 rad/s (it was obtained with
[bg, ag]=butter(3,1,s)). Because the cutoff is 1 rad/s, the Matlab
command [Bz, Az]=bilinear(Bs,As,Fs,1), which uses pre-warping, does
not change the result. But pre-warping should be trained with other
questions.
3.30. To be done. 30
3.31. The coefficients b and a allow to draw the direct forms I, II and

II transposed. The command sos=tf2sos(b,a) allows to obtain the 2


SOSs (a order 1 and order 2 SOSs). The command [r,p,k]=residue(b,a)
is useful for the parallel implementation, which can be obtained after
grouping the groups of complex poles.

The difference equation is


y[n] = 0.0639x[n] + 0.1916x[n 1] + 0.1916x[n 2] + 0.0639x[n 3] +
0.9658y[n 1] 0.5826y[n 2] + 0.1060y[n 3],
and the direct form II implementation (poles are implemented first)
requires:
w[n] = x[n] + 0.9658w[n 1] 0.5826w[n 2] + 0.1060w[n 3]
and then
y[n] = 0.0639w[n] + 0.1916w[n 1] + 0.1916w[n 2] + 0.0639w[n 3]

38

3 Analog and Digital Systems

such that a corresponding code is below:

10

15

main ( ) {
int x , y ;
int wn , wnm1 , wnm2 , wnm3 ;
wn =0; // initialize filter memory with zeros
wnm1 =0;
wnm2 =0;
wnm3 =0;
while (1) { // infinite loop
x = readAD ( ) ;
wn = x + 0.9658* wnm1 -0.5826* wnm2
+0.1060* wnm3 ;
y = 0.0639 * wn +
0.1916* wnm1 +
0.1916* wnm2 +
0.0639 * wnm3 ;
writeDA ( y ) ;
wnm3 = wnm2 ; // prepare for next iteration
wnm2 = wnm1 ;
wnm1 = wn ;
}
}

3.4 Solutions: Extra Exercises


3.1.

To be done. 1

3.2.

To be done. 2

3.3.

The gains can be obtained with:

z =[ exp ( j * pi /4) exp ( j *2* pi /3) ]


Hz = polyval (b , z ) ./ polyval (a , z )
Hgainlinear = abs ( Hz )
Hphase = angle ( Hz )
HgaindB =20* log10 ( abs ( Hz ) )

The difference equation is


y[n] = 0.0226x[n] + 0.0906x[n 1] + 0.1359x[n 2] +
0.0906x[n 3] + 0.0226x[n 4] + 1.4198y[n 1] 1.1299y[n 2] +
0.4116y[n 3] + 0.0638y[n 4]
3.4.

To be done. 4

3.5.

To be done. 5

3.5 Solutions: Exercises not in the book


3.6.

To be done. 6

3.7.

To be done. 7

3.8.

To be done. 8

3.9.

To be done. 9

39

3.10. To be done. 10
3.11. To be done. 11
3.12. To be done. 12

3.5 Solutions: Exercises not in the book


Explain the discussion: For example, a unity-gain 20-kHz 5-pole,
3-dB ripple Chebyshev MFB filter with a 2nd pole-pair fn of 19.35 kHz
and a Q of 8.82 needs an op amp with unity gain bandwidth of at least
17 MHz. On the other hand, a 5-pole Butterworth MFB filter, with a
worst case Q of 1.62 needs only a 3.2-MHz op amp. The same 5-pole
Butterworth filter implemented with a Sallen-Key topology would require
a 8.5-MHz op amp in the high-Q section.
3.1.

The discussion tells that approximations such as Chebyshev and elliptic


achieve sharp transition bands but use poles with high Q. These high
Q values require fast opamps.
3.2.

Explain the Op Amp Slew Rate.

When you apply a step function u(t) to the input of an opamp, you can
see that it takes some time until the output goes from 0 to 1. This is
related to the slew rate, which is faster for opamps that can deal with
higher frequencies.
8) Reproduce on Octave / Matlab figs. 13 and 15 of texas_sbfa001a.pdf
assuming a Butterworth response.
Fig 13 is approximated by the commands below. Note that the Bessel
filter is not the same as the one used by Texas because we are not
positioning the cutoff frequency as they did. Also, the other two filters
may be different.
cutoffFrequency = 20000; % in Hz
N = 5; % order
w = linspace (2* pi *200 ,2* pi *200000 ,1000) ;

40

3 Analog and Digital Systems

[ Bs , As ] = butter (N , 2* pi * cutoffFrequency , 's ') ;


Hbu = freqs ( Bs , As , w ) ;
[ Bs , As ] = cheby1 (N ,3 ,2* pi * cutoffFrequency , 's ') ;
Hbe = freqs ( Bs , As , w ) ;

10

[ Bs , As ] = besself (N ,2* pi * cutoffFrequency ) ;


Hch = freqs ( Bs , As , w ) ;

15

20

clf
semilogx ( w /(2* pi ) ,20* log10 ( abs ( Hbu ) ) )
hold on
semilogx ( w /(2* pi ) ,20* log10 ( abs ( Hbe ) ) , 'k ')
semilogx ( w /(2* pi ) ,20* log10 ( abs ( Hch ) ) , 'r ')
axis ([200 200 e3 -90 10])
legend ( ' But ' , ' Bes ' , ' Che ') ;
grid

9) Repeat 8) but at the lab.


10) Projete um filtro digital que possa ter desempenho similar ao analogico em 8). Estude os efeitos do uso de apenas 8 bits para representar
os coeficientes do filtro e armazenar os sinais. Leia 2009_High Speed
and Low Power FPGA Implementation of FIR Filter for DSP Applications.pdf e 2004_Losada_Practical FIR Filter Design in MATLAB.pdf
como base. Note que o toolbox de fixed-point do Octave eh um tanto
distinto do do Matlab. Pode usar qualquer um.
Vide a nova versao do livro sobre quantizar os coeficientes do filtro
usando Octave.
3.3.

Study the anti-aliasing filters at http://www.minicircuits.com.

Using FilterPro, execute the project of a reject-band using default


options, which should lead to an order 6 and cutoff frequency of 1 kHz.
a) What does it mean Min GBW reqd. in the end of the Schematic?
b) how to interpret the Group Delay plot? c) Why each stage of SOS
has f0, BW and Q? d) Use Edit to re-do the project using a Chebyshev
with a maximum of 1 dB ripple in the passband instead of Bessel. How
did that impact the Group delay?

3.4.

a) Min GBW is the minimum product of gain versus bandwidth that


the opamp should be able to supply. The higher this value, the better.

3.5 Solutions: Exercises not in the book

41

Figure 3.2: Reject-band with default options.

Figure 3.3: Reject-band with a Chebyshev approximation.

b) The group delay shows how the frequency components of the input
signal get delayed. This delay is frequency-dependent. For example,
its peak is located at approximately 533.3 Hz, and at this frequency
the input component (the component at 533.3 Hz) gets delayed by 991
s. For components with frequency less than approximately 85 Hz, the
delay the filter imposes is 548 s.
Each SOS corresponds to a pair of poles with its own f0, BW and Q.
The combination of the 3 SOS compose the final transfer function.

42

3 Analog and Digital Systems

The group delay for Chebyshev of Figure 3.3 can be compared to the
one with Bessel in Figure 3.2. It can be seen that the poles of Chebyshev
have higher Q (from approximately 1 to 4 is the last two SOS) and
the group delay is very different and worse for Chebyshev, which has a
peak of 2260 sat the frequency 642.2 Hz. More than twice the delay
imposed by the Bessel filter at the peak frequency.
Study the advantages and disadvantages when comparing Butterworth, Chebyshev and Bessel responses.

3.5.

In summary, Bessel has a good group delay behavior but a poor attenuation (gain) behavior. Chebyshev is the opposite while Butterworth is
a trade of between the two.
When cascading the 2nd order stages, why the stages with lower
Q are placed first by Filter Pro?

3.6.

To avoid saturation (overflow when the filter is digital) because a specific


frequency can then get attenuated and just afterwards amplified. The
opposite sequence could saturate the signal.
Compare the MFB and Sallen-Key topologies. Can you find a
more sophisticated topology in the literature? If yes, describe it.

3.7.

There are topologies better than Sallen-Key. For example, read: http:
//www.maxim-ic.com/app-notes/index.mvp/id/1762.
3.8.

Briefly explain what sensitivity means.

If the frequency response (or other function) has a high sensitivity to a


specific parameter, it means that small changes in this parameter can
greatly affect the frequency response. The topology of filters are better
if they make the frequency response not too sensitive to parameters
such as capacitor and resistor values.
Study the issue discussed at http://www.dsprelated.com/
groups/matlab/show/5738.php.

3.9.

The discussion is about the distinction between the cutoff frequency


c and the passband frequency p (the frequency at the corner of the
passband). The cutoff frequency is basically the 3 dB frequency while
the gain at the passband frequency p can be arbitrary. One thing to
note is that the fir1 function assumes that its cutoff frequency has a
gain of 6 dB (instead of 3 dB).

3.5 Solutions: Exercises not in the book

43

3.10. Study the algorithm used to design [b, a]=butter(2,1/4) including

the pre-warping stage.

Using Matlab, the step 1 is


get analog, pre-warped frequencies
and it uses u = 2*fs*tan(pi*Wn/fs);. At step 5 one can see the bilinear
function.
Octave also has pre-warping with W = 2/T*tan(pi*W/T); and a similar
structure.
3.11. Using the function fir1, compare the FIR filters with cutoff fre-

quency /4 rad for the windows Hamming, Hann and rectangular. The
commands can be
bham = fir1 (30 ,1/3 , hamming (31) ) ;
bhan = fir1 (30 ,1/3 , hanning (31) ) ;
bret = fir1 (30 ,1/3 , rectwin (31) ) ;

and freqz can help. How do they compare with respect to: attenuation,
decay, side lobe and width of the main lobe.
The following commands can be used
bham = fir1 (30 ,1/3 , hamming (31) ) ;
freqz ( bham ,1)
grpdelay ( transpose ( bham ) ) ;

3.12. The Kaiser window is very flexible. Study the project below

that uses Fs = 11025 Hz, passband [0, 1000] Hz, and rejection band
[1200, Fs /2]. The minimum attenuation at rejection band is 40 dB and
the maximum ripple at the passband is 5% (i. e., the filter can go from
1 to 0.95 at the passband).
[n , w , beta , ftype ] = kaiserord ([1000 ,1200] , [1 ,0] ,
[0.05 ,0.01] , 11025) ;
freqz ( fir1 (n ,w , ftype , kaiser ( n +1 , beta ) , ' noscale ')
,1 ,[] ,11025) ;

Design an IIR Butterworth that meets the requirements and compare


the order with the Kaiser FIR filter.
The code below illustrates a solution. Note that the order of the
Butterworth is too large (order 30) and the design function has numerical
problems.

44

10

15

3 Analog and Digital Systems

% design the FIR


[n , w , beta , ftype ] = kaiserord ([1000 ,1200] , [1 ,0] ,
[0.05 ,0.01] , 11025) ;
Bkaiser = fir1 (n ,w , ftype , kaiser ( n +1 , beta ) , ' noscale ') ;
[ Hkaiser , w ]= freqz ( Bkaiser ,1 ,[] ,11025) ;
% design the IIR
Wp =1000/(11025/2) ;
Ws =1200/(11025/2) ;
Rp =20* log10 (0.95) ;
Rs =40;
[n , Wn ] = buttord ( Wp , Ws , Rp , Rs ) ;
[ Bbutter , Abutter ] = butter (n , Wn ) ;
[ Hbutter , w ]= freqz ( Bbutter , Abutter ,[] ,11025) ;
plot (w , abs ( Hkaiser ) ,w , abs ( Hbutter ) ) ;
pause
plot (w ,20* log10 ( abs ( Hkaiser ) ) ,w ,20* log10 ( abs ( Hbutter ) ) ) ;

3.13. New question Can you generate random noise and filter it?

N =1000;
x = randn (1 , N ) ;
psd ( x )
pause
[B , A ]= butter (5 ,0.3 , ' high ') ; % high - pass filter
y = filter (B ,A , x ) ;
psd ( y )

You might also like