Digital Circuits and Signal Simulation Lab Manual - (R23) - 1
Digital Circuits and Signal Simulation Lab Manual - (R23) - 1
II B.TECH I SEMESTER
(R23)
LAB OBSERVATION
(23A04303T)
Name:
H.T. No.:
LIST OF EXPERIMENTS
1. Write a program to generate various Signals and Sequences: Periodic and Aperiodic, Unit Impulse, Unit Step,
Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc function.
2. Perform operations on Signals and Sequences: Addition, Multiplication, Scaling, Shifting, Folding,
Computation of Energy and Average Power.
3. Write a program to find the trigonometric & exponential Fourier series coefficients of a rectangular periodic
signal. Reconstruct the signal by combining the Fourier series coefficients with appropriate weightages- Plot
the discrete spectrum of the signal.
4. Write a program to find Fourier transform of a given signal. Plot its amplitude and phase spectrum.
5. Write a program to convolve two discrete time sequences. Plot all the sequences.
6. Write a program to find auto correlation and cross correlation of given sequences.
7. Write a program to verify Linearity and Time Invariance properties of a given Continuous System.
8. Write a program to generate discrete time sequence by sampling a continuous time signal. Show that with
sampling rates less than Nyquist rate, aliasing occurs while reconstructing the signal.
9. Write a program to find magnitude and phase response of first order low pass and high
10. Write a program to find response of a low pass filter and high pass filter, when a speech signal is passed
through these filters.
11. Write a program to generate Complex Gaussian noise and find its mean, variance, Probability Density
Function (PDF) and Power Spectral Density (PSD).
12. Generate a Random data (with bipolar) for a given data rate (say 10kbps). Plot the same for a time period of
0.2 sec.
13. To plot pole-zero diagram in S-plane/Z-plane of given signal/sequence and verify its stability.
Note: All the experiments are to be simulated using MATLAB or equivalent software.
I. COURSE OBJECTIVES:
• Verify the truth tables of various logic circuits.
• Design sequential/combinational circuit using Hardware Description Language and verify their functionality.
• Simulate various Signals and Systems through MATLAB
• Analyze the output of a system when it is excited by different types of deterministic and random signals.
CO-PO/PSO Mapping
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 3 - - - - - - - - - - - 3 -
CO2 3 - - - - - - - - - - - 3 -
CO3 - 3 3 - - - - - - - - 3 -
CO4 - 3 3 - - - - - - - - - 3 -
CO5 - - - - 3 - - - - - - - 3 -
CO 3 3 3 3 3 - - - - - - - 3 -
LABORATORY INSTRUCTIONS
1. While entering the Laboratory, the students should follow the dress code.
2. The students should bring their observation book, record, calculator, necessary stationery items
and graph sheets if any for the lab classes without which the students will not be allowed for doing
the experiment.
3. All the Equipment and components should be handled with utmost care. Any breakage or damage
will be charged.
4. If any damage or breakage is noticed, it should be reported to the concerned in charge immediately.
5. The theoretical calculations and the updated register values should be noted down in the
observation book and should be corrected by the lab in-charge on the same day of the laboratory
session.
6. Each experiment should be written in the record note book only after getting signature from the lab
in-charge in the observation notebook.
7. Record book must be submitted in the successive lab session after completion of experiment.
Precautions.
Procedure:
Simulation tool:
1.Double click the project navigator and select the option File-new project.
2.Give the project name.
3.Select the Verilog module
4.Type Verilog code.
5.Check for syntax.
6.Select the new source, choose Verilog fixture for test bench
7.Choose behavioral simulation and simulate it by Xilinx ISE simulator.
8.Verify the output.
Synthesis tool:
1.Double click the project navigator and select the option File-new project.
2.Give the project name.
3.Select the Verilog module
4.Type Verilog code.
5.Check for syntax.
6.Select - view RTL schematic, Technology schematic and device utilization summary from the synthesis-xst menu.
7. Verify the logic circuit and equivalent parameters.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 1
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
EXP. No.1 Four variables combinational circuit and obtain minimal SOP
DATE: expression
AIM: To design a four variable combinational circuit, obtain minimal SOP expression and verify the truth table using
Digital Trainer Kit.
Hardware required:PC
Theory:
A combinational circuit is a type of digital logic circuit where the output depends solely on the current inputs,
without any memory or feedback from previous states. The circuit's behavior is determined by a logical function of the
inputs, which can be expressed in different forms such as Sum of Products (SOP) or Product of Sums (POS).
In a four-variable combinational circuit, there are four input variables, typically denoted as A, B, C, and D. These
inputs can take binary values (0 or 1), leading to 24=162^4 = 1624=16 possible input combinations. The output of the
circuit is a logical function F(A,B,C,D), which can be represented in a truth table or by a Boolean expression.
The Sum of Products (SOP) is a canonical form of Boolean expression where the function is expressed as a sum
(OR) of product terms (ANDs). Each product term in the SOP form corresponds to a minterm, which is a combination
of input variables that produces a true output (1) for the function.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 2
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
The above Boolean expression has seven product terms. They are mapped top to bottom and left to right on the K-map
above. For example, the first P-term A’B’CD is the first row, 3rd cell, corresponding to map location A=0, B=0, C=1,
D=1.
The other product terms are placed in a similar manner. Encircling the largest groups possible, two groups of four are
shown above.
The dashed horizontal group corresponds to the simplified product term AB. The vertical group corresponds to
Boolean CD. Since there are two groups, there will be two product terms in the Sum-Of-Products result
of Out=AB+CD.
Verilog Code:
module sop(a,b,c,d,y);
input a,b,c,d;
output out;
assign out = (a&b)|(c&d);
endmodule
Testbench Code:
module sop_tb;
//
Inputs
reg a;
reg b;
reg c;
reg d;
//
Outputs
wire out;
initial begin
// Initialize Inputs
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 3
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
a = 0; b = 0; c = 0; d = 0; #5;
a = 0; b = 0; c = 0; d = 1; #5;
a = 0; b = 0; c = 1; d = 0; #5;
a = 0; b = 0; c = 1; d = 1; #5;
a = 0; b = 1; c = 0; d = 0; #5;
a = 0; b = 1; c = 0; d = 1; #5;
a = 0; b = 1; c = 1; d = 0; #5;
a = 0; b = 1; c = 1; d = 1; #5;
a = 1; b = 0; c = 0; d = 0; #5;
a = 1; b = 0; c = 0; d = 1; #5;
a = 1; b = 0; c = 1; d = 0; #5;
a = 1; b = 0; c = 1; d = 1; #5;
a = 1; b = 1; c = 0; d = 0; #5;
a = 1; b = 1; c = 0; d = 1; #5;
a = 1; b = 1; c = 1; d = 0; #5;
a = 1; b = 1; c = 1; d = 1; #5;
$finish;
end
endmodule
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 4
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Aim: To verify functional table of 3 to 8-line Decoder/De-multiplexer and verify the output using Hardware Description
Language.
Hardware required:PC
Theory:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 5
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 6
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module decoder3to8(in,out, en);
input [2:0] in;
input en;
output [7:0] out;
reg [7:0] out;
always @( in or en)
begin
if (en)
begin
out=8'd0;
case (in)
3'b000: out[0]=1'b1;
3'b001: out[1]=1'b1;
3'b010: out[2]=1'b1;
3'b011: out[3]=1'b1;
3'b100: out[4]=1'b1;
3'b101: out[5]=1'b1;
3'b110: out[6]=1'b1;
3'b111: out[7]=1'b1;
default: out=8'd0;
endcase
end
else
out=8'd0;
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 7
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
1:8 Demultiplexer:
Code:
module demux_1to8(I,SEL,Y) ;
input I;
input [2:0]SEL;
output [7:0]Y;
reg [7:0]Y;
always @ (I,SEL)
begin
case(SEL)
3'b000: Y=4'b00000001;
3'b001: Y=4'b00000010;
3'b010: Y=4'b00000100;
3'b011: Y=4'b00001000;
3'b011: Y=4'b00010000;
3'b011: Y=4'b00100000;
3'b011: Y=4'b01001000;
3'b011: Y=4'b10001000;
endcase
end
endmodule
module demux_1to8_tb;
// Inputs
reg I;
reg [2:0] SEL;
// Outputs
wire [7:0] Y;
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 8
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
SEL = 3'b100; #5;
SEL = 3'b101; #5;
SEL = 3'b110; #5;
SEL = 3'b111; #5;
$finish;
end
endmodule
module dec_tb;
// Inputs
reg [2:0] in;
// Outputs
wire [7:0] out;
// Instantiate the Unit Under Test (UUT)
dec uut
(
.in(in),
.out(out) );
initial begin
// Initialize Inputs
in = 3'b000; #5;
in = 3'b001; #5;
in = 3'b010; #5;
in = 3'b011; #5;
in = 3'b100; #5;
in = 3'b101; #5;
in = 3'b110; #5;
in = 3'b111; #5;
$finish;
end
endmodule
RTL Schematic:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 9
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 10
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
AIM: To design a four variable logic function using 8 to 1 multiplexer and verify the output using Hardware
Description Language.
Hardware required:PC
Theory:
Implement the following function using 8:1 multiplexer workaround: F (A,B, C,D) = ∑m (0,1,3,5,7,10,,11,13,14,15)
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 11
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module mux8to1(
input A, B, C, D,
output F
);
wire [7:0] mux_in;
// Select line
assign F = mux_in[{B,C,D}];
endmodule
Testbench Code:
module mux8to1_tb;
// Inputs
reg A;
reg B;
reg C;
reg D;
// Outputs
wire F;
initial begin
// Initialize Inputs
A = 0;B = 0; C = 0; D = 0; #50;
A = 0;B = 0; C = 0; D = 1; #50;
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 12
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
A = 0;B = 0; C = 1; D = 0; #50;
A = 0;B = 0; C = 1; D = 1; #50;
A = 0;B = 1; C = 0; D = 0; #50;
A = 0;B = 1; C = 0; D = 1; #50;
A = 0;B = 1; C = 1; D = 0; #50;
A = 0;B = 1; C = 1; D = 1; #50;
A = 1;B = 0; C = 0; D = 0; #50;
A = 1;B = 0; C = 0; D = 1; #50;
A = 1;B = 0; C = 1; D = 0; #50;
A = 1;B = 0; C = 1; D = 1; #50;
A = 1;B = 1; C = 0; D = 0; #50;
A = 1;B = 1; C = 0; D = 1; #50;
A = 1;B = 1; C = 1; D = 0; #50;
A = 1;B = 1; C = 1; D = 1; #50;
$finish;
end
endmodule
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 13
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
EXP. No.4 Design full adder circuit and verify its functional table
DATE:
AIM: To design full adder circuit and verify its functional table using Hardware Description Language.
Hardware required:PC
Theory:
Full-Adder: The half-adder does not take the carry bit from its previous stage into account. This carry bit from its previous
stage is called carry-in bit. A combinational logic circuit that adds two data bits, A and B, and a carry-in bit, Cin, is called
a full-adder.
The Boolean functions describing the full-adder are:
Sum, S = (x y) Cin
Carry, C = xy + Cin (x y)
Boolean Expression:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 14
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Logic Circuit:
Verilog Code:
module full_adder(a,b,c,sum,carry);
input a,b,c;
output sum,carry;
assign sum = a^b^c;
assign carry=(a&b)|(b&c)|(c&a);
endmodule
Testbench Code:
module full_adder_tb;
//
Inputs
reg a;
reg b;
reg c;
//
Outputs
wire
sum;
wire
carry;
initial begin
// Initialize Inputs
a = 0; b = 0; c = 0; #5;
a = 0; b = 0; c = 1; #5;
a = 0; b = 1; c = 0; #5;
a = 0; b = 1; c = 1; #5;
a = 1; b = 0; c = 0; #5;
a = 1; b = 0; c = 1; #5;
a = 1; b = 1; c = 0; #5;
a = 1; b = 1; c = 1; #5;
$finish;
end
endmodule
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 16
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
AIM: To design a four-bit ring counter using D/JK Flip-flops and verify the output using Hardware Description
Language.
Hardware required:PC
Theory:
A ring counter is a type of shift register counter where the output of the last flip-flop is fed back to the input of the first flip-flop,
forming a ring-like structure. In a four-bit ring counter, there are 4 flip-flops, and only one of them is set to '1' at any given time
while the others are set to '0'. This '1' circulates around the ring, creating a sequence of outputs.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 17
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
assign q = q_reg;
endmodule
assign q = q_reg;
endmodule
Testbench Code:
module ring_tb_v;
// Inputs
reg clk;
reg reset;
// Outputs
wire [3:0] q;
initial
// Initialize Inputs
clk = 0;
always #10 clk = ~clk;
initial begin
reset = 1; #50;
reset = 0; #50;
$finish;
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 19
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 20
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
AIM: To design a four-bit Johnson’s counter using D/JK flip-flops and verify the output using Hardware Description
Language.
Hardware required:PC
Theory:
A Johnson counter, also known as a twisted ring counter, is a type of shift register where the complement of the last flip-flop’s
output is fed back to the input of the first flip-flop. A four-bit Johnson counter cycles through 8 unique states (twice the number
of flip-flops), making it a MOD-8 counter. This counter can be implemented using either D flip-flops or JK flip-flops.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 21
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
endmodule
module johnson_counter_4bit_jk(
input clk, // Clock input
input reset, // Reset input
output reg [3:0] q // 4-bit counter output
);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 22
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
always @(posedge clk or posedge reset) begin
if (reset) begin
q_int <= 4'b0000;
end else begin
q_int[3] <= ~q_int[0];
q_int[2] <= q_int[3];
q_int[1] <= q_int[2];
q_int[0] <= q_int[1];
end
end
assign q = q_int;
endmodule
Testbench Code:
module johnson_tb;
// Inputs
reg clk;
reg reset;
// Outputs
wire [3:0] q;
initial
// Initialize Inputs
clk = 0;
always #10 clk = ~clk;
initial begin
reset = 1; #50;
reset = 0; #50;
$finish;
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 23
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 24
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
EXP. No. 7 4-bit Universal Shift Register for different Modes of operation
DATE:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 25
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module universal_shift_reg(
input clk, rst_n,
input [1:0] select, // select operation
input [3:0] p_din, // parallel data in
input s_left_din, // serial left data in
input s_right_din, // serial right data in
output reg [3:0] p_dout, //parallel data out
output s_left_dout, // serial left data out
output s_right_dout // serial right data out
);
always@(posedge clk) begin
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 26
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
if(!rst_n) p_dout <= 0;
else begin
case(select)
2'h1: p_dout <= {s_right_din,p_dout[3:1]}; // Right Shift
2'h2: p_dout <= {p_dout[2:0],s_left_din}; // Left Shift
2'h3: p_dout <= p_din; // Parallel in - Parallel out
default: p_dout <= p_dout; // Do nothing
endcase
end
end
assign s_left_dout = p_dout[0];
assign s_right_dout = p_dout[3];
endmodule
Testbench Code:
module TB;
reg clk, rst_n;
reg [1:0] select;
reg [3:0] p_din;
reg s_left_din, s_right_din;
wire [3:0] p_dout; //parallel data out
wire s_left_dout, s_right_dout;
universal_shift_reg usr(clk, rst_n, select, p_din, s_left_din, s_right_din, p_dout, s_left_dout, s_right_dout);
p_din = 4'b1101;
s_left_din = 1'b1;
s_right_din = 1'b0;
$finish;
end
// To enable waveform
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 27
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 28
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
EXP. No. 8 Construct MOD-8 ripple counter circuit using T-Flip-Flops and Test It with a low
DATE: frequency clock
AIM: To construct MOD-8 ripple counter circuit using T-flip-flops and test it with a low frequency clock using Hardware
Description Language.
Hardware required:PC
Theory:
A MOD-8 ripple counter is a type of asynchronous counter that counts from 0 to 7 (which is 8 states, hence MOD-8)
and then resets to 0. It is called a "ripple" counter because the output of one flip-flop triggers the next flip-flop in the
sequence, causing a "ripple" effect as the clock signal propagates through the flip-flops.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 29
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module mod8_ripple_counter_t(
input wire clk, // Clock input
input wire reset, // Reset input
output reg [2:0] q // 3-bit counter output
);
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 30
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Testbench Code:
module tb_mod8_ripple_counter_t;
reg clk;
reg reset;
wire [2:0] q;
// Test sequence
initial begin
// Initialize signals
clk = 0;
reset = 1;
// Apply reset
#30 reset = 0;
// Monitor signals
initial begin
$monitor("At time %t, q = %b", $time, q);
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 31
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 32
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
AIM: To construct MOD-8 synchronous counter using T flip-flop and verify the result using Hardware Description
Language.
Hardware required:PC
Theory:
A MOD-8 synchronous counter is a type of digital counter that counts from 0 to 7 (which is 8 states, hence MOD-8).
After reaching the count of 7, it resets to 0 and continues counting in a cyclic manner. The counter uses T flip-flops as
the basic building blocks.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 33
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module mod8_counter_t(
input wire clk, // Clock input
input wire reset, // Reset input
output reg [2:0] q // 3-bit counter output
);
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 34
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Testbench Code:
module tb_mod8_counter_t;
reg clk;
reg reset;
wire [2:0] q;
// Test sequence
initial begin
// Initialize signals
clk = 0;
reset = 1;
// Apply reset
#10 reset = 0;
// Monitor signals
initial begin
$monitor("At time %t, q = %b", $time, q);
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 35
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 36
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
AIM: To design single bit comparator and test the output using Hardware Description Language.
Hardware required:PC
Theory:
A single-bit comparator is a digital logic circuit used to compare two binary inputs, each of 1 bit. The comparator
evaluates whether the two inputs are equal, or if one is greater than or less than the other.
• Inputs:
o A: A single-bit binary input (either 0 or 1).
o B: Another single-bit binary input (either 0 or 1).
• Outputs:
o A > B: A binary output that is 1 if A is greater than B, and 0 otherwise.
o A = B: A binary output that is 1 if A is equal to B, and 0 otherwise.
o A < B: A binary output that is 1 if A is less than B, and 0 otherwise.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 37
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 38
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module single_bit_comparator(
input a, // Input bit a
input b, // Input bit b
output a_eq_b, // Output: a equals b
output a_gt_b, // Output: a greater than b
output a_lt_b // Output: a less than b
);
endmodule
Testbench Code:
module tb_single_bit_comparator;
reg a;
reg b;
wire a_eq_b;
wire a_gt_b;
wire a_lt_b;
// Test sequence
initial begin
initial begin
a = 0; b = 0; #5;
a = 0; b = 1; #5;
a = 1; b = 0; #5;
a = 1; b = 1; #5;
$finish;
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 39
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 40
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
EXP. No. 10(b) Construct 7 Segment Display Circuit Using Decoder and 7 Segment LED
DATE:
AIM: To construct seven segment display circuit using decoder and seven segment LED and verify the output using
Hardware Description Language.
Hardware required:PC
Theory:
A seven-segment display is an electronic component used to display decimal numbers (0-9) and some alphabets (like
A, b, C, d, E, F) using LEDs arranged in a specific pattern. The display consists of seven LEDs (labeled a through g)
arranged in a figure-eight pattern, and sometimes an eighth LED is used for a decimal point.
Decoder/Driver Circuit:
A decoder/driver circuit is used to convert binary input signals into the corresponding signals required to light up the
appropriate segments on the seven-segment display. The most common decoders used are:
Working Principle:
1. Binary Input: The seven-segment display circuit typically accepts a 4-bit binary input representing the
numbers 0 to 9. This input can be provided by a set of switches or a binary counter.
2. Decoder Functionality:
o The decoder/driver takes the 4-bit binary input and decodes it into seven output signals that correspond to the
segments a to g of the seven-segment display.
o The output signals are then used to drive the segments of the display. For example, to display the number "3,"
the decoder would activate segments a, b, c, d, and g.
3. Current Limiting Resistors: Resistors are placed in series with each LED segment to limit the current
flowing through them, protecting the LEDs from damage due to excessive current.
4. Display Output:
o For a common anode display, the decoder outputs low (0) signals to turn on the corresponding segments by
connecting them to ground.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 41
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
o For a common cathode display, the decoder outputs high (1) signals to turn on the corresponding segments by
connecting them to the supply voltage.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 42
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 43
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Verilog Code:
module seven_segment_decoder(
input wire [3:0] binary_in, // 4-bit binary input
output reg [6:0] seg // 7-segment display output (a to g)
);
endmodule
Testbench Code:
module tb_seven_segment_decoder;
// Test sequence
initial begin
// Monitor signals
$monitor("At time %t: binary_in = %d, seg = %b", $time, binary_in, seg);
// Test case 0
binary_in = 4'd0;
#10;
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 44
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
// Test case 1
binary_in = 4'd1;
#10;
// Test case 2
binary_in = 4'd2;
#10;
// Test case 3
binary_in = 4'd3;
#10;
// Test case 4
binary_in = 4'd4;
#10;
// Test case 5
binary_in = 4'd5;
#10;
// Test case 6
binary_in = 4'd6;
#10;
// Test case 7
binary_in = 4'd7;
#10;
// Test case 8
binary_in = 4'd8;
#10;
// Test case 9
binary_in = 4'd9;
#10;
// End simulation
$finish;
end
endmodule
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 45
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RTL Schematic:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 46
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
MATLAB INTRODUCTION:
MATLAB, which stands for Matrix Laboratory, is a state-of-the-art mathematical
software package, which is used extensively in both academia and industry. It is an interactive
program for numerical computation and data visualization, which along with its programming
capabilities provides a very useful tool for almost all areas of science and engineering. Unlike
other mathematical packages, such as MAPLE or MATHEMATICA, MATLAB cannot perform
symbolic manipulations without the use of additional Toolboxes. It remains however, one of the
leading software packages for numerical computation.
As you might guess from its name, MATLAB deals mainly with matrices. A scalar is a 1-
by-1 matrix and a row vector of length say 5, is a 1-by-5 matrix.. One of the many advantages of
MATLAB is the natural notation used. It looks a lot like the notation that you encounter in a
linear algebra. This makes the use of the program especially easy and it is what makes MATLAB
a natural choice for numerical computations. The purpose of this experiment is to familiarize
MATLAB, by introducing the basic features and commands of the program.
Operators:
1. + addition
2. -subtraction
3. * multiplication
4. ^ power
5. ' transpose
6. \ left division
7. / right division
Remember that the multiplication, power and division operators can be used in conjunction with
a period to specify an element-wise operation.
Built in Functions:
1. Scalar Functions:
Certain MATLAB functions are essentially used on scalars, but operate element-wise when
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 47
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
1. sin -trigonometric sine
7. exp -exponential
13. floor -round towards negative infinity 14. ceil -round towards positive infinity
2. Vector Functions:
Other MATLAB functions operate essentially on vectors returning a scalar value. Some of
1. max largest component : get the row in which the maximum element lies
3. Matrix Functions:
Much of MATLAB’s power comes from its matrix functions. These can be further separated into
two sub-categories. The first one consists of convenient matrix building functions, some of
which are given below.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 48
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
eg: diag([0.9092;0.5163;0.2661])
ans =
0.9092 0 0
0 0.5163 0
0 0 0.2661
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 49
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Aim: Generate various signals and sequences (Periodic and aperiodic), such as Unit Impulse,
Unit Step, Square, Saw tooth, Triangular, Sinusoidal, Ramp, Sinc.
Software Required: Matlab software
Theory: If the amplitude of the signal is defined at every instant of time, then it is called
continuous time signal. If the amplitude of the signal is defined at only at some instants of time,
then it is called discrete time signal. If the signal repeats itself at regular intervals, then it is called
periodic signal. Otherwise they are called aperiodic signals.
EX: ramp, Impulse, unit step, sinc- Aperiodic signals square, sawtooth, triangular sinusoidal –
periodic signals.
» plot(x,y)
It is good practice to label the axis on a graph and if applicable indicate what each axis
represents. This can be done with the xlabel and ylabel commands.
» xlabel('x')
» ylabel('y=cos(x)')
Inside parentheses, and enclosed within single quotes, we type the text that we wish to be
displayed along the x and y axis, respectively. We could even put a title on top using
» plot (x,y,’g’)
Where the third argument indicating the color, appears within single quotes. We could get a
dashed line instead of a solid one by typing
» plot (x,y,’--’)
or even a combination of line type and color, say a blue dotted line by typing
» plot (x,y,’b:’)
We can get both graphs on the same axis, distinguished by their line type, using
» plot(x,y,'r--',x,z,'b:')
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 50
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
When multiple curves appear on the same axis, it is a good idea to create a legend to label and
distinguish them. The command legend does exactly this.
» legend ('cos(x)','sin(x)')
The text that appears within single quotes as input to this command, represents the legend
labels. We must be consistent with the ordering of the two curves, so since in the plot command
we asked for cosine to be plotted before sine, we must do the same here.
At any point during a MATLAB session, you can obtain a hard copy of the current plot
by either issuing the command print at the MATLAB prompt, or by using the command menus
on the plot window. In addition, MATLAB plots can by copied and pasted (as pictures) in your
favorite word processor (such as Microsoft Word). This can be achieved using the Edit menu on
the figure window. Another nice feature that can be used in conjunction with plot is the
command grid, which places grid lines to the current axis (just like you have on graphing paper).
Type help grid for more information. Other commands for data visualization that exist in
MATLAB include subplot create an array of (tiled) plots in the same window log log plot using
log-log scales semi logx plot using log scale on the x-axis semi logy plot using log scale on the
y-axis
The Sinc Function
The sinc function computes the mathematical sinc function for an input vector or matrix x.
Viewed as a function of time, or space, the sinc function is the inverse Fourier transform of the
rectangular pulse in frequency centered at zero of width 2p and height
The sinc function has a value of 1 when x is equal to zero, and a value of for all other elements
of x.
% Generation of signals and sequences
clc;
clear all;
close all;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of unit impulse signal
t1=-1:0.01:1
y1=(t1==0);
subplot(2,2,1);
plot(t1,y1);
xlabel('time');
ylabel('amplitude');
title('unit impulse signal');
%generation of impulse sequence
subplot(2,2,2);
stem(t1,y1);
xlabel('n');
ylabel('amplitude');
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 51
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
title('unit impulse sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of unit step signal
t2=-10:1:10;
y2=(t2>=0);
subplot(2,2,3);
plot(t2,y2);
xlabel('time');
ylabel('amplitude');
title('unit step signal');
%generation of unit step sequence
subplot(2,2,4);
stem(t2,y2);
xlabel('n');
ylabel('amplitude');
title('unit step sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of square wave signal
t=0:0.002:0.1;
y3=square(2*pi*50*t);
figure;
subplot(2,2,1);
plot(t,y3);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('square wave signal');
%generation of square wave sequence
subplot(2,2,2);
stem(t,y3);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('square wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of sawtooth signal
y4=sawtooth(2*pi*50*t);
subplot(2,2,3);
plot(t,y4);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title('sawtooth wave signal');
%generation of sawtooth sequence
subplot(2,2,4);
stem(t,y4);
axis([0 0.1 -2 2]);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 52
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
xlabel('n');
ylabel('amplitude');
title('sawtooth wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of triangular wave signal
y5=sawtooth(2*pi*50*t,.5);
figure;
subplot(2,2,1);
plot(t,y5);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title(' triangular wave signal');
%generation of triangular wave sequence
subplot(2,2,2);
stem(t,y5);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('triangular wave sequence');
%generation of sinsoidal wave signal
y6=sin(2*pi*40*t);
subplot(2,2,3);
plot(t,y6);
axis([0 0.1 -2 2]);
xlabel('time');
ylabel('amplitude');
title(' sinsoidal wave signal');
%generation of sin wave sequence
subplot(2,2,4);
stem(t,y6);
axis([0 0.1 -2 2]);
xlabel('n');
ylabel('amplitude');
title('sin wave sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of ramp signal
y7=t;
figure;
subplot(2,2,1);
plot(t,y7);
xlabel('time');
ylabel('amplitude');
title('ramp signal');
%generation of ramp sequence
subplot(2,2,2);
stem(t,y7);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 53
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
xlabel('n');
ylabel('amplitude');
title('ramp sequence');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%generation of sinc signal
t3=linspace(-5,5);
y8=sinc(t3);
subplot(2,2,3);
plot(t3,y8);
xlabel('time');
ylabel('amplitude');
title(' sinc signal');
%generation of sinc sequence
subplot(2,2,4);
stem(y8);
xlabel('n');
ylabel('amplitude');
title('sinc sequence');
OUTPUT WAVEFORM:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 54
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 55
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 56
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
1. Operations on Signals and Sequences
Aim: To performs functions on signals and sequences such as addition, multiplication, scaling,
shifting, folding, computation of energy and average power.
Theory:
Signal Addition
Addition: any two signals can be added to form a third signal,
z (t) = x (t) + y (t)
Multiplication:
Multiplication of two signals can be obtained by multiplying their values at every instant. z
z(t) = x (t) y (t)
Time reversal/Folding:
Time reversal of a signal x(t) can be obtained by folding the signal about t=0.
Y(t)=y(-t)
Signal Amplification/Scaling : Y(n)=ax(n) if a < 1 attenuation
a >1 amplification
Time shifting: The time shifting of x(n) obtained by delay or advance the signal in time by
using y(n)=x(n+k)
If k is a positive number, y(n) shifted to the right i e the shifting delays the signal
If k is a negative number, y(n ) it gets shifted left. Signal Shifting advances the signal
Program :
clc;
clear all;
close all;
% generating two input signals
t=0:.01:1;
x1=sin(2*pi*4*t);
x2=sin(2*pi*8*t);
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('input signal 1');
subplot(2,2,2);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 57
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
plot(t,x2);
xlabel('time');
ylabel('amplitude');
title('input signal 2');
% addition of signals
y1=x1+x2;
subplot(2,2,3);
plot(t,y1);
xlabel('time');
ylabel('amplitude');
title('addition of two signals');
% multiplication of signals
y2=x1.*x2;
subplot(2,2,4);
plot(t,y2);
xlabel('time');
ylabel('amplitude');
title('multiplication of two signals');
% scaling of a signal1
A=2;
y3=A*x1;
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('time');
ylabel('amplitude');
title('input signal')
subplot(2,2,2);
plot(t,y3);
xlabel('time');
ylabel('amplitude');
title('amplified input signal');
% folding of a signal1
h=length(x1);
nx=0:h-1;
subplot(2,2,3);
plot(nx,x1);
xlabel('nx');
ylabel('amplitude');
title('input signal')
y4=fliplr(x1);
nf=-fliplr(nx);
subplot(2,2,4);
plot(nf,y4);
xlabel('nf');
ylabel('amplitude');
title('folded signal');
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 58
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
%shifting of a signal 1
figure;
subplot(3,1,1);
plot(t,x1);
xlabel('time t');
ylabel('amplitude');
title('input signal');
subplot(3,1,2);
plot(t+2,x1);
xlabel('t+2');
ylabel('amplitude');
title('right shifted signal');
subplot(3,1,3);
plot(t-2,x1);
xlabel('t-2');
ylabel('amplitude');
title('left shifted signal');
%operations on sequences
n1=1:1:9;
s1=[1 2 3 0 5 8 0 2 4];
figure;
subplot(2,2,1);
stem(n1,s1);
xlabel('n1');
ylabel('amplitude');
title('input sequence1');
s2=[1 1 2 4 6 0 5 3 6];
subplot(2,2,2);
stem(n1,s2);
xlabel('n2');
ylabel('amplitude');
title('input sequence2');
% addition of sequences
s3=s1+s2;
subplot(2,2,3);
stem(n1,s3);
xlabel('n1');
ylabel('amplitude');
title('sum of two sequences');
% multiplication of sequences
s4=s1.*s2;
subplot(2,2,4);
stem(n1,s4);
xlabel('n1');
ylabel('amplitude');
title('product of two sequences');
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 59
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
% program for energy of a sequence
z1=input('enter the input sequence');
e1=sum(abs(z1).^2);
disp('energy of given sequence is');e1
% program for energy of a signal
t=0:pi:10*pi;
z2=cos(2*pi*50*t).^2;
e2=sum(abs(z2).^2);
disp('energy of given signal is');e2
% program for power of a sequence
p1= (sum(abs(z1).^2))/length(z1);
disp('power of given sequence is');p1
% program for power of a signal
p2=(sum(abs(z2).^2))/length(z2);
disp('power of given signal is');
Output:
enter the input sequence[1 3 2 4 1]
energy of given sequence is
e1 = 31
energy of given signal is
e2 = 4.0388
power of given sequence is
p1 = 6.2000
power of given signal is
p2 = 0.3672
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 60
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 61
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 62
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
3.To find the trigonometric & exponential Fourier series coefficients of a
rectangular periodic signal, reconstruct the signal and [lot the discrete
spectrum of the signal.
Aim: To find the trigonometric & exponential Fourier series coefficients of a rectangular
periodic signal. Reconstruct the signal by combining the Fourier series coefficients with
appropriate weightages- Plot the discrete spectrum of the signal.
Theory: to compute the trigonometric fourier series coefficients of a periodic square wave time
signal that has a value of 2 from time 0 to 3 and a value of -12 from time 3 to 6. It then repeats
itself. I am trying to calculate in MATLAB the fourier series coefficients of this time signal and
am having trouble on where to begin.
subplot(2,1,1)
plot([-3 -2 -2 -1 -1 0 0 1 1 2 2 3],... % plot original y(t)
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 63
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
yt = c0*ones(size(t)); % initialize yt to c0
subplot(2,1,2)
plot([-3 -2 -2 -1 -1 0 0 1 1 2 2 3],... % plot original y(t)
[-1 -1 1 1 -1 -1 1 1 -1 -1 1 1], ':');
hold; % plot truncated trigonometric FS
plot(t,yt);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['EE341.01: Truncated Trigonometric Fourier Series with N = ',...
num2str(N)];
title(ttle);
hold;
subplot(2,1,1)
stem(0,c0); % plot c0 at nwo = 0
hold;
for n = -N:2:N, % loop over series index n
cn = 2/(j*n*wo); % Fourier Series Coefficient
stem(n*wo,abs(cn)) % plot |cn| vs nwo
end
for n = -N+1:2:N-1, % loop over even series index n
cn = 0; % Fourier Series Coefficient
stem(n*wo,abs(cn)); % plot |cn| vs nwo
end
xlabel('w (rad/s)')
ylabel('|cn|')
ttle = ['EE341.01: Amplitude Spectrum with N = ',num2str(N)];
title(ttle);
grid;
hold;
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 64
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
subplot(2,1,2)
stem(0,angle(c0)*180/pi); % plot angle of c0 at nwo = 0
hold;
for n = -N:2:N, % loop over odd series index n
cn = 2/(j*n*wo); % Fourier Series Coefficient
stem(n*wo,angle(cn)*180/pi); % plot |cn| vs nwo
end
for n = -N+1:2:N-1, % loop over even series index n
cn = 0; % Fourier Series Coefficient
stem(n*wo,angle(cn)*180/pi); % plot |cn| vs nwo
end
xlabel('w (rad/s)')
ylabel('angle(cn) (degrees)')
ttle = ['EE341.01: Phase Spectrum with N = ',num2str(N)];
title(ttle);
grid;
hold;
OUTPUT WAVEFORM:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 65
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 66
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
4. To find Fourier transform of a given signal and plot its amplitude
and phase spectrum.
Aim: To find the Fourier Transform of a given signal and plotting its magnitude and phase
spectrum.
Software Required: Matlab software
Theory:
Fourier Transform:
The Fourier transform as follows. Suppose that ƒ is a function which is zero outside of some
interval [−L/2, L/2]. Then for any T ≥ L we may expand ƒ in a Fourier series on the interval
[−T/2,T/2], where the "amount" of the wave e2πinx/T in the Fourier series of ƒ is given by By
definition Fourier Transform of signal f(t) is defined as
Program:
clc;
clear all;
close all;
fs=1000;
N=1024; % length of fft sequence
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]);
grid;
xlabel('t');
ylabel('amplitude');
title('input signal');
% Fourier transform of given signal
x1=fft(x);
% magnitude spectrum
k=0:N-1;
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag);
grid;
xlabel('t');
ylabel('amplitude');
title('magnitude of fft signal')
%phase spectrum
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 67
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Xphase=angle(x1);
subplot(3,1,3);
plot(k,Xphase);
grid;
xlabel('t');
ylabel('angle');
title('phase of fft signal');
OUTPUT WAVEFORM:
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 68
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
5. To convolve two discrete time sequences and plot all the sequences
Aim: Write the program for convolution between two signals and also between two
sequences.
Software Required: Matlab software
Theory:
Convolution involves the following operations.
• Folding
• Multiplication
• Addition
• Shifting
Convolution is an integral concatenation of two signals. It is used for the determination of the
output signal of a linear time-invariant system by convolving the input signal with the impulse
response of the system. Note that convolving two signals is equivalent to multiplying the Fourier
transform of the two signals.
Program:
clc;
close all;
clear all;
%program for convolution of two sequences
x=input('enter input sequence: ');
h=input('enter impulse response: ');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence')
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 69
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse response sequence')
subplot(3,1,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title('linear convolution')
disp('linear convolution y=');
disp(y)
%program for signal convolution
t=0:0.1:10;
x1=sin(2*pi*t);
h1=cos(2*pi*t);
y1=conv(x1,h1);
figure;
subplot(3,1,1);
plot(x1);
xlabel('t');
ylabel('x(t)');
title('input signal')
subplot(3,1,2);
plot(h1);
xlabel('t');
ylabel('h(t)');
title('impulse response')
subplot(3,1,3);
plot(y1);
xlabel('n');
ylabel('y(n)');
title('linear convolution');
.
Output:
enter input sequence: [1 3 4 5]
enter impulse response: [2 1 4]
linear convolution y=
2 7 15 26 21 20
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 70
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
RESULT:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 71
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
6. To find auto correlation and cross correlation of given sequences.
Aim: To compute Auto correlation and Cross correlation between signals and sequences.
Software Required: Mat lab software
Theory:
Correlations of sequences:
It is a measure of the degree to which two sequences are similar. Given two real-valued
sequences x(n) and y(n) of finite energy,
Convolution involves the following operations.
1. Shifting
2. Multiplication
3. Addition
Program:
clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence');
h=input('enter the impulse suquence');
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse sequence');
% cross correlation between two
y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title(' cross correlation between two sequences ');
% auto correlation of input sequence
z=xcorr(x,x);
subplot(2,2,4);
stem(z);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 72
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');
% cross correlation between two signals
% generating two input signals
t=0:0.2:10;
x1=3*exp(-2*t);
h1=exp(t);
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('t');
ylabel('x1(t)');
title('input signal');
subplot(2,2,2);
plot(t,h1);
xlabel('t');
ylabel('h1(t)');
title('impulse signal');
% cross correlation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t');
ylabel('z1(t)');
title('cross correlation ');
% auto correlation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t');
ylabel('z2(t)');
title('auto correlation ');
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 73
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 74
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
7. To verify Linearity and Time Invariance properties of a given
Continuous/Discrete System.
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 75
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
y2=x2.^2;
y3=x3.^2;
yt=a1*y1+a2*y2;
if y3==yt
disp('given system [y(n)=x(n).^2 ]is Linear');
else
disp('given system is [y(n)=x(n).^2 ]non Linear');
end
Output:
enter the scaling factor a1=3
enter the scaling factor a2=5
given system [y(n)=n.x(n)]is Linear
given system is [y(n)=x(n).^2 ]non Linear
Program (B) :
Output:
transformation of delay signal yd:
0 0 0 1 4 9 16 25 36 49 64 81
delay of transformation signal dy:
0 0 0 1 4 9 16 25 36 49 64 81
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 76
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 77
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
8. To generate discrete time sequence by sampling a continuous time signal.
Show that with sampling rates less than Nyquist rate, aliasing occurs while
reconstructing the signal.
The maximum frequency component of g(t) is fm. To recover the signal g(t) exactly from its
samples it has to be sampled at a rate fs ≥ 2fm.
The minimum required sampling rate fs = 2fm is called ' Nyquist rate
Program:
clc;
clear all;
close all;
t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('time');
ylabel('x(t)');
title('continous time signal');
grid;
n1=-4:1:4;
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs<2fm');
hold on;
subplot(2,2,2);
plot(n1,x1);
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 78
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
subplot(2,2,3);
stem(n2,x2);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs=2fm');
hold on;
subplot(2,2,3);
plot(n2,x2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3);
xlabel('time');
ylabel('x(n)');
title('discrete time signal with fs>2fm')
hold on;
subplot(2,2,4);
plot(n3,x3)
grid;
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 79
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
9. To find magnitude and phase response of first order low pass and high
pass filter. Plot the responses in logarithmic scale.
Aim: To find magnitude and phase response of first order low pass and high pass filter. Plot the
responses in logarithmic scale.
Theory: To get the phase response in the time domain you need to estimate the delay between
the input and the output at the test frequency and then convert to phase. For sure, taking the angle
of the RMS ratio will not yield that delay. If you really want to estimate the delay in the time
domain, there is a function called finddelay that may be of use.
However, the alternative approach is to work in the frequncy domain, i.e., use the ratio of the
frequency response of the output to the frequency resposne of the input to directly stimate the
magnitude and phase response of the system. The code that follows shows how to do that for a
simple low pass filter. Keep in mind, that any approach you use may begin to suffere as you test
frequency gets close to the Nyquist frequency. You can experiment with this code to see how
close you can get before this simple approach begins to break down.
Program :
f=1:15;
% second order filter with 10 Hz pass band
H = @(f,s) 1./(1./(2*pi*f).^2*s.^2 + 2./(2*pi*f)*s + 1);
H10 = @(s) H(10,s);
% magnitude estimation
magn = abs(H10(1j*2*pi*f));
% phase estimation
phase = rad2deg( angle(H10(1j*2*pi*f)) );
figure;
subplot(2,1,1);
semilogx(f,mag2db(magn));
title('Frequency response of the filter using abs(Out/Inp)')
xlabel('Frequency');
ylabel ('Change in output/input P-P' );
subplot(2,1,2);
semilogx(f,phase);
title('Phase response of the filter using angle(Out/Inp)')
xlabel('Frequency');
ylabel ('phase' );
% check against inbuilt functions
H_tf = @(f) tf(1,[1./(2*pi*f).^2 2./(2*pi*f) 1]);
figure;
bodeplot(H_tf(10),2*pi*f)
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 80
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 81
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
10. To find response of a low pass filter and high pass filter, when a speech
signal is passed through these filters.
Aim: To find response of a low pass filter and high pass filter, when a speech signal is passed
through these filters.
Theory:
y = lowpass(x,wpass) filters the input signal x using a lowpass filter with normalized passband
frequency wpass in units of π rad/sample. lowpass uses a minimum-order filter with a stopband
attenuation of 60 dB and compensates for the delay introduced by the filter. If x is a matrix, the function
filters each column independently.
y = lowpass(x,fpass,fs) specifies that x has been sampled at a rate of fs hertz. fpass is the
passband frequency of the filter in hertz.
y = lowpass(xt,fpass) lowpass-filters the data in timetable xt using a filter with a passband frequency
of fpass hertz. The function independently filters all variables in the timetable and all columns inside each
variable.
y = lowpass( ,Name,Value) specifies additional options for any of the previous syntaxes using name-
value pair arguments. You can change the stopband attenuation, the transition band steepness, and the
type of impulse response of the filter.
[y,d] = lowpass( ) also returns the digitalFilter object d used to filter the input.
lowpass( ) with no output arguments plots the input signal and overlays the filtered signal.
Program :
% Read standard sample tune that ships with MATLAB.
[dataIn, Fs] = audioread('guitartune.wav');
% Filter the signal
fc = 800; % Make higher to hear higher frequencies.
% Design a Butterworth filter.
[b, a] = butter(6,fc/(Fs/2));
freqz(b,a)
% Apply the Butterworth filter.
filteredSignal = filter(b, a, dataIn);
% Play the sound.
player = audioplayer(filteredSignal, Fs);
play(player);
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 82
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
11. To generate Complex Gaussian noise and find its mean, variance,
Probability Density Function (PDF) and Power Spectral Density (PSD).
Aim: Write the program for generation of Gaussian noise and computation of its mean, mean
square value, standard deviation, variance, and skewness.
Software Required: Matlab software
Theory:
Gaussian noise is statistical noise that has a probability density function (abbreviated pdf) of
the normal distribution (also known as Gaussian distribution). In other words, the valuestha the
noise can take on are Gaussian-distributed. It is most commonly used as additive white noise to
yield additive white Gaussian noise (AWGN).Gaussian noise is properly defined as the noise
with a Gaussian amplitude distribution. says nothing of the correlation of the noise in time or of
the spectral density of the noise. Labeling Gaussian noise as 'white' describes the correlation of
the noise. It is necessary to use the term "white Gaussian noise" to be correct. Gaussian noise is
sometimes misunderstood to be white Gaussian noise, but this is not the case.
Program:
clc;
clear all;
close all;
%generates a set of 2000 samples of Gaussian distributed random numbers
x=randn(1,2000);
%plot the joint distribution of both the sets using dot.
subplot(211)
plot(x,'.');
title('scatter plot of gaussian distributed random numbers');
ymu=mean(x)
ymsq=sum(x.^2)/length(x)
ysigma=std(x)
yvar=var(x)
yskew=skewness(x)
p=normpdf(x,ymu,ysigma);
subplot(212);
stem(x,p);
title(' gaussian distribution');
Output:
ymu = 0.0403
ymsq = 0.9727
ysigma = 0.9859
yvar = 0.9720
yskew = 0.0049
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 83
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 84
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
12. Generate a Random data (with bipolar) for a given data rate (say 10kbps).
Plot the same for a time period of 0.2 sec.
Aim: To Generate a Random data (with bipolar) for a given data rate (say 10kbps). Plot the same
for a time period of 0.2 sec.
Theory:
X = rand returns a single uniformly distributed random number in the interval (0,1).
X = rand(sz) returns an array of random numbers where size vector sz specifies size(X). For
example, rand([3 4]) returns a 3-by-4 matrix.
Program :
clc;
clear all;
a=-3
b=3
x=rand
c=a+(b-a)*x
y=c^2
z=y
for i=1:1000
x1=rand
c1=a+(b-a)*x1
y1=c1^2
if y1<z
z=y1
else
z;
end
end
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 85
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Aim: Write the program for locating poles and zeros and plotting pole-zero maps in s-plane
and z-plane for the given transfer function.
Software Required: Matlab software
Theory:
Z-transforms
The Z-transform, like many other integral transforms, can be defined as either a one-sided or
two-sided transform.
Program
clc;
clear all;
close all;
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 86
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 87
DIGITAL CIRCUITS AND SIGNAL SIMULATION LAB II B.TECH I SEMESTER
Result:
____________________________________________________________________________
Dept. of ECE CHADALAWADA RAMANAMMA ENGINEERING COLLEGE(A) Page | 88