You are on page 1of 37

LABORATORY MANUAL

ECE 303 and ECE353


Unified Electronics Lab-III

1
S. Name of the Experiments Sr no
No

MATLAB

1. To develop program for designing an FIR and 3


IIR filter

2. To develop a program for Computing discrete 10


Convolution and Correlation

3. To develop a program for Computing Circular 13


Convolution

4. To develop a program for Computing DFT and


IDFT in MATLAB

5. To develop a program for Computing Inverse Z-


Transform

BREAD BOARD

6. To design and implement on a breadboard a


circuit to perform Amplitude Modulation.

MTE

7. To design and implement on a breadboard a


circuit to perform Frequency Modulation.

8. Compile, Elaborate, and Simulate a 2-to-1 mux


Design using Incisive Simulator

MICROPROCESSOR

9. Interfacing and control of stepper motor using


8085 microprocessor.

10. Generation of delay in binary counting using


8085 microprocessor.

11. To implement a moving 7-segment display with


suitable delay using 8085 microprocessor.

12. Write a program to interface two digit numbers


2
using seven Segment LEDs, use 8086
microprocessor and 8255 PPI.
FIR filters

AIM: To verify FIR filters.

EQUIPMENTS:
Constructor – MATLAB Software

THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose
output is based on the weighted summation of a finite number of past inputs. An FIR transversal
filter structure can be obtained directly from the equation for discrete-time convolution.

In this equation, x(k) and y(n) represent the input to and output from the filter at time n.
h(n-k) is the transversal filter coefficients at time n. These coefficients are generated by using
FDS (Filter Design Software or Digital filter design package).
FIR – filter is a finite impulse response filter. Order of the filter should be specified.
Infinite response is truncated to get finite impulse response. placing a window of finite length
does this. Types of windows available are Rectangular, Barlett, Hamming, Hanning, Blackmann
window etc. This FIR filter is an all zero filter.

PROGRAM:

%fir filt design window techniques


clc;
clear all;
close all;

rp=input('enter passband ripple');


rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1)
3
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->')

RESULTS:

4
5
6
IIR filters

AIM: To design and implement IIR (LPF/HPF)filters.

EQUIPMENTS:
Software - MATLAB

THEORY:
The IIR filter can realize both the poles and zeroes of a system because it has a rational
transfer function, described by polynomials in z in both the numerator and the denominator:

The difference equation for such a system is described by the following:

M and N are order of the two polynomials.


bk and ak are the filter coefficients. These filter coefficients are generated using FDS (Filter
Design software or Digital Filter design package).
IIR filters can be expanded as infinite impulse response filters. In designing IIR
filters, cutoff frequencies of the filters should be mentioned. The order of the filter
can be estimated using butter worth polynomial. That’s why the filters are named as
butter worth filters. Filter coefficients can be found and the response can be plotted.

PROGRAM:

% IIR filters LPF & HPF


clc;clear all;close all;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
c=input('enter choice of filter 1. LPF 2. HPF \n ');
if(c==1)
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
disp('Frequency response of IIR HPF is:');
7
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');

RESULTS:

8
9
LINEAR CONVOLUTION AND CORRELATION

AIM: To verify Linear Convolution.

EQUIPMENTS:
Software -- MATLAB 7.5

THEORY:
Convolution is a formal mathematical operation, just as multiplication, addition, and
integration. Addition takes two numbers and produces a third number, while convolution takes
two signals and produces a third signal. Convolution is used in the mathematics of many fields,
such as probability and statistics. In linear systems, convolution is used to describe the
relationship between three signals of interest: the input signal, the impulse response, and the
output signal.

In this equation, x1(k), x2(n-k) and y(n) represent the input to and output from the system
at time n. Here we could see that one of the input is shifted in time by a value every time it is
multiplied with the other input signal. Linear Convolution is quite often used as a method of
implementing filters of various types.

ALGORITHM:

1. Enter the input Sequence ,x having length=4


2. Enter the Impulse Sequence, h having length=4
3. Performing the Convolution, store the value in y
4. Plotting the Input Sequence.
5. Plotting the Impulse Sequence.
6. Plotting the Output Sequence.

PROGRAM:

%linear convolution program


clc;
clear all;
close all;
disp('linear convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
10
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;

RESULT:

11
%program for discrete Correlation
x=[1 2 3 4];
y=[2 3 4 5];
z=xcorr(x,y);
stem(z);
subplot(2,2,1),stem(x)
title(‘input sequence 1’)
subplot(2,2,2),stem(y)
title(‘input sequence 2’)
subplot(2,2,3),stem(z)
title(‘output sequence’)

ALGORITHM:

1 Enter the input Sequence ,x having length=4


2 Enter the Impulse Sequence, y having length=4
3 Performing the Correlation, store the value in y
4 Plotting the Output Sequence ,store in z.

RESULT:
input sequence 1 input sequence 2
4 6

3
4
2
2
1

0 0
1 2 3 4 1 2 3 4

output sequence
40

30

20

10

0
0 2 4 6 8

12
CIRCULAR CONVOLUTION

AIM: To verify Circular Convolution.

EQUIPMENTS:
Software - MATLAB 7.5

THEORY:
Circular convolution is another way of finding the convolution sum of two input signals.
It resembles the linear convolution, except that the sample values of one of the input signals is
folded and right shifted before the convolution sum is found. Also note that circular convolution
could also be found by taking the DFT of the two input signals and finding the product of the
two frequency domain signals. The Inverse DFT of the product would give the output of the
signal in the time domain which is the circular convolution output. The two input signals could
have been of varying sample lengths. But we take the DFT of higher point, which ever signals
levels to. For eg. If one of the signal is of length 256 and the other spans 51 samples, then we
could only take 256 point DFT. So the output of IDFT would be containing 256 samples instead
of 306 samples, which follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51
respectively of the two inputs. Thus the output which should have been 306 samples long is
fitted into 256 samples. The 256 points end up being a distorted version of the correct signal.
This process is called circular convolution.

PROGRAM:

%circular convolution program


clc;clear all;close all;
disp('circular convolution program');
x=input('enter i/p x(n):');
m=length(x);
h=input('enter i/p sequence h(n)');
n=length(h);
subplot(2,2,1), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
subplot(2,2,2), stem(h);
title('i/p sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);

y(1)=0;

13
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%ciruclar conv
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');grid;

RESULT:

14
DFT AND IDFT
AIM: To develop a program for Computing DFT and IDFT in MATLAB

REQUIREMENTS: MATLAB 7.5

THEORY:
The discrete Fourier transform (DFT) X[k] of a finite-length sequence x[n] can be easily
computed in MATLAB using the function fft. There are two versions of this function. fft(x)
computes the DFT X[k] of the sequence x[n] where the length of X[k] is the same as that of x[n].
fft(x,L) computes the L-point DFT of a sequence x[n] of lengthN where L ≥ N. IfL > N, x[n] is
zero-padded with L−N trailing zero-valued samples before the DFT is computed. The inverse
discrete Fourier transform (IDFT) x[n] of a DFT sequence X[k] can likewise be computed using
the function ifft, which also has two versions.

PROGRAM CODE:

% Program to perform Discrete Fourier Transform


clc;clear all; close all hidden;
x=input('The given sequence is x(n): ');
N=length(x);
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n).*exp(-j.*2.*pi.*(n-1).*(k-1)./N);
end
end
display('The DFT of the given sequence is:')
X
p=0:(N-1);
stem(p,abs(X)),grid

Input Sequence:-

ALGORITHM:

1 Enter the input Sequence ,x having length=4

15
2 Set the range of k according to the length of x.
3 Computing DFT, store the value in X(k).
4 Plotting the DFT of given Sequence,store in X(k).
RESULT:
20

18

16

14

12

10

0
0 0.5 1 1.5 2 2.5 3

Fig shows DFT of input sequence

% Program to perform Inverse Discrete Fourier Transform


clc;clear all; close all hidden;
x=input('The given sequence is x(n): ');
N=length(x);
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n).*exp(j.*2.*pi.*(n-1).*(k-1)./N);
end
end
display('The DFT of the given sequence is:')
X
p=0:(N-1);
16
stem(p,abs(X)),grid

Input Sequence:

ALGORITHM:

1 Enter the input Sequence, x having length=4


2 Set the range of k according to the length of x.
3 Computing IDFT, store the value in X(k).
4 Plotting the IDFT of given Sequence, store in X(k).

RESULT:
10

0
0 0.5 1 1.5 2 2.5 3

Fig shows IDFT of input sequence

17
INVERSE Z TRANSFORM

AIM: To develop a program for Computing Inverse Z-Transform

EQUIPMENTS: MATLAB 7.5

THEORY:
Description: In mathematics and signal processing, the Z-transform converts a discrete
time-domain signal, which is a sequence of real or complex numbers, into a complex frequency-
domain representation. The Z-transform, like many other integral transforms, can be defined as
either a one-sided or two-sided transform.
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z)
defined as

.
Alternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or unilateral
Z-transform is defined as

In signal processing, this definition is used when the signal is causal.


Rational Z-transform to partial fraction form:
Consider the transfer function in the rational form i-e;
18z3
G(z)= ------------------
18z3+3z2-4z-1
We can evaluate the partial fraction form of the above system using matlab command. The
partial fraction form be,
G(z)= 0.36__ + __0.24__ + _0.4____
18
1 – 0.5z-1 1+0.33 z-1 (1+0.33 z-1)
Matlab command that converts rational z-transform in to partial fraction form is
‘residuez’.
If you want to see the poles and zeros in a zplane. This function displays the poles and zeros
of discrete-time systems. Use the under given matlab command
zplane(b,a)

PROGRAM CODE:

%program to perform Inverse Z-Transform


b=[1,0.4*sqrt(2)];
a=[1,-0.8*sqrt(2),0.64];
[R,P,C]=residuez(b,a);
m=abs(P');
subplot(1,2,1);
plot(m);
title('magnitude');
A=angle(P')/pi;
subplot(1,2,2);
plot(A);
title('Angle');
freqz(a,b,10)

ALGORITHM:

1. Write the poles and zeros of the input sequence.


2. Returned vector R contains the residues,Column vector contains P contains the pole
locations. And row vector contains the direct terms.
3. Plot the pole magnitudes.
4. Plot the pole angles in pi units.
5. Plot the frequency response of given z-transform of the given function.

Input Sequence:

RESULT: MAGNITUDE AND ANGLE:-

19
20
m a g n itu d e A n g le
2 0 .2 5
10
M agnitude (dB )

0 .2
0
1 .5 0 .1 5
-1 0
0 .1
-2 0
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1 1 0 .0 5
N o r m a l i z e d F r e q× uπ er an dc / ys a (m p l e )
0
150
0 .5 -0 .0 5

100 -0 .1
P has e (degrees )

0 -0 .1 5
50
-0 .2

0 -0 .5 -0 .2 5
0 0 .1 0 .2 0 .3 0 .4 0 .5 0 .6 0 .7 0 .8 0 .9 1 1 1 .5 2 1 1 .5 2
N o r m a l i z e d F r e q× uπ er an dc / ys a (m p l e )

Experiment no 6
AIM : To design and implement on a breadboard a circuit to perform Amplitude modulation.
APPARATUS: Two IC BC 107BP,33k, 100k,two 4.7k,270ohm resistor, two 4.7μF capacitor,
CRO(20 Mhz),Function generator(1Mhz),connecting wires and probes.

20
PROCEDURE:-
1. Connect the circuit as per the given circuit diagram.
2. Apply fixed frequency carrier signal to carrier input terminals.
3. Apply modulating signal from function generator of 1VP-P of 500Hz.
4. Note down and trace the modulated signal envelop on the CRO screen. 5. Find the modulation
index by measuring Vmax and Vmin from the modulated (detected/ traced) envelope.
M=(Vmax –Vmin)/(Vmax+Vmin)
6. Repeat the steps 3,4 & 5 by changing the frequency or/& amplitude of the modulating signal
so as to observe over modulation, under modulating and perfect modulation.
7. For demodulation, apply the modulated signal (A.M) as an input to the demodulator and verify
the demodulated output with respect to the applied modulating signals and their respective
outputs.

21
Observed m= (Vmax + V min) / (V max – V min )

22
ERROR ANALYSIS: Calculate Modulation index using mathematical formula mc = Vm/Vc.
%AGE ERROR = ((m –mc)/ mc)x100% RESULT:

23
Experiment no 7
AIM : To design and implement on a breadboard a circuit to perform Frequency modulation.
APPARATUS: IC LM 2206,10k, two 100k,three 4.7k,220ohm resistor,22μF,1μF,10μF,0.01μF,
CRO(20 Mhz),Function generator(1Mhz),connecting wires and probes. CIRCUIT DIAGRAM:

1. Connect the circuit as per the given circuit diagram.


2. 2. Apply the modulating signal of 500HZ with 1Vp-p.
3. Trace the modulated wave on the C.R.O & plot the same on graph.
4. Find the modulation index by measuring minimum and maximum frequency deviations
from the carrier frequency using the CRO. M = S/f = maximum Frequency deviation /
[ modulating signal frequency
5. Repeat the steps 3& 4 by changing the amplitude and /or frequency of the modulating
Signal.

EXPECTED WAVEFORMS

24
OBSERVATION TABLE
Formula used: m f = δ / f m
where δ = k Vm fc
K is the proportionality constant

25
Find the average m f. Calculated mf = kVm fc /fm mf min = mf max = mf avg cal = %age error =
((Calculated mf - observed mf ) / Calculated mf )x100%

26
Result
Experiment -8
AIM Interfacing 8x8 keyboard using 8085 microprocessor.
Apparatus required Push Switches (64)
SAMPLE PROGRAM:

Block Diagram

Source program
MVI A, 90H : Initialize Port A as input and
OUT CR : Port B as Output
START: MVI A, 00 : Make all scan lines zero
OUT PB
BACK: IN PA
CPI FF : Check for key release
JNZ BACK : If not, wait for key release
CALL DELAY : Wait for key debounce
BACK 1: IN PA

27
CPI FF : Check for key press
JZ BACK 1 : If not, wait for key press
CALL DELAY : Wait for key debounce
MVI L, 00H : Initialize key counter
MVI C, 08H
MVI B, FEH : Make one column low
NEXTCOL: MOV A, B
OUT PB
MVI D, 08H : Initialize row counter
IN PA : Read return line status
NEXTROW: RRC : Check for one row
JNC DISPLAY : If zero, goto display else continue
INR L : Increment key counter
DCR D : Decrement row counter
JNZ NEXTROW : Check for next row
MOV A, B
RLC : Select the next column
MOV B, A
DCR C : Decrement column count
JNZ NEXTCOL : Check for last column if not repeat
JMP START : Go to start
INTERFACING SCHEME

Delay subroutine:
Delay: LXI D, Count
Back: DCX D
MOV A, D
ORA E
JNZ Back
RET
FLOWCHART

28
Conclusion A stepper motor is a digital motor. It can be driven by digital signal. Fig. shows the
typical 2 phase motor rated 12V /0.67 A/ph interfaced with the 8085 microprocessor system
using 8255. Motor shown in the circuit has two phases, with center-tap winding. The center taps
of these windings are connected to the 12V supply. Due to this, motor can be excited by
grounding four terminals of the two windings. Motor can be rotated in steps by giving proper
excitation sequence to these windings. The lower nibble of port A of the 8255 is used to generate
excitation signals in the proper sequence. These excitation signals are buffered using driver
transistors. The transistors are selected such that they can source rated current for the
windings.Motor is rotated by 1.80 per excitation.
____________________________________________________________________________

29
Experiment 9
AIM Generation of delay in binary counting using 8085 microprocessor .
SAMPLE PROGRAM Write a program for displaying binary up counter. Counter should count
numbers from 00 to FFH and it should increment after every 0.5 sec.
Source Program:
LXI SP, 27FFH : Initialize stack pointer
MVI C, OOH : Initialize counter
BACK: CALL Display : Call display subroutine
CALL Delay : Call delay subroutine
INR C : Increment counter
MOV A, C CPI OOH : Check counter is > FFH
JNZ BACK : If not, repeat
HLT : Stop
Delay Subroutine:
Delay: LXI B, count : Initialize count
BACK: DCX D : Decrement count
MOV A, E
ORA D : Logically OR D and E
JNZ BACK : If result is not 0 repeat RET : Return to main program

30
Experiment 10

AIM: TO implement a moving 7-segment display with suitable delay using 8085
microprocessor.

Apparatus required 7-segment display


Sample program Interface an 8-digit 7 segment LED display using 8255 to the 8085
microprocessor system and write an 8085 assembly language routine to display message on the
display.
INTERFACING SCHEME

31
CONCLUSION
Fig. shows the multiplexed eight 7-segment display connected in the 8085 system using 8255. In
this circuit port A and port B are used as simple latched output ports. Port A provides the
segment data inputs to the display and port B provides a means of selecting a display position at
32
a time for multiplexing the displays. A0-A7 lines are used to decode the addresses for 8255. For
this circuit different addresses are:
PA = 00H PB = 01H
PC = 02H CR = 03H.
The register values are chosen in Fig. such that the segment current is 80 mA. This current is
required to produce an average of 10 mA per segment as the displays are multiplexed. In this
type of display system, only one of the eight display position is 'ON' at any given instant. Only
one digit is selected at a time by giving low signal on the corresponding control line. Maximum
anode current is 560 mA (7-segments x 80 mA = 560 mA), but the average anode current is 70
mA.

33
Experiment 11
Aim: Write a program to interface two digit numbers using seven Segment LEDs, use 8086
microprocessor and 8255 PPI

Apparatus required 7-segment display

Flow Chart

34
35
Circuit Diagram

Conclusion
Fig. shows the interfacing of eight 7-segment digits to 8085 through 8279. As
shown in the figure eight display lines (Bo-B3 and Ao-A3) are buffered with
the help of transistor and used to drive display digits. These buffered lines
are connected in parallel to all display digits. So, Sl and S2 lines are decoded
and decoded lines are used for selection of one of the eight digits

Source program:
LXI B, 6200B : Initialize lookup table pointer
MVI C, 08H : Initialize counter
MVI A, 00H : Initialize keyboard/display
OUT 8IH : Mode

36
MVI A, 3EH : Initialize prescaler count
OUT 8IH
MVI A, 90H : Initial size 8279 in write Display
OUT 8IH : RAM-mode
BACK : MOV A, M : Get the 7-segment code
OUT 80H : Write 7-segment code in display RAM
INX H : Increment lookup table pointer
DCR C : Decrement counter
JNZ BACK : if count = 0 stop, otherwise go to back
HLT : Stop program execution

37

You might also like