of 203
8/11/2019 IT_Y5_new_NW
1/203
TCP/IP
IT 5012
Sample Question
for
Second semester
8/11/2019 IT_Y5_new_NW
2/203
1. Discuss how to make routing efficient and keep routing table small using the network
portion of a destination address. (20 marks)
2. Describe the IP algorithm used to forward datagram. (10 marks)
3. How to make routes using IP address between source and destination when you want to sent
a datagram. (20 marks)
4. When a datagram arrive at a best, how to handle it. (20 marks)
5. When encounter an error how to report the error to the original source and how to correct it.
(20 marks)
6. Describe about Testing destination reach ability and status. (10 marks)
7. When the routers make routing changes. Explain about it completely. (20 marks)
8.
Explain the discovering router before it can send datagrams to destinations an other
networks. (20 marks)
9. Describe the protocol which provides ports used to distinguish among multiple programs
executing on a single machine, completely. (10 marks)
10.Describe the format of UPD messages. (10 marks)
11.How a UPD datagram encapsulate in an IP datagram for transmission across an internet.
And also describe the conceptual layering of UDP. (20 marks)
12.Discuss about UDP Multiplexing , Demultiplexing , and Ports. (10 marks)
13.How many features that can characterize the interface between application programs and
the TCP/IP reliable delivery service . And also explain those features . (20 marks)
14.Show how the simplest positive acknowledgement protocol transfers data and also show
Timeout and retransmission that occurs when a packet is lost. (10 marks)
15.Describe the format of a TCP segment . Explain it completely. (10 marks)
16.Discuss the Acknowledgements and Retransmission. (10 marks)
17.How to establishing a TCP Connection. Explain it. (10 marks)
18.
How to closing a TCP Connection. Explain it briefly. (10 marks)
19.Draw the diagram of the TCP finite State Machine and explain about it. (20 marks)
8/11/2019 IT_Y5_new_NW
3/203
Introduction to Computer System
IT 5012
Sample Answer and Question
for
Second semester
8/11/2019 IT_Y5_new_NW
4/203
1. Discuss how to make routing efficient and keep routing table small using the network
portion of a destination address. (20 Marks)
Solution:
Using the network portion of a destination address instead of the complete host address
makes routing efficient and keeps routing table small. More important, it helps hide
information, keeping the details of specific hosts confined to the local environment in
which those hosts operate. Typically, a routing table contains pairs (N,R), where N is the
IP address of the destination network, and R is the IP address of the next router along the
path to the network N. Router R is called next hop, and the idea of using a routing table to
store a next hop for each destination is called next-hop routing. Thus, the routing table in a
router R only specifies one step along the path from R to a destination network- the router
does not know the complete path to a destination.
It is important to understand that each entry in a routing table points to a router that can be
reached across a single network. That is, all router listed in machine Ms routing table
must lie on networks to which M connects directly. When a datagram is ready to leave M,
IP software locates the destination IP address and extracts the network portion. M then
uses the network portion to make a routing decision, selecting a router that can be reached
directly.
The example internet consists of four networks connected by three routers. In the figure,
the routing table gives the routes that router R uses. Because R connects directly to
networks 20.0.0.0 and 30.0.0.0, it can use direct delivery to send a host on either of those
networks. Given a datagram destined for a host on the network 40.0.0.0, R routes it to the
address of router S, 30.0.0.7. S will then deliver the datagram directly. R can reach
address 30.0.0.7 because both R and S attach directly to network 30.0.0.0.
To hide information, keep routing tables small, and make routing decisions efficient, IP
routing software only keeps information about destination network addresses, not about
individual host addresses.
8/11/2019 IT_Y5_new_NW
5/203
0.0.0.0 ELIVER DIRECTLY
0.0.0.0 ELIVER DIRECTLY
0.0.0.0 0.0.0.5
0.0.0.0 0.0.0.7
(b)
Figure (a) An example internet with 4 networks and 3 routers and (b) the routing table in R
2. Describe the IP algorithm used to forward datagram. (10 marks)
Solution:
The IP algorithm used to forward datagram becomes:
TO REACH HOSTS
ON NETWORK
ROUTE TO THIS
ADDRESS
8/11/2019 IT_Y5_new_NW
6/203
3. How to make routes using IP address between source and destination when you want to sent
a datagram. (20 marks)
Solution:
It is important to understand that except for decrementing the time to live and re-computing
the checksum, IP routing does not alter the original datagram. In particular, the datagram
source and destination addresses remain unaltered; they always specify the IP address of
the original source and the IP address of the ultimate destination. When IP executes the
routing algorithm, it selects a new IP address, the IP address of the machine to which the
datagram should be sent next. The new address is most likely the address of a router.
However, if the datagram can be delivered directly, the new address is the same as the
address of the ultimate destination.
The IP address selected by the IP routing algorithms is known as the next-hop address
because it tells where the datagram must be sent next. After executing the routing
algorithm, IP passes the datagram and the next hop address to the network interface
software responsible for the physical network over which the datagram must be sent. The
network interface software binds the next hop address to a physical address, forms a frame
using that physical address, places the datagram in the data portion of the frame, and send
the results. After using the next hop address to find a physical address, the network
interface software discards the next hop address.
IP dutifully extracts the destination address in each datagram and uses the routing table to
produce a next hop address. It then passes the datagram and next hop address to the
network interface, which re-computes the binding to a physical address. Figure shows that
there are two important reasons.
First, the routing table provides an especially clean interface between IP software that
routes datagram and high level software that manipulates routes. To debug routing
problems, network manager often needs to examine the routing tables. Second, the whole
point of the Internet Protocol is to build an abstraction that hides the details of underlying
networks. Figure shows the address boundary. We will see that observing the boundary
8/11/2019 IT_Y5_new_NW
7/203
also helps keep the implementation of remaining TCP/IP protocols easy to understand, test
and modify.
Figure IP software and the routing tables it uses resides above the address boundary.
4. When a datagram arrive at a best, how to handle it. (20 marks)
Solution:
When an IP datagram arrives at a host, the network interface software delivers it to the IPmodule for processing. If the datagrams destination address matches the hosts IP address,
IP software on the host accepts the datagram and passes it to the appropriate higher-level
protocol software for further processing. If the destination IP address does not match, a
host is required to discard the datagram.
Unlike hosts, routers perform forwarding. When an IP datagram arrives at a router, it is
delivered to the IP software. Again, two cases arrive: the datagram could have reached its
final destination, or it may need to travel further. As with the host, if the datagram
destination IP address matches the routers own IP address, the IP software passes the
datagram to higher level protocol software for processing. If the datagram has not reached
its final destination, IP routes the datagram using the standard algorithm and the
information in the local routing algorithm.
Even a host may have multiple physical connections, each with its own IP address. When
an IP datagram arrives, the machine must compare the destination internet address to the IP
8/11/2019 IT_Y5_new_NW
8/203
address for each of its network connections. If any match, it keeps the datagram and
processes it. A machine must also accept datagrams that were broadcast on the physical
network. If the address does not match any of the local machines addresses, IP decrement
the Time-To-Live field in the datagram header, discarding the datagram if the count
reaches zero, or computing a new checksum and routing the datagram if the count remains
positive.
While using a host as a router is not usually a good idea, if one chooses to use that
arrangement, the host must be configured to route datagrams just as a router does.
There are four reasons why a host not designated to serve as a router should refrain from
performing any router functions. First, when such a host receives a datagram intended for
some other machine, something has gone wrong with internet addressing, routing, or
delivery. The problem may not be revealed if the host takes corrective action by routing
the datagram. Second, routing will cause unnecessary network traffic (and may steal CPU
time from legitimate uses of the host). Third, simple errors can cause chaos. Routers do
more than merely route traffic. Routers use a special protocol to report errors, while hosts
do not (again, to avoid having multiple error reports bombard a source). Routers also
propagate routing information to ensure that their routing tables are consistent. If hosts
route datagrams without participating fully in all router functions, unexpected anomalies
can arise.
5. When encounter an error how to report the error to the original source and how to correct
it. (20 marks)
Solution:
Technically, ICMP is an error reporting mechanism. It provides a way for routers that
encounter an error to report to the original source.
When a datagram causes an error, ICMP can only report the error condition back to the
original source of the datagram; the source must relate the error to an individual application
program or take other action to correct the problem.
8/11/2019 IT_Y5_new_NW
9/203
6. Describe about Testing destination reachability and status. (10 marks)
Solution:
TCP/IP protocol provides facilities to help network managers or users identify network
problems. One of the most frequently used debugging tools invokes the ICMP echo
request and echo reply messages. A host or router sends an ICMP echo request message to
a specified destination. Any machine that receives an echo request formulates an echo
reply and returns it to an original sender. The request contains an operational data area; the
reply contains a copy of the data sent in the request. The echo request and associated canbe used to test whether the destination is reachable and responding.
The command users invoke to send ICMP echo requests is named ping. Sophisticated
versions of ping send a series of ICMP echo request, capture responses, and provide
statistics about datagram loss. They allow the user to specify the length of the data being
sent and the interval between requests. Less sophisticated versions merely send one ICMP
echo request and await a reply.
7. When the routers make routing changes. Explain about it completely. (20marks)
Solution:
Internet routing tables usually remain static over long periods of time. If the networks
topology changes, routing tables in a router or host may become incorrect. A change can
be temporary (e.g., when hardware needs to be repaired) or permanent (e.g., when a new
network is added to the internet). Routers are assumed to know correct routes; hosts begin
with minimal routing information and learn new routes from routers.
When a router detects a host using a non-optimal route, it sends the host an ICMP
message, called a redirect, requesting that the host change its route. The router also
forwards the original datagram onto its destination.
The advantage of the ICMP redirect scheme is simplicity: it allows a host to boot knowing
the address of only one router on the local network. The initial router returns ICMP
redirect messages whenever a host sends a datagram for which there is a better route. The
host routing table remains small but still contains optimal routes for all destinations in use.
8/11/2019 IT_Y5_new_NW
10/203
In the figure, assume source S sends a datagram to destination D. Assume that router R1
incorrectly routes the datagram through router R2 instead of through router R4 (i.e., R1
incorrectly chooses a longer path than necessary). When router R5receives the datagram, it
cannot send an ICMP redirect message to R1because it does not know R1s address.
In addition to the requisite TYPE, CODE, and CHECKSUM fields, each redirect message
contains a 32-bits ROUTER INTERNET ADDRESS field and an INTERNET HEADER
field.
The ROUTER INTERNET ADDRESS field contains the address of a router. The
INTERNET HEADER field contains the IP header plus the next 64 bits of the datagram
that triggered the message. The CODE field of an ICMP redirect message further specifies
how to interpret the destination address, based on values assigned as follows:
Code Value Meaning
0
Redirect datagrams for the Net (now obsolete)
1
Redirect datagrams for the Host
2
Redirect datagrams for the Type of Service and Net
3
Redirect datagrams for the Type of Service and Host
Figure: ICMP redirect messages do not provide routing changes among routers. In this
example, router R5cannot redirect R1to use the shorter path for datagrams from S to D
8/11/2019 IT_Y5_new_NW
11/203
Figure: ICMP redirect message format
8. Explain the discovering router before it can send datagrams to destinations an other
networks. (20 marks)
Solution:
After a host boots, it must learn the address of at least one router on the local network
before it can send datagrams to destinations on other networks. ICMP supports a router
discovery scheme that allows a host to discover a router address.
ICMP router discovery is not the only mechanism a host can use to find a router address.
The ICMP router discovery scheme helps in two ways. First, instead of providing a
statically configured router address via a bootstrap protocol, the scheme allows a host to
obtain information directly from the router itself. Second, the mechanism uses a soft state
technique with timers to prevent hosts from retaining a route after a router crashes router
advertise their information periodically, and host discard a route if the timer for a route
expires.
Besides the TYPE, CODE, and CHECKSUM fields, the message contains a field labeled
NUM ADDRS that specifies the number of address entries which follow (often 1), an
ADDR SIZE field that specifies the size of an address in 32-bit units (1 for IPv4
addresses), and a LIFETIME field that specifies the time in seconds a host may use the
advertised address(es).
The remainder of the message consists of NUM ADDRS pairs of fields, where each pair
contains a ROUTER ADDRESS and an integer PRECEDENCE LEVEL for the route. Of
course, a host must never send a router advertisement message.
8/11/2019 IT_Y5_new_NW
12/203
Fig ICMP router advertisement message format used with IPv4
9. Describe the protocol which provides ports used to distinguish among multiple
programs executing on a single machine, completely. (10 marks)
Solution:
UDP provides protocol ports used to distinguish among multiple programs executing on a
single machine. That is, in addition to the data sent, each UDP message contains both a
destination port number and a source port number, making it possible for the UDP software
at the destination to deliver the message to the correct recipient and for the recipient to send
a reply.
The User Datagram Protocol (UDP) provides an unreliable connectionless delivery service
using IP to transport messages between machines. It uses IP to carry messages, but adds
the ability to distinguish among multiple destinations within a given host computer.
10. Describe the format of UPD messages. (10 marks)
Solution:
Each UDP message is called a user datagram. A user datagram consists of two parts: a
UDP header and a UDP data area. The header is divided into four 16-bit fields that specify
the port from which the message was sent, the port to which the message is destined, the
message length, and a UDP checksum.
The SOURCE PORT and DESTINATION PORT fields contain the 16-bit UDP protocol
port numbers. The LENGTH field contains a count of octets in the UDP header and the
user data. Thus, the minimum value for LENGTH is eight, the length of the header alone.
The UDP checksums is optional and need not be used at all; a value of zero in the
CHECKSUM field means that the checksum has not been computed. Thus, the UDP
8/11/2019 IT_Y5_new_NW
13/203
checksum provides the only way to guarantee that data has arrived intact and should be
used. When the computed checksum is zero, UDP uses the representation with all bits set
to one.
Figure: The format of fields in a UDP datagram
11. How a UPD datagram encapsulate in an IP datagram for transmission across an
internet. And also describe the conceptual layering of UDP. (20 marks)
Solution:
Layering UDP above IP means that a complete UDP message, including the UDP header
and data, is encapsulated in an IP datagram as it travels across an internet.
The IP layer prepends a header to what it receives from UDP. Finally, the network
interface layer embeds the datagram in a frame before sending it from one machine to
another.
A packet arrives at the lowest layer of network software and begins its ascent through
successively higher layers. Each layer removes one header before passing the message on,so that by the time the highest level passes data to the receiving process, all headers have
been removed.
The IP layer is responsible only for transferring data between a pair of hosts on an internet,
while the UDP layer is responsible only for differentiating among multiple sources or
destination within one host.
8/11/2019 IT_Y5_new_NW
14/203
Figure: The Conceptual Layering of UDP between application programs and IP
Figure: A UDP datagram is encapsulated in an IP datagram for transmission across an
internet. The datagram is further encapsulated in a frame each time it travels across a
single network
.12. Discuss about UDP Multiplexing , Demultiplexing , and Ports. (10 marks)
Solution:
Conceptually, all multiplexing and demultiplexing between UDP software and application
programs occur through the port mechanism. While processing input, UDP acceptsincoming datagrams from the IP software and demultiplexes based on the UDP destination
port.
A UDP port is as a queue. When UDP receives a datagram, it checks to see that the
destination port number matches one of the ports currently in use. If not, it sends an ICMP
port unreachable error message and discards the datagram. If a match is found, UDP
8/11/2019 IT_Y5_new_NW
15/203
enqueues the new datagram at the port where an application program can access it. Of
course, an error occurs if the port is full, and UDP discards the incoming datagram.
Figure Example of demultiplexing one layer above IP
13. How many features that can characterize the interface between application programs
and the TCP/IP reliable delivery service . And also explain those features . (20 marks)
Solution:
The interface between the application programs and TCP/IP reliable delivery service can be
characterized by 5 features:
Stream Orientation. When two application programs (user processes) transfer large
volumes of data, we think of data as a stream of bits, divided into 8-bit octets, which are
informally called bytes. The stream delivery service on the destination machine passes to
the receiver exactly the same sequence of octets that the sender passes to it on the source
machine.
8/11/2019 IT_Y5_new_NW
16/203
Virtual Circuit Connection. One application places a call which must be accepted by
the other. Protocol software module in the two operating systems communicate by sending
messages across an internet, verifying that the transfer is authorized, and that both sides are
ready. Once all details have been settled, the protocol modules inform the application
programs that a connection has been established and that transfer can begin.
Buffered Transfer. Application programs send a data stream across the virtual circuit
by repeatedly passing data octets to the protocol software. When transferring data, each
application uses whatever size pieces it find convenient, which can be as small as a single
octet. At the receiving end, the protocol software delivers octets from the data stream in
exactly the same order they were sent, making them available to the receiving application
program as soon as they have been received and verified.
For those application where data should be delivered even though it does not fill a buffer,
the stream service provides a push mechanism that application use to force a transfer. At
the sending side, a push forces protocol software to transfer all data that has been generated
without waiting to fill a buffer. The push function only guarantees that all data will be
transferred; it does not provides record boundaries.
Unstructured Stream. It is important to understand that the TCP/IP stream service does
not honor structure data streams. Applications programs using the stream service must
understand stream content and agree on stream format before they initiate a connection.
Full Duplex Connection. Connections provided by the TCP/IP stream service allow
concurrent transfer in both directions. Such connections are called full duplex. From the
point of view of an application process, a full duplex connection consists of two
independents streams flowing in opposite directions, with no apparent interaction. The
advantage of a full duplex connection is that the underlying protocol software can send
control information for one stream back to the source in datagrams carrying data in the
opposite direction. Such piggybacking reduces network traffic.
14 . Show how the simplest positive acknowledgement protocol transfers data and also
show Timeout and retransmission that occurs when a packet is lost. (10 marks)
Solution:
8/11/2019 IT_Y5_new_NW
17/203
A protocol using positive acknowledgement with retransmission in which the sender awaits
an acknowledgement for each packet sent. Vertical distance down the figure represents
increasing time and diagonal lines across the middle represent network packet
transmission.
Timeout and retransmission occurs when a packet is lost. The dotted lines show the time
that would be taken by the transmission of a packet and its acknowledgement, if the packet
was not lost.
15. Describe the format of a TCP segment . Explain it completely. (10 marks)
Solution:
8/11/2019 IT_Y5_new_NW
18/203
The unit of transfer between the TCP software on two machines id called a segment.
Segments are exchanged to establish connections, transfer data, send acknowledgements,
advertise window sizes, and close connections.
Each segment is divided into two parts, a header followed by data. The header, known as
TCP header, carries the expected identification and control information. Fields SOURCE
PORT and DESTINATION PORT contain the TCP port numbers that identify the
application programs at the ends of the connection. The SEQUENCE NUMBER field
identifies the position in the senders byte stream of the data in the segment. The
ACKNOWLEDGE NUMBER field identifies the number of the octets that the source
expects to receive next.
The HLEN field contains an integer that specifies the length of the segment header
measured in 32-bit multiples. The OPTIONS field varies in length, depending on which
options have been included. The 6-bit field marked RESERVED is reserved for future use.
TCP software uses the 6-bit field labeled CODE BITS to determine the purpose and
contents of the segment. The WINDOW field contains a 16-bit unsigned integer in
network-standard byte order.
Figure The format of TCP segment with a TCP header followed by data.
16. Discuss the Acknowledgements and Retransmission. (10 marks)
Solution:
A TCP acknowledgement specifies the sequence number of the next octet that the receiver
excepts to receive. The TCP acknowledgement scheme is called cumulative because it
8/11/2019 IT_Y5_new_NW
19/203
reports how much of the stream has accumulated. Cumulative acknowledgements have
both advantages and disadvantages. One advantage is that acknowledgements are both
easy to generate and unambiguous. Another advantage is that lost acknowledgements do
not necessarily force retransmission. A major disadvantage is that the sender does not
receive information about all successful transmissions, but only about a single position in
the stream that ahs been received.
17. How to establishing a TCP Connection . Explain it . (10 marks)
Solution:
The first segment of a handshake can be identified because it has the SYN nit set in the
code field. The second message has both the SYN bit and ACK bits set, indicating that it
acknowledges the first SYN segment as well as continuing the handshake. The final
handshake message is only an acknowledgement and is merely used to inform the
destination that both sides agree that a connection has been established.
The handshake is carefully designed to work even if both machines attempt to initiate a
connection simultaneously. Thus, a connection can be established from either end or from
both ends simultaneously. Once the connection has been established, data can flow in both
directions equally well. There is no master or slave.
The three-way handshake is both necessary and sufficient for correct synchronization
between the two ends of the connection. TCP builds on an unreliable packet deliver
service, so message can be lost, delayed, duplicated, or delivered out of order. Thus, the
protocol must use a timeout mechanism and retransmit lost requests. Trouble arises if
retransmitted and original requests arrive while the connection is being established. A
three-way handshake solves these problems.
Figure The sequence of messages in a three-way handshake.
8/11/2019 IT_Y5_new_NW
20/203
18. How to closing a TCP Connection . Explain it briefly. (10 marks)
Solution:
Two programs that use TCP to communicate can terminate the conversation gracefully
using the close operation. TCP uses a modified three-way handshake to close connections.
When an application program tells TCP that it has no more data to send, TCP will close the
connection in one direction. To close its half of a connection, the sending TCP finishes
transmitting the remaining data, waits for the receiver to acknowledge it, and then sends a
segment with the FIN bit set. The receiving TCP acknowledges the FIN segment and
informs the application program on its end that no more data is available (e.g., using the
operating systems end-of-file mechanism).
Once a connection has been closed in a given direction, TCP refuses to accept more data
for that direction. Meanwhile, data can continue to flow in the opposite direction until the
sender closes it.
The difference between three-way handshakes used to establish and break connections
occurs after a machine receives the initial FIN segment. Instead of generating a second
FIN segment immediately, TCP sends an acknowledgement and then informs the
application of the request to shut down. Informing the application program of the request
and obtaining the response may take considerable time. Finally, when the application
program instructs TCP to shut down the connection completely, TCP sends the second FIN
segment and the original site replies with the third message, an ACK.
Figure The modified three-way handshake used to close connection.
8/11/2019 IT_Y5_new_NW
21/203
19. Draw the diagram of the TCP finite State Machine and explain about it. (20 marks)
Solution:
The operation of TCP can best be explained with a theoretical model called a
finite state machine. Figure shows the TCP finite state machine , with circles representing
state and arrows representing transitions between them. An active open command forces a
transition from the CLOSED state to the SYN SENT state . When TCP follows the
transition, it emits a SYN segment. When the other end returns a segment that contains a
SYN plus ACK, TCP moves to the ESTABLISHED state and begins data transfer .
The TIME WAIT state reveals how TCP handles some of the problem incurred
with unreliable delivery . Because the timer allows TCP to distinguish old connections
from new ones , it prevents TCP from responding with a RST (reset) if the other end
retransmits a FIN request.
8/11/2019 IT_Y5_new_NW
22/203
8/11/2019 IT_Y5_new_NW
23/203
B.E and M.E ( Second Semester)
Sample Question
IT-5013 Digital Signal Processing
Chapter 3
1. Determine the Z-transform and sketch the ROC of the signals
(a) x (n) = (1/2)n u(n)
(b) x (n) = -3u(-n-1) (10-Marks)
2. State and prove ANY THREE properties of the Z-transform. (20-Marks)
3. Determine the Z-transform and sketch the ROC of the signal
x(n)=[3(2)n
-4(3)n]u(n). (10-Marks)
4. Determine the system function and the unit sample response of the system describe by
the difference equation.
y(n)=1/2 y(n-1)+2x(n) (10-Marks)
5. Determine the inverse Z-transform of
X(Z)=21 5.05.11
1 + ZZ
When
(a)
ROC: |Z| > 1
(b)ROC: | Z| < 0.5
(c)
ROC: 0.5 < |Z| < 1 (20-Marks)
6. Determine the causal signal x(n) having the Z-transform.
1X(Z)=
( 1 + Z-1
) ( 1 - Z-1
)2
(20-Marks)
7. The well-known Fibonacci sequence of integer numbers is obtained by computing each
term as the sum of the two previous ones. The first few terms of the sequence are
1,1,2,3,4,5,8.
Determine a closed-form expression for the nth term of the Fibonacci sequence.
(20-Marks)
8. Determine the step response of the system
y(n)=
y(n-1) + x(n) -1 < < 1when the initial condition is y(-1)=1 (20-Marks)
9. Determine the unit step response of the system describe by the difference equation
y(n) = 0.9y(n-1)- 0.81y(n-2) + x(n)
under the following initial condition:
y(-1)=y(-2)=1 (20-Marks)
8/11/2019 IT_Y5_new_NW
24/203
10. Determine the transient and steady-state response of the system characterized by the
Difference equation
y(n) = 0.5y(n-1) + x(n)
when the input signal is x(n)=10 cos(n/4)u(n).
The system initially at rest (i.e, it is relaxed) (20-Marks)
11. Determine the inverse Z-transform of
H(Z)=21
1
5.15.31
43
+
ZZ
Z
Specify the ROC of H(Z) and determine h(n) for the following conditions:
(a)
The system is stable.
(b) The system is causal.
(c)
The system is purely anticausal. (20-Marks)
12. Compute the convolution of the following signals by means of Z-transform
x1(n)=
/2
(20-Marks)
24. Determine the spectrum of the signal.
x(n) = cos 0n
when (a) 0 = 2 (b) 0 =3
(20-Marks)
25. Determine the Fourier series coefficients and the power density spectrum of the signal
show in fig:
(20-Marks)
26. Determine the signal x(n) corresponding to the spectrum
1 | | c
X ( ) =
0 otherwise
(20-Marks)
27. Determine the Fourier transform and the energy density spectrum of the sequence
A 0 n L - 1
x ( n ) =
0 otherwise
which is illustrated in fig.
(20-Marks)
28. Determine the Fourier transform of the signal
x(n)=a n
-1 < a < 1 (20-Marks)
- N N0 nL
x(t)
A
8/11/2019 IT_Y5_new_NW
27/203
29. Consider the full-wave rectified sinusoid in fig
(a)Determine its spectrum Xa(F).
(b)
Compute the power of the signal.
(c)
plot the power spectrum density.
(d)Check the validity of Parsevals relation for this signals. (20-Marks)
30. Compute the Fourier transform of the following signals.
(a) x(n) = u(n) - u(n-6)
(b) x(n) = 2nu(n-6)
(c) x(n) = cos( /3)n [u(n) - u(n-6)] (20-Marks)
8/11/2019 IT_Y5_new_NW
28/203
BE. IT
Digital Signal Processing
Sample Questions and Answers
CHAPTER -3
1. Determine the Z-transform and sketch the ROC of the signal. (10 marks )
(a)x(n)= (1/2)nu(n)
(b)x(n)= -3u(-n-1)
Solution:
(a)x(n) = (1/2)n u(n)
X(Z) =
=n
x(n) Z-n
=
=0n
(1/2)nZ
-n
=
=0n
(1/2 Z-1)n
=
1
2
11
1
z
ROC: | 1
2
1 Z |< 1
ROC: |Z | >
Re
Im
1/2
(b)x(n) = -3u(-n-1)
X(Z) =
=n
x(n) Z-n
=
=
1
n
-3u (-n-1) Z-n
= -3
=1l
(Z)l (where l = -n)
= -3Z
Z
1
=11
3Z
ROC: |Z|
8/11/2019 IT_Y5_new_NW
29/203
2. State and prove ANY THREE properties of the Z-transform.Scaling in the z-Domain (20-Marks)
IF x(n) Z X(Z) ROC: r1 < |Z| < r2
Then anx(n) Z X(a-1Z) ROC: |a| r1 < |Z| < r2
For any constant a, real or complex.
Proof: By definition,
Z{ anx(n) } =
=n
anx(n)Z
-n
=
=n
x(n) (a-1Z)-n
= X (a-1
Z)
Since the ROC of X(Z) is r1< |Z| < r2, the ROC of X(a-1
Z) is r1< |a-1
Z| < r2(or)|a| r1< |Z| < |a| r2
Time Reversal
IF x(n) Z X(Z) ROC: r1 < |Z| < r2
Then x(-n) Z X(Z-1) ROC:2
1
r< |Z| 3
X(Z) =121
3 Z
-131
4 Z
; ROC: |Z| > 3
Fig: ROC of X(Z)
4. Determine the system function and the unit sample response of the system described by
the difference equation.
y(n) =2
1y (n - 1) + 2x(n) (10 marks)
Solution:
y(n) =2
1y (n - 1) + 2x(n)
Y(Z) =2
1Z
-1Y(Z) + 2 X(Z)
8/11/2019 IT_Y5_new_NW
31/203
Y(Z) (1-2
1Z
-1) = 2 X(Z)
)(
)(
ZX
ZY=
1
2
11
2
Z
H(Z) =1
2
11
2 Z
h(n) = 2 (2
1)
nu(n)
This is the unit sample response of the system.
5. Determine the inverse Z-transform of
X(Z) =21 5.05.11
1 + ZZ
(20 marks)
when (a) ROC: |Z| > 1
(b) ROC: |Z| < 0.5(c) ROC: 0.5 < |Z| < 1
Solution:
X(Z) =21
5.05.11
1 + ZZ
X(Z) =5.05.12
2
+ ZZ
Z
X(Z) =)5.0)(1(
2
ZZ
Z
Z
ZX )(=
)5.0)(1( ZZ
Z =
5.01
21
+
Z
A
Z
A
A1 = (Z-1) 1)(
=ZZ
ZX
A1 =15.0 = ZZ
Z
=5.01
1
A1 = 2
A2 = (Z-0.5) 5.0)(
=ZZ
ZX
A2 = 5.01 = ZZ
Z
=15.0
5.0
A2 = -1
Z
ZX )(=
5.0
1
1
2
ZZ
X(Z) =5.01
27
Z
Z
Z
X(Z) =11 5.01
1
1
2
ZZ
8/11/2019 IT_Y5_new_NW
32/203
(a)When the ROC is |Z| > 1 , the signal x(n) is causal arc terms are causal terms.
x(n) = 2(1)nu(n) (0.5)nu(n)= (2 - 0.5
n) u(n)
(b)When the ROC is |Z| < 0.5 , the signal x(n) is anticausal.
Thus both terms result in anticausal components.
x(n) = [-2 + (0.5)n] u(-n-1)
(c)When the ROC is 0.5 < |Z| < 1 , the signal x(n) is two sided.Thus one of term is a causalpart and the other is anticausal part. Thus,
x(n) = - 2 (1)nu(-n-1) (0.5)nu(n).
6. Determine the causal signal x(n) having the Z-transform
X(Z) =211 )1)(1(
1 + ZZ
(20 marks)
Solution:
X(Z) =211 )1)(1(
1 + ZZ
X(Z) = 2
3
)1)(1( + ZZ
Z
X(Z) has simple pole at p1= -1 and a double pole at p2= p3= 1.Thus partial fraction
exp
Z
ZX )(=
2
2
)1)(1( + ZZ
Z=
2
321
)1(11 +
+
+ Z
A
Z
A
Z
A
A1= (Z+1)1
)(
=ZZ
ZX
A1 = 12
2
)1( =
Z
Z
Z
A1= 2
2
)11()1(
A1=4
1
A3= 1
2
1 =
+ Z
Z
Z
A3=11
12
+
A3=2
1
A2=
Z
ZXZdZd )()1(
2Z=1
A2= 1
2
1 =
+ Z
Z
Z
dZ
d
A2= 2
2
)1(
)1(27)1(
+
+
Z
ZZ1=Z
A2=4
3
4
14
)11(
12)11(2
=
=+
+
2
)1(
21
1
43
1
41
)(
+
+
+
=
ZZZZ
ZX
8/11/2019 IT_Y5_new_NW
33/203
X(Z) =2)1(
21
1
43
1
41
+
+
+ Z
Z
Z
Z
Z
Z
=2)1(2
1
)1(
1
4
3
)1(
1
4
11
1
11
+
+
+ Z
Z
ZZ
x(n) = )(21)(
43)()1(
41 nununun ++
x(n) = )(24
3)1(
4
1nu
nn
++
7. The well-known Fibonancci sequence of integer numbers is obtained by computing each
term as the sum of the two previous one. The first few terms of the sequence are
1,1,2,3,5,8,13,21,34,.Determine a closed form expression for the nth term of the
Fibonancci sequence. (20 marks)
Solution:
y(n) = y(n-1) + y(n-2) ( )A initial conditionn=0 ( )11)2()1()0( =+= yyy
)2(1)1()0()1( =+= yyy
0)1( =y
( ) 12 =y
( ){ } ( ) ( ) 0;1
>
+=
=
++ KZnyZYZKnyZK
n
nK
eqn:
(A) ( ) ( ) ( ){ } ( ) ( ) ( ){ }2211 211 ZyZyZYZZyZYZZY ++++= +++
( ) ( )[ ] ( ) ( ) ( )[ ]211 121 ++++= ++ yZyZYZyZYZ ( ) ( ) 121 ++= ++ ZYZZYZ
( ) 11 21 = + ZZZY
211
1
=ZZ
12
2
=
ZZ
Z
( )
+
+
=
=+
2
51
2
511
21
2
Z
A
Z
A
ZZ
Z
Z
ZY
2
511
+=P ,
2
512
=P
( ) ( )
111 PZZ
ZYPZA ==
1
2
PZPZ
Z=
=
21
1
PP
P
=
8/11/2019 IT_Y5_new_NW
34/203
52
51
2
51
2
51
2
51
+=
+
+
+
=
( ) ( )222 PZZ
ZYPZA ==
2
1
PZPZ
Z=
=
12
2
PP
P
=
52
51
2
51
2
51
2
51
=
+
=
( )
+
+
=+
2
51
52
51
2
51
52
51
ZZZ
ZY
( ) Z
Z
Z
Z
ZY
+
+
=+
52
51
52
51
2
51
52
51
+
+
= 11
2
511
52
51
2
511
52
51
ZZ
( ) ( )nunynn
++=
2
51
2
51
2
51
52
51
( ) ( ) ( )nunnn
+
++
+
=
151
151
1
2
1
5
1
8 . Determine the step response of the system ( ) ( ) xnyny += 1 , 11
8/11/2019 IT_Y5_new_NW
35/203
( )11
1
+
=
ZZX
( ) ( ) ( )ZXZYZZY +++ ++= 1
( ) ( )1
1
1
1
++
+=
ZZYZZY
( ) ( )( )111 111
1 +
+
=
ZZZZY
( )( )( ) ( ) ( )1
2
1
1
11 1111
1
+
+
=
=
Z
A
Z
A
ZZZY
( ) ( )
11
1 11 =
=Z
ZYZA
=
=
=
=
11
1
11
1
1
11
Z
( ) ( )1
1
2 11 =
= ZZYZA
=
=
1
1
1
11Z
( ) ( )
( )( ) ( )( )111 111
111 +
+
+
=
ZZZZY
( ) ( )ZYZny += 1
( ) ( )( )
( )( )
( )nununnun
+
=
1
1
1
( ) ( )nun
nun
+
++=
1
1
1
11
( ) ( )nunnun
+++=1
111
( ) ( )( )nu
nn
+++=
1
1111
( )nunn
+++
= 111
1
1
( )nun
+
= 21
1
1
9 . Determine the unit step response of the system described b difference equation.
( ) ( ) ( ) ( )nxnynyny += 281.019.0 under the following initial conditions:
( ) ( ) 121 == yy (20 marks)
Solution:
( ) ( ) ( ) ( )nxnynyny += 281.019.0( ) ( ) 121 == yy
210 81.09.01)(,)(
)()( +== ZZZA
ZA
ZNZy
Zi
==
=
k
n
nN
k
k
k ZnyZaZN11
0 )()(
8/11/2019 IT_Y5_new_NW
36/203
= { }))2()1(()1( 2122111 ZyZyZaZyZa ++
= 21
21 aZaZa ++
= )81.0()81.0(9.0 1 ++ Z
= 181.009.0
Z
=
==
+
+
==N
k
k
k
k
n
nN
k
k
k
Zi
Za
ZnyZa
ZA
ZNZy
1
110
1
)(
)(
)()(
21
10
81.09.01
81.009.0
)(
)()(
+
==
ZZ
Z
ZA
ZNZyZi
)9.01)(9.01(
81.009.0
1212
1
=
ZeZe
Z
jj
)9.01()9.01( 1212
+
=
Ze
B
Ze
A
jj
)9.01)(9.01(
)9.01()9.01(
1212
1212
+=
ZeZe
ZeBZeA
jj
jj
3
1
12
1
9.0
1
)9.01(
81.009.0
jZ
j
eZe
ZA =
=
3
2
3
9.0
19.01
9.0/81.009.0
j
j
j
e
e
eA
=
866.05.1
779.036.0
j
j
+
+=
B = A*
)9.01(
4936.0026.0
9.01
4936.0026.0)(
1213
+
+=
Ze
j
Ze
jZy
jjZi
)()873
cos()9.0(988.0)(.
nunny nZi +=
10. Determine the transient and steady state response of the system characterized by the
difference equation.
y(n)=0.5 y(n-1) + x(n) when the input signal x(n) = 10 cos (4
n) u(n)
The system is initially at rest (i.e it is relaxed). (20 marks)
Solution:
y(n) = 0.5 y(n-1) + x(n)
Y(Z) = 0.5 y(Z)Z-1
+ X(Z)Y(Z) (1-0.5Z
-1) = X(Z)
8/11/2019 IT_Y5_new_NW
37/203
H(Z) =15.01
1
)(
)(
=ZZX
ZY
One pole at Z=0.5
x(n) =10 cos (4
n) u(n)
+=
+=
2
0
1
01
021
1
cos21
cos1)()cos(
4cos21
)4cos1(10)(ZZ
ZnunZZ
ZZX
Q
21
1
21
)2
11(10
+
=
ZZ
Z
Y(Z) = H(Z) X (Z)
)21)(5.01(
)2
11(10
211
1
+
=
ZZZ
Z
Y(Z) =)1)(1)(5.01(
)2
11(10
14141
1
ZeZeZ
Z
jj
=)1()1()5.01( 1414
1
+
+ Ze
C
Ze
B
Z
A
jj
( ) 221
1
1
21
2
1110
=
+
=Z
ZZ
Z
A
42.21
22
1110
+
=
( ) ( )91.1
172.2
142.4
828.25
414.1110
225
2110=
=
=
=
( ) 41 1
141
1
15.01
21110
je
ZjZeZ
Z
B=
=
)
1
*4511)(455.01(
)45*2
1110
4
.
.
je
=
=)9011))(7071.07071.0(5.01(
))7071.07071.0(2
11(10
j
j
=))0(1)(354.0354.01
)5.05.01(10
jj
j
+
+
=)1)(354.0646.0(
55
jj
j
++
+
= 7.2879.6)4510414)(7.28737.0(
45071.7
=
+
8/11/2019 IT_Y5_new_NW
38/203
C = B* = 6.79 7.28
Y(Z) =1414
1
1
7.2879.6
1
7.2879.6
5.01
9.1
+
+
ZeZeZ jj
y(n) = -1.9(0.5)nu(n) +2*6.79(1)ncos (
n
4
- 28.7) u(n)
The natural or transient rep: is
ynr (n) = -1.9(0.5)nu(n)
The forced or steady state rep: is
yfr(n) = 13.58 cos (
n
4
- 28.7) u(n)
11 . Determine the inverse Z-transform of
( )21
1
5.15.31
43
+
=
ZZ
ZZH .
Specify the ROC of H(Z) and determine h(n) for the following condition
(a)The system is stable(b)The system is causal
(c)The system is purely anticausal. (20 marks)
Solution:
( )21
1
5.15.31
43
+
=
ZZ
ZZH
( )( )( )11
1
312
11
43
=
ZZ
ZZH
( )1
1 31211
+
=Z
B
Z
AZH
21
1
1
31
43=
=
ZZ
ZA
1=A
311
1
1
211
43=
=
ZZ
ZB
2=B
( )11 31
2
211
1
+
=ZZ
ZH
The system has poles at21=Z and .3=Z
(a) The system is stable ROC:2
1 < Z < 3.
( ) ( ) ( ) ( )1322
1
= nununh
n
n
(b)The system is causal ROC:2
1 < Z < 3.
( ) ( ) ( ) ( )nunh nn 322
1 +=
8/11/2019 IT_Y5_new_NW
39/203
(c)The system is anticausal ROC:2
1 < Z < 3.
( ) ( ) ( )1322
1
= nunh n
n
, system is unstable.
12. Compute the convolution of the following signals by means of Z-transform.
(20-Marks)
8/11/2019 IT_Y5_new_NW
40/203
12
)2
1(1
1
=Z
X
2
1:;
2
1 >
= ZROC
Z
Z
{ } )()()()( 2121 zXZXnxnxZ =
2
1237
5)(
2
=
Z
Z
ZZ
ZZXQ
)2
1)(2)(
3
1(
5)(
2
=
ZZZ
ZZX
)2
1)(2)(
3
1(
5)(
=
ZZZ
Z
Z
ZX
)2
1(
)2()
3
1(
)(
+
+
=
Z
C
Z
B
Z
A
Z
ZX
3
1)
2
1)(2(
5
=
=ZZZ
ZA
6=A
2
1)
2
1)(
3
1(
5
=
=ZZZ
ZB
4=B
2
1)2)(
3
1(
5
=
=ZZZ
ZC
10=C
3
1
)10(
2
4
3
1
6)(
+
+
=
ZZ
ZZ
ZX
22
1:,
3
11
)10(
21
4
3
11
6)(
11
1
8/11/2019 IT_Y5_new_NW
41/203
13. Use the one-side Z-transform to determine the zero input response ,y 0),(2 nny in the
following case.
0)2(5.0)1(5.1)( =+ nynyny ; y(-1)=1,y(-2)=0 (10-Marks)
+ =
+
+
n
k
n
kZ ZnxZXZknx )()()(1
|
[ ] 00.05.15.05.11)()2()1()(5.0)1()(5.1)(
121
221
=++
+++++
+++
ZZZZY
ZyyZYZZyZYZzY
21
1
5.05.11
)5.05.1()(
+
+
=
ZZ
ZZY
)1)(5.01(
5.05.1)(
11
1
=
ZZ
ZZYzi (where no input signal)
11 15.01 +
=
Z
B
Z
A
2
1=A
2=B
11 1
2
5.01
2
1
)(
+
=
ZZZY
zi
)()1(2)5.0(2
1)( nuny nnzi
+=
)()
2
1(2 1 nun
= +
14. Compute the zero state response for the following pair of system and input signal.
(10-Marks)
)7()()(),()5
2()( == nununxnunh n
)7()()(),()5
2()( == nununxnunh n
)()()( ZZHZYzs =
{ })()( nhZZH =
=
)()5
2
( nuZ n
=1
5
21
1
Z
{ })7()()( = nunuZZX
=1
7
1 11
1
Z
Z
Z
=1
7
1
1
Z
Z
)()()( ZZHZYzs =
8/11/2019 IT_Y5_new_NW
42/203
=1
7
1 1
1
521
1
Z
Z
Z
= [ ]6543211
1
521
1
++++++
ZZZZZZZ
let1
5211)(
=
ZZYzs
61 )(...)()()( ++= ZZYZZYZYZYzs zszszs
)()5
2()( nunY n
zs =
)6(...)1()()( +++= nynynyny zszszszs
)6()5
2(...)1()
5
2()()
5
2( 61 +++= nununu nnn
15 . Determine the response of the system described by the difference equation .
( ) ( ) ( ) ( )nxnynyny += 26
11
6
5
to the input signal
( ) ( ) ( )13
1= nnnx .
Take the initial condition: ( ) 11 =y and ( ) 02 =y . (20-marks)
Solution:
( ) 11 =y , ( ) 02 =y
( ) ( ) ( ) ( )nxnynyny += 261
16
5
( ) ( ) ( ) ( )ZXZZYZZYZY += 216
1
6
5
( ) ( )ZXZZZY =
+= 21
6
1
6
51
( ) ( )21
6
1
6
51
1
)( +==
ZZzX
ZYZH
( ) ( ) ( )13
1= nnnx
( ) ( ) ( )
= 1
3
1nnZZX
1
3
11 = Z
( ) ( ) ( )ZXZHZYZS =
+=
1
21 3
11
6
1
6
51
1Z
ZZ
8/11/2019 IT_Y5_new_NW
43/203
21
1
6
1
6
51
3
11
+
=
ZZ
Z
=
11
1
2
11
3
11
3
11
ZZ
Z
1
2
11
1
=
Z
( ) ( )nunyn
ZS
=
2
1
( ) ( ) nN
K
K
n
K
K ZnyZaZN = =
=1 1
0
( )==
=K
n
n
K
K
K ZnyZa1
2
1
( ) ( ) ( ){ }22211 211 ZyZyZaZyZa ++= 1
21
= Zaa
( ) 106
1
6
5 = ZZN
==
6
1,
6
521 aaQ
( ) 216
1
6
51 += ZZZA
( ) ( )
( )ZAZN
ZYzi
0=
21
1
61
651
61
65
+
=
ZZ
Z
( )( )111
211
311
61
65
=
ZZ
Z
11
211
311
+
=Z
B
Z
A
31
1
1
211
61
65
=
=
Z
Z
ZA
( )
( )32
11
36
16
5
=
32=
21
1
1
311
61
65
=
=
ZZ
ZB
( )
( )23
11
2
6
1
6
5
=
8/11/2019 IT_Y5_new_NW
44/203
2
3=
( )11
311
32
211
23
=
ZZZYzi
( ) ( ) ( )nununy
nn
zi
= 3
1
3
2
2
1
2
3
( ) ( ) ( )nynyny ziZS +=
)()3
1(3
2)()
21(
2
3)()
2
1( nununu nnn +=
)()3
1(3
2)()
21(
2
5nunu nn =
)()3
1(3
2)
21(
2
5nunn
=
16. Determine the unit step response of the causal system described by the differenceEquation.
)()1()( zxnyny +=
)()()( 1 zXZzYnY +=
)()1)(( 1 zXZzY =
11
1
)(
)()(
==
ZzX
zYzH
x(n)=u(n) X(z)=11
1z
)()()( zzHzY =
=11 1
1
1
1
ZZ
=21 )1(
1Z
Double pole at Z=1
The inverse Z transform of Y(z) is
y(n)=(n+1)u(n)
8/11/2019 IT_Y5_new_NW
45/203
17. By using schur Cohn stability test, determine if the system having the system function.
H(z)=21
2
1
471
1
ZZ (10 marks)
is stable.
H(z)=21
2
1
471
1
ZZ
A2(Z)= 121,
21;
21
471 22
21
8/11/2019 IT_Y5_new_NW
46/203
Solution:
(a) ( ) ( ) ( ) ( ) ( )12
14
12
11
=
nununxnn
( ) ( ) ( )nuZZU n2
11 =
1211
1
=Z
ROC: 1>Z
( ) ( ) ( )12
11
2 =
nuZZUn
( )ZUZ 21=
1
1
211
=
Z
Z ROC:
21>Z
( ) ( ){ }nxZZX =
( ) ( ) ( ) ( )12
14
12
11
=
nuZnuZnn
1
1
1
2114
12
11
1
= Z
Z
Z
( )1
1
211
411
=
Z
ZZX
( ) ( ) ( )nuny n3
1=
( )1
311
1
=Z
ZY ; ROC:3
1>Z
( ) ( ) ( )ZXZHZY =
( ) ( )( )ZXZYZH =
1
1
1
411
211
311
1
=
Z
Z
Z
( )( )( )11
1
411
311
211
=
ZZ
ZZH
( ) ( )114
113
11 +
=
Z
B
Z
A
31
1
1
411
211=
=Z
Z
ZA
( )
( )34
11
32
11
=
2=
41
1
1
311
211
=
=
ZZ
ZB
( )
( )43
11
42
11
=
8/11/2019 IT_Y5_new_NW
47/203
3=
( )11
311
2
411
3
=ZZ
ZH
( ) ( ) ( ) ( )nunh nn
=
312
413
(b) ( )( )( )11
1
411
311
211
=
ZZ
ZZH
21
1
121
1271
211
+
=
ZZ
Z
( ) ( ) ( ) ( ) ( )12
122
1112
7 += nxnxnynyny
(c)
(d) The system is stable
19. Determine the interconnection of the systems shown in fig:where h(n)=anu(n) , -1< a
8/11/2019 IT_Y5_new_NW
48/203
=
=
1
)1(n
k
k kna
= an-1
u(n-1) , n 1h2(n) = h(n) * (n-2)
=
=
k
knkh )2()(
=
=
2
)2(n
k
k kna
= an-2
u(n-2) , n 2
The impulse response of the overall system;
h(n) = h1(n) + h2(n)
= an-1
+ an-2
, n 2-1 < a < 1
-1 < 1na < 1 and -1 < 2na < 1
=k
h(n) <
The system is stable .The system is causal since h(n) = 0 for n < 0 .
(b) h(n) = an-1
u(n-1) + an-2
u(n-2)
H1(z) = z {an-1u(n-1)}
=1
1
1
az
z ; ROC z > a
H2(z) = z { an-2
u(n-2) }
=1
2
1
az
z; ROC z > a
H(z) =1
21
1
+
az
zz
y(n) ay(n-1) = x(n-1) + x(n-2)y(n) = ay(n-1) + x(n-1) + x(n-2)
20. Consider the system
8/11/2019 IT_Y5_new_NW
49/203
H(z) =21
2
211
25
2
5
31
+
+
zz
zz
Determine
(a)The impulse response
(b)The zero-state step response (20 marks)
(a) h(n) = ?
H(z) =21
2
211
25
2
5
31
+
+
zz
zz
252
53
21
2 +
+=
zz
z
)5
1)(5
2(
21
+=zz
z
)5
1()5
2( +
=
z
B
z
A
A5
2
51
21
=
+=
zz
z
2
9
5152
21
52
=
+=
B5
1
)5
2(
)2
1(
=
+=
zz
z
=2
7
52
51
21
51
=
+
H(z) =
512
7
522
9
zz
=1
1
1
1
521
*27
521
*29
zz
zz
h(n) = 9 (2/5)n-1u(n-1) 7/2 (1/5)n-1u(n-1)
(c)yzs(n) = ?
x(n) = u(n)
X(z) =11
1z
where Yzs(z) = H(z) X(z)
121
21
1
1*
7252531
21
+
+=
zz
zz
8/11/2019 IT_Y5_new_NW
50/203
=1
*
252
53
21
2 +
+
z
z
zz
z
)1)(
5
1)(
5
2(
21
)(
+=
zzz
z
z
zYzs
=)1()
51()
52(
+
+ z
C
z
B
z
A
A =5
2)1)(
51(
21
=
+
zzz
z
=)1
52)(
51
52(
21
52
+
= 2
15
B =
51)1)(
52(
21
=
+
zzz
z
=
1
)5
1)(5
2(
21
51
=
+
z
zz
=)
51)(
521(
2
11
+
z
=8
25
=z
zYzs )(
1
825
518
35
522
15
+
+
zzz
11
825
518
35
525
15
)(1
+
+
=
zzz
z
z
zzYzs
)(8
25)()
51(
8
35)()
5
2(
2
15)( nunununy nnzs ++
=
= )(8
25)5
1(8
35)
52(
2
15nunn
++
21. Consider the system
21
21
252531
21
)(
+
+=
zz
zzzH
Determine the step response if y(-1) =1 and y(-2)=2. (20-Marks)
8/11/2019 IT_Y5_new_NW
51/203
solution:
21
21
252
531
21
)(
+
+=
zz
zzzH
2)2(,1)1( == yy
Assume x(n)=0
)(
)()( 0
zA
zNzY
zi =
A(z)=1-21
25
2
5
3 + ZZ
25
2,
5
3,2 21 === aaN
==
=k
n
nN
k
k
k ZnyZaZN11
0 )()(
==
=
k
n
n
k
k
k ZnyZa1
2
1)(
22
2
1
1 )2()1(()1( ZyZyZaZyZa ++=
22
2
2
2
1
1 2ZZaZZaZZa ++=
2
1
21 2aZaa ++=
25
4
25
2
5
3 1 = Z
1
25
2
25
11 = Z
YZi(Z) =)(
)(0
ZA
ZN
21
1
252
531
252
2511
+
=
ZZ
Z
252
53
252
2511
2
2
+
=
ZZ
ZZ
252
53
)25
2
25
11(
2 +
=
ZZ
ZZ
)5
1)(5
2(
252
2511
)(
=
ZZ
Z
Z
ZYzi
)5
1()5
2( +
=
Z
B
Z
A
A =5
2
51
252
2511
=
ZZ
Z
8/11/2019 IT_Y5_new_NW
52/203
=25
12
51)
52(
252)
52(
2511
=
B =5
1
5
225
225
11
=
ZZ
Z
=25
1
52)
51(
252)
51(
2511
=
51
251
5225
12)(
=
ZZZ
ZYzi
51
251
52
2512
)(
=
Z
Z
Z
Z
Z
ZYzi
= 115
1125
1
521
25
12
ZZ
)()5
1(
25
1)()
5
2(
25
12)( nununy nn
zi =
Chapter (4)
Frequency Analysis of Signals
1. Determine the fourier series and the power density spectrum of the rectangular pulse
signal illustrated in fig.
Solution:
width= Tp = fundamental period
Ck =
pT
tkF
p
dtetxT
02)(1
=
2
2
02)(1 p
p
T
T
kFt
p
dtetxT
= 2
2
2 01
e
tkF
p
dtAeT
= 2
2
2 0
dte
TA tkF
p
-Tp Tp0-/2 t/2
x(t)
8/11/2019 IT_Y5_new_NW
53/203
For k=0, Ck= 2
2
1
dt
T
A
p
= [ ] 22
t
T
A
p
=
+ 22
pT
A
=pp T
A
T
A =
2
2
For k # 0,
= 2
2
2 0
dte
T
AC
tkFj
p
k
=2
20
2
2
0
kFj
e
T
A tkFj
p
=
22
22
0
00
2
kFjkFj
p
eekFjT
A
= [ ]
00
02
kFjkFj
p
eekFjT
A
=
j
ee
kFT
A kFjkFj
p 2
00
0
=
)
2
(
00
0 j
ee
kFT
A kFjkFj
p
=
0kFT
A
p 0sin kF
=
pT
A
0
0sin
kF
kF
=
=
p
p
k
T
A
kT
A
C
0,
0
0sin
kF
kF
0#, k
The power density spectrum for the rectangular pulse train is
=
=
0,2
)(
2)(
2
k
pT
A
pT
ACk
0#,2)
0
0sin
( kkF
kF
8/11/2019 IT_Y5_new_NW
54/203
2. Determine the fourier transform and the energy density spectrum of a rectangular pulse
signal defined as.
x(t)=
>
2
20
tA
t
(20-marks)
x(t)
solution
A
t
- 2
2
X(F)= dtetx Ftj
2)(
= dtAe Ftj2
2
2
for F#0, X(F) = A22
2
Fj
e Ftj
=A
Fj
eeFjFj
2
22
22
=
2
(
j
ee
F
A FjFj
=F
A
sin
F
FAF
sin=
For F=0,X(F)= 2
2
2
dtAe Ftj
=A 2
21
dt
8/11/2019 IT_Y5_new_NW
55/203
=At ]22
=A
AA
==
+
2
2
22
X(F)=
= 0,0#,
FA
FA
To Find zero-crossing pts,
x(F)=0
A 0sin
=
F
F
sin sin=F F ,....2,1 =
F = ,....2
,1
F = ,....)2,1( = mm
( )2
)(FXFSxx = is called the energy density spectrum of x(t).
=2
)(FX
2)(
0#,2)sin
(2)(
A
kF
FA
3. Determine the spectrum of the signal
nnx 0cos)( =
3)(2)( 00
== bawhen (20 marks)
Solution:
8/11/2019 IT_Y5_new_NW
56/203
=
=
1
0
2)(
1 N
n
Nnk
k enxN
C
(a) f 20 =
f2 = 2
2
2
=f
f is not a rational number, the signal is not perodic. This signal cannot
be expressed in Fourier Series. The spectrum consist of the signal frequency
component at .20 =
(b) f20 =
=
=
==
=
=
5
0
62
)(6
1
/61
/6
1
23
n
nkj
k enxC
cyclesamplesf
N
samplescyclef
f
[ ]
=
=
=
=
+=
=
=
=
5
0
62
362
3
5
0
62
33
5
0
62
5
0
62
0
2
1
6
1
)2
(6
1
)3
cos(6
1
cos6
1
n
nkjnjnkjnj
n
nkj
njnj
n
nkj
n
nkj
eeee
eee
en
ne
[ =
=
+=
5
0
)1(6
25
0
)1(6
2
12
1
n
knj
n
knj
k eeC
Consider the first summation,
==
=
,...2,,01
0
5
0
)1(2NNkN
otherwisen
kN
nje
L
L
=
=
==
1.......
016
0
5
0
6)1(
2 k
k
otherwisen
knj
e
L
L
Consider the second summation,
8/11/2019 IT_Y5_new_NW
57/203
=
=
==
5.......
616
0
5
0
6)1(
2 k
k
otherwisen
knj
e
L
L
== 5,1,..........
2
1
..............0
k
otherwisekC
2
1
2
1
2
1,
2
1
115
1371
51
==
===
=
==
+
CC
CCC
CC
CC
Nkk
4. Determine the Furier Series coefficients and the power density spectrum of the signal
show in fig.
(20 marks)
Solution:
for k=0,
=
=
=
=
=
=
=
=
=
1
0
2
1
0
1
0
1
0
2
)(
11
)(1
L
n
nNkj
k
L
n
L
nk
N
n
Nnkj
k
eN
AC
N
ALA
N
AA
NC
enxN
C
8/11/2019 IT_Y5_new_NW
58/203
Nkj
NLk
eN
A
Nkj
NLkj
eN
A
eee
eee
N
A
e
e
N
A
NL
kj
NL
kj
Nkj
Nkj
Nkj
NLkj
NLkj
NLkj
Nkj
NLkj
sin2
sin
sin2
sin2
)11(
)(
1
1
)1(2
)1(2
222
222
2
2
=
=
=
=
=
=
NNkN
LA
OtherwiseN
kN
LkN
Lkj
eN
Ak
C2,,0..............
..........sin
sin)1(
==
NNkN
LA
Otherwise
Nk
NLk
N
Ak
C2,,0..............
..........sin
sin
The power density spectrum of this periodic signal
=
==0.....,..........2.)(
0,2
)sin
sin(
2)(
2 kN
LA
k
Nk
NLk
N
Ak
Cx
P
5. Determine the signal x(n) corresponding to the spectrum.
= cww
OtherwisewX
.........................1
........................0)(
(20 marks)Solution:
= 2 )(21
)( wXnx wjwn
de
8/11/2019 IT_Y5_new_NW
59/203
=
c
c
w
w
1 wjwn de
for n=0 , x(n) = 2
1
c
c
w
w1
w
d
=2
1[ ] c
c
w
ww
=2
1[ ]
ccw
wcc
wwww c
c==+
2
2
for n 0, x(n) = dwec
c
w
w
jwn
21
c
c
w
w
jwn
jn
e
=
2
1
=
j
ee njwnjw cc
22
1
nwn
nx csin1
)(
=
nw
nww
c
ccsin
=
=
=
0,
0,sin
)(nc
w
nn
cw
nc
wc
wnx
6. Determine the Fourier transform and the energy density spectrum of the sequence.
= 10,
,0)(
LnAOtherwise
nx
which is illustrated in fig.
8/11/2019 IT_Y5_new_NW
60/203
Solution:
=
=n
njenxX )()(
=
=1
0
L
n
njAe
For = 0 , ALAXL
n
==
=
1
0
1)(
for 0 ,
=
=1
0
)(L
n
njAeX
=
=1
0
)(L
n
njeA
j
Lj
e
eAX
=
1
1*)(
2sin
2sin
.
2sin2
2
sin2
.
)(
)(.
2)1(
2
)1(
222
222
L
eA
j
Lj
eA
eee
eeeA
Lj
Lj
jjj
LjLjLj
=
=
=
=
= 0,
0#,
2
sin
2sin
2)1(
)(
AL
lLjAe
X
== 0,
0#,
2sin
2sin
)(
ALl
A
X
The energy density spectrum is simply the square of the expression.
8/11/2019 IT_Y5_new_NW
61/203
== 0,
0#,2)
2sin
2sin
(2
2)(
ALl
A
X
7. Determine the Fourier transform of the sigal x(n)= an
-1
8/11/2019 IT_Y5_new_NW
62/203
=2
2
221
1
aaeae
aaeaejj
jj
+
+
+
=2
2
cos21
1
aa
a
+
8. Consider the full-wave rectified sinusoid in Fig .
(a)Determine its spectrum ( )FXa .(b)Compute the power of the signal.
(c)Plot the power spectral density
(d) Check the volidity of parsevals relation for this signal. (20- marks)
Solution:
2=p
T ,2
110
==
pT
F
( ) FtAtxa 2sin=
At t= ( ) 02sin0, == FAtx 2 =F
F=2
1
(a) ( ) tAtx
=
2
12sin
=A sin t
For k#0, =
pT
tkFj
p
k etxT
C 02
)(1
=
0
2 0sin1
dtteA tkF
=
0
2 0sin dtteA tkFj
=
0
12
2dte
j
eeA tkjtjtj
=
( )
+
0
)21(21
2 dteej
A tkjtkj
8/11/2019 IT_Y5_new_NW
63/203
=
( )
( )
( )
( )
+
+
0
21
0
21
21212
kj
e
kj
e
j
Atkjtkj
( )
( )
( )
( )
+
=
+
kj
e
kj
e
j
Akjkj
21212
121121
( )
( )
( )
( )
+
=+
kj
e
kj
e
j
A kjkj
21212
121121
+
+
=
kkjj
A
21
11
21
11
2
++=
24221
4242
2 kkk
kkA
=
241
4
2 k
A
( )2412
k
A
=
For k=0 , ( )dttXT
C
pTp
k =1
dttA =
0
sin1
+= 0coscos
A
A2=
(b) ( ) dttXT
P
PTP
x
21=
dttA
2
sin
1
=
( )
=
==
=0,
41
2
0,2
2
2
2
2
kk
A
kA
CPk
kx
8/11/2019 IT_Y5_new_NW
64/203
(c)
(d) ( )
=
==PT
k
k
P
x CdttX
TP
221
9.Compute the Fourier transform of the following signals.
(a) )6()()(1 = nununx
(b) )6(2)(2 = nunx n
(c) [ ])6()()3
cos()(3 = nununx n (20-Marks)
solution:
(a) )6()()(1 = nununx
==
==5
0
61)(nn
nx
for =0,
= =
===1
0
5
0
61,0)0(l
n n
AX
for
# 0,
8/11/2019 IT_Y5_new_NW
65/203
=
=1
0
)(l
n
jwnAewX
=jw
jwl
e
eA
1
1
=
2sin
)2sin()1)(2(
w
wllwjAe
== 0,
0#,
2sin
2sin
)( wAl
ww
wl
Al
wX
=
= 0,6
0#,
2sin
sinw
ww
w
(b). )6(2)(2 = nunx n
=
=
n
jewnenxZX )()( 22
jwn
n
ne
=
=
6
2
For w#0,
=
=
0
5
0
2 )2()2()(n n
njwnjw eewX
=jw
jw
jw e
e
e
21
)2(1
21
16
=jw
wj
e
e
21
64 6
for w=0,
===
==5
006
2 222)0(n
n
n
n
n
nX
=21
21
21
16
= 64211 6 =+
=
= 0,64
0#,
21
664
)( w
wjw
e
wje
wX
8/11/2019 IT_Y5_new_NW
66/203
(c).
[ ])6()()3
cos()(3 = nununx n
)6()()(1 = nununx
)()
3
cos()( 13 nXnnx =
by modulation property,
)3
(2
1)
3(
2
1)(
++= wXwXwX
8/11/2019 IT_Y5_new_NW
67/203
Programming Languages and Compiling
Techniques
IT 5015
for
Second Semester
Sample Question
8/11/2019 IT_Y5_new_NW
68/203
1. (a) Define the following terms. (10 Marks)
(a) class, instance variables, constructors, methods.
(b) parent class or super class
(c) abstract
(d) interface
(e) polymorphic
(b) Using expression Abstract Syntax of Jay and meaning of an expression,
write the variable class. (6 Marks)
2.(a) Using expression Abstract Syntax of Jay and meaning of an expression,
write the value class, intvalue subclass and Undefvalue subclass of the value
class. (10 Marks)(b) Using expression Abstract Syntax of Jay and meaning of an expression,
write the Binary class. ( 6 Marks)
3.(a) Evaluate the following lambda expression. ( 6 Marks)
(a) (( x. x * x ) 2 )
(b) ( ( y . ( ( x . xyz ) a ) ) b )
(c) ( ( x . x * x ) 5 )
(d ) ( ( y . ( ( x . x + y + z ) 3 ) ) 2 )
(e) ( ( v . ( . ) ( ( x . x) y ( z . z ) ) )
(f)(( x . ( ( y . ( ( z. xyz ) a ) )b ))c)
4. Evaluate the following expression wing your. Scheme interpreter.(10 Marks)
(a) ( null? ( ) )
(b) ( null? ( a b c d e ) )
(c) ( car ( a ( b c ) d e ) )
(d) ( cdr ( a ( b c ) d e ) )
(e) ( cardr ( a ( b c ) d e ) )
(f)(equal? 5 5)
8/11/2019 IT_Y5_new_NW
69/203
(g)(equal? '(1 2) '(2 1))
(h)(append '(1 2) '(3 4))
(i)(list '(1 2) '(3 4) 5)
(j)(cons 10 evens)
5. Evaluate the scheme expression ( sum 1 2 3 4 5 ) showing all the steps in
the expression of the sum function. (6 Marks)
6. Write a scheme function for get and onion with the following application.
(a)an application of get function =(get 'z '((x 5) (y 3) (z 1)))
(b) an application of onion function =(onion 'z 1 '((x 5) (y 3) (z 1))) ( 10 Marks)
7. Use extended symbolic differentiation program to differentiate the following.
2.X+1 (6 Marks)8. Write a Scheme function named elements which counts the number of
elements in a list: for example: ( elements ( 1 ( 2 ( 3 ) 4) 5 6 ) ) is 6, while
the length of the same list is 4. ( 6 Marks)
9. Draw the table of Properties of Predicode Logic Expressions. ( 6 Marks)
10. Transform the following predicate to conjunctive normal form.( 10 Marks)
))))(),(()(()(( ybookyxreadsyxwritesxliteratex
11. Draw a small family tree for the following. ( 6 Marks)
parent ( A, B ) : father ( A, B )
parent ( A, B ) : mother ( A, B )
grandparent ( C, D ) : parent ( C, E ) . parent ( E .D )
mother ( mary, sue ).
mother ( mary, bill ).
mother ( sue, mary ).
mother ( sue, jeff).
mother ( jane, ron ).
father ( john, sue ).
father ( john, bill ).
8/11/2019 IT_Y5_new_NW
70/203
father ( bob, nanoy ).
father ( bob, jeff ).
father ( bill, ron ).
12. Draw search tree for the Query d ( x, 2 * x + 1, Ans ). (6 Marks)
13. Consider the family tree. Draw a search tree, in the style for the query
grandparent ( Who, ron ). ( 3 Marks)
14.Define a new relation cousin that defines the relationship between any
two people whose parents are siblings. Write a query for this expanded program
that will identify all people who are cousins of Ron. (3 Marks)
15. By forming the passing table verify that the grammar with the following
productions is YACC grammar. (16 Marks)
accept : expr
expr : expr + expr
expr * expr
( expr )
NUM
16.(a) Explain why bottom-up passing is more generally applicable than top-
down passing. (4 Marks)
(b) Explain what is meant by shift- reduce and reduce- reduce conflicts in
bottom-up passing. (4 Marks)
(c) By forming the passing table verify that the grammar with the following
productions is LR (1). ( 8 Marks)
1. S axF
2. F ,JF
3.
4. J ax
5. x
8/11/2019 IT_Y5_new_NW
71/203
1. E E + T
2. E T
3. T T * F
4. T F
5. F ( E )
6. F x
In which E is the sentence symbol. The grammar may be used a basis for
bottom-up passing as is shown by passing the following sentence.( 16 Marks)
x + x + x * x.
17. Explain about symbol tables with example. (10 Marks)18. Explain about Type tables with example. (10 Marks)
19. What are the main characteristics of object oriented programming
languages? (6 Marks)
20. Write down the roles of Ada. (6 Marks)
21. What are the properties of the address of the value x? (8 Marks)
22. Explain about three types of storage. (8 Marks)
23. Draw the run time stack for the following program. (8 Marks)
Program demo (output);
var x,y:real;
procedure first;
var c, d: integer;
procedure second;
var p, q: integer;
begin
.
.
end;
procedure third;
8/11/2019 IT_Y5_new_NW
72/203
var m, n: integer;
begin
.
.
end;
begin
second;
Third
Begin
firstend
25. Explain two phase when garbage collection. ( 4 Marks)
26. In many language implementations, characters occupy as much storage
space as integers. Give argument for and against this situation. ( 2 Marks)
27. What are good reasons for compliers to produce intermediate code?
Describe three well- known examples. ( 10 Marks)
28. Produce three-address code, P-code and Byte code for the following
statements.
(a) if ( expression ) statements else statements (16 Marks)
(b) while ( expression ) statement.
29. Produce three-address code for each of the following expressions.( 3 Marks)
(a) a +b + c
(b) ( a + b ) * ( c + d ) * ( e + f )
(c) x * y * Z + -p * q
30. Considers the piece of C code: ( 3 Marks)
n = 0 ;
sum 2 = 0;
while ( n < 10 )
8/11/2019 IT_Y5_new_NW
73/203
{ n = n + 1;
M = 2 * n ;
Sum2= sum2 + m ;
}
******************************
8/11/2019 IT_Y5_new_NW
74/203
Programming Languages and Compiling Techniques
IT 5015
for
Second Semester
Sample Question
8/11/2019 IT_Y5_new_NW
75/203
1. (a) Define the following terms. (10 Marks)
(a) class, instance variables, constructors, methods.
(b) parent class or super class
(c) abstract
(d) interface
(e) polymorphic
Soln
Sol:
(a) In an object-oriented language the data type is bound together with the initialization and other
operations on that type. The type is referred to as a class, local variables are called instance variables,
their initializingas are accomplished by special methods called constructors, and other operations are
implemented by methods.
(b)A class can be declared as a subclass of another class, which is called the parent class or super class.
(c)Java allows a class to be declared abstract, in which case one or more of its methods are declared to be
abstract.
(d)An interface declares a collection of features identified by abstract methods.
(e)The term polymorphic means "having many forms."In object-oriented languages polymorphism refers
to the late binding of a call to a specific method in an object.
(b) Using expression Abstract Syntax of Jay and meaning of an expression, write the
variable class. (6 Marks)
sol:
class Variable Extends Expression{
String id;
public Variable(String id) {this.id=id;}public boolean equals(Object obj){
String s=((Variable)obj).id;
Return id.equalsIgnorCase(s);
}
public int hashcode(){ return id.hashcode;}
public Value M(State sigma) {
return (Value)(sigma.get(this));
8/11/2019 IT_Y5_new_NW
76/203
}
}
2.(a) Using expression Abstract Syntax of Jay and meaning of an expression, write the
value class, intvalue subclass and Undefvalue subclass of the value class.(10 Marks)
sol:
class Value Extends Expression{
public Value(int i) {return new IntValue(i);}
public Value(Boolean b) {return new BooleanValue(b);}
public Value() {return new UndefValue();}
public boolean isUndef(){return false;}
public int intVal(){ return -1;}
public boolean boolanVal(){ return false;}
public Value M(State sigma){return this;}
}
}
class IntValue extends Value{
int intVal;
public intValue(int i){intValue=i;}
public intVal(){return intVal;}
class undefValue extends Value{
public UndefValue extends Value{returns true;}
}
(b) Using expression Abstract Syntax of Jay and meaning of an expression, write the
Binary class. ( 6 Marks)
Sol:class Binary Extends Expression{
Operator op;
Expression term1,term2;
Public Binary(Operator o, Expression t1, Expression t2){
op=p; term1=t1; term2=t2;
}
public Value M(State sigma) {
8/11/2019 IT_Y5_new_NW
77/203
return op.apply(term1.M(sigma), term2.M(sigma));
}
}
3.(a) Evaluate the following lambda expression. ( 6 Marks)
(a) (( x. x * x ) 2 )
(b) ( ( y . ( ( x . xyz ) a ) ) b )
(c) ( ( x . x * x ) 5 )
(d ) ( ( y . ( ( x . x + y + z ) 3 ) ) 2 )
(e) ( ( v . ( . ) ( ( x . x) y ( z . z ) ) )
(f)(( x . ( ( y . ( ( z. xyz ) a ) )b ))c)
Soln
(a) (( x. x * x ) 2 )=2*2=4
(b) ( ( y . ( ( x . xyz ) a ) ) b )= ( ( y . ayz ) b )=abz
(c)
( ( x . x * x ) 5 )=5*5=10
(d) ( ( y . ( ( x . x + y + z ) 3 ) ) 2 )= ( ( y . 3+y+z ) 2 )=3+2+z=5+z
(e) ( ( v . ( . ) ( ( x . x) y ( z . z ) ) )= ( ( v . ( . ) ( y ( z . z ) ) )
(f) (( x . ( ( y . ( ( z. xyz ) a ) )b ))c)= (( x . ( ( y . xya)b ))c)= (( x .xba)c)=cba
4. Evaluate the following expression wing your. Scheme interpreter. ( 10 Marks)
(a) ( null? ( ) )
(b) ( null? ( a b c d e ) )
(c) ( car ( a ( b c ) d e ) )
(d) ( cdr ( a ( b c ) d e ) )(e) ( cardr ( a ( b c ) d e ) )
(f)(equal? 5 5)
(g)(equal? '(1 2) '(2 1))
(h)(append '(1 2) '(3 4))
(i)(list '(1 2) '(3 4) 5)
(j)(cons 10 evens)
Sol;
8/11/2019 IT_Y5_new_NW
78/203
(a)
#t
(b)#f
(c)
a
(d)(( b c ) d e )
(e)
( b c )
(f)
#t
(g)
#f
(h)
(1 2 3 4 )
(i)
((1 2) (3 4) 5)
(j)
(10 0 2 4 6 8)
5. Evaluate the scheme expression ( sum 1 2 3 4 5 ) showing all the steps in the
expression of the sum function. ( 6 Marks)
sol:
( sum 1 2 3 4 5 )
=(+ 1( sum 2 3 4 5 ))
=(+ 1(+ 2( sum 3 4 5 )))
=(+ 1(+ 2( +3(sum 4 5 ))))
=(+ 1(+ 2( +3(+ 4(sum 5 )))))
=(+ 1(+ 2( +3(+ 4(+5(sum ))))))
=(+ 1(+ 2( +3(+ 4(+5 0)))))
=(+ 1(+ 2( +3(+ 4 5))))
=(+ 1(+ 2( +3 9)))
=(+ 1(+ 2 12))
=(+ 1 14)
=15
6. Write a scheme function for get and onion with the following application.
(a)an application of get function =(get 'z '((x 5) (y 3) (z 1)))
(b) an application of onion function =(onion 'z 1 '((x 5) (y 3) (z 1))) ( 10 Marks)Sol:
A scheme function for get function
(define (get id sigma)
(if (equal? id (caar sigma))) (cadar sigma)
(get id (cdr sigma))
))
(a)an application of get function =(get 'z '((x 5) (y 3) (z 1)))
8/11/2019 IT_Y5_new_NW
79/203
=(get 'z '((y 3) (z 1)))
=(get 'z '(z 1))
=1
A scheme function for onion function
(define (onion id val sigma)
(if (equal ? id (caar sigma))
(cons (list id val)(cdr sigma))
(cons (car sigma)(onion id val(cdr sigma)))
))
(b) an application of onion function =(onion 'z 2 '((x 5) (y 3) (z 1)))
=(cons '(x 5) (onion 'z 2 '( (y 3) (z 1))))
=(cons '(x 5) (cons '(y 3)(onion 'z 2 '(z 1))))
=(cons '(x 5) (cons '(y 3)(cons '(z 2) '())))
='((x 5) (y 3) (z 2))
7. Use extended symbolic differentiation program to differentiate the following. (6 Marks)
2.x+1
Sol:
(diff 'x "(+(* 2 x) 1))
=(list '+ (diff 'x '(* 2 x)) (diff 'x 1))
=(list '+(list '+ ( list '* 2 (diff 'x 'x)) ( list '* x (diff 'x 2))) (diff 'x 1))
=(list '+(list '+ ( list '* 2 1) ( list '* x (diff 'x 2))) (diff 'x 1))
=(list '+(list '+ '(* 2 1) ( list '* x (diff 'x 2))) (diff 'x 1))
=(list '+(list '+ '(* 2