14670_lmece303 latest

44
LABORATORY MANUAL ECE 303 and ECE353 Unified Electronics Lab-III 1

Upload: sahil-sood

Post on 14-Oct-2014

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 14670_LMECE303 Latest

LABORATORY MANUAL

ECE 303 and ECE353

Unified Electronics Lab-III

1

Page 2: 14670_LMECE303 Latest

S.No Name of the Experiments Sr no

MATLAB

1. To develop program for designing an FIR and IIR filter 3

2. To develop a program for Computing discrete Convolution and Correlation 10

3. To develop a program for Computing Circular Convolution 13

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 using seven Segment LEDs, use 8086 microprocessor and 8255 PPI.

FIR filters

2

Page 3: 14670_LMECE303 Latest

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 techniquesclc;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;endc=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');if(c==1)

3

Page 4: 14670_LMECE303 Latest

y=rectwin(n1);disp('Rectangular window filter response');endif (c==2)y=triang(n1);disp('Triangular window filter response');endif(c==3)y=kaiser(n1);disp('kaiser window filter response');end%LPFb=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-->');%HPFb=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-->');%BPFwn=[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-->');%BSFb=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-->')

4

Page 5: 14670_LMECE303 Latest

RESULTS:

5

Page 6: 14670_LMECE303 Latest

6

Page 7: 14670_LMECE303 Latest

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 IIRfilters, cutoff frequencies of the filters should be mentioned. The order of the filtercan be estimated using butter worth polynomial. That’s why the filters are named asbutter worth filters. Filter coefficients can be found and the response can be plotted.

PROGRAM:

% IIR filters LPF & HPFclc;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

7

Page 8: 14670_LMECE303 Latest

if(c==2) disp('Frequency response of IIR HPF is:');[b,a]=butter(n,wn,'high','s');endw=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

Page 9: 14670_LMECE303 Latest

9

Page 10: 14670_LMECE303 Latest

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=42. Enter the Impulse Sequence, h having length=43. Performing the Convolution, store the value in y4. 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);

10

Page 11: 14670_LMECE303 Latest

title('i/p sequencce x(n)is:');xlabel('---->n');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-1y(i)=0;for j=1:m+n-1 if(j<i+1)y(i)=y(i)+x(j)*h(i-j+1);endendendysubplot(2,2,[3,4]),stem(y);title('convolution of x(n) & h(n) is :');xlabel('---->n');ylabel('---->y(n)');grid;

RESULT:

11

Page 12: 14670_LMECE303 Latest

%program for discrete Correlationx=[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=42 Enter the Impulse Sequence, y having length=43 Performing the Correlation, store the value in y4 Plotting the Output Sequence ,store in z.

RESULT:

1 2 3 40

1

2

3

4input sequence 1

1 2 3 40

2

4

6input sequence 2

0 2 4 6 80

10

20

30

40output sequence

12

Page 13: 14670_LMECE303 Latest

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 programclc;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

13

Page 14: 14670_LMECE303 Latest

x=[x,zeros(1,n-m)]; m=n;end y=zeros(1,n);

y(1)=0; 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); endfor 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 endendysubplot(2,2,[3,4]),stem(y);title('convolution of x(n) & h(n) is:');xlabel('---->n');ylabel('---->y(n)');grid;

RESULT:

14

Page 15: 14670_LMECE303 Latest

DFT AND IDFTAIM: 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 Transformclc;clear all; close all hidden;x=input('The given sequence is x(n): ');N=length(x);for k=1:NX(k)=0;for n=1:NX(k)=X(k)+x(n).*exp(-j.*2.*pi.*(n-1).*(k-1)./N);end

15

Page 16: 14670_LMECE303 Latest

enddisplay('The DFT of the given sequence is:')Xp=0:(N-1);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 DFT, store the value in X(k).4 Plotting the DFT of given Sequence,store in X(k).RESULT:

16

Page 17: 14670_LMECE303 Latest

0 0.5 1 1.5 2 2.5 30

2

4

6

8

10

12

14

16

18

20

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:NX(k)=0;for n=1:NX(k)=X(k)+x(n).*exp(j.*2.*pi.*(n-1).*(k-1)./N);endenddisplay('The DFT of the given sequence is:')Xp=0:(N-1);stem(p,abs(X)),grid

Input Sequence:

ALGORITHM:

1 Enter the input Sequence, x having length=42 Set the range of k according to the length of x.3 Computing IDFT, store the value in X(k).

17

Page 18: 14670_LMECE303 Latest

4 Plotting the IDFT of given Sequence, store in X(k).

RESULT:

0 0.5 1 1.5 2 2.5 30

1

2

3

4

5

6

7

8

9

10

Fig shows IDFT of input sequence

18

Page 19: 14670_LMECE303 Latest

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-1We 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____ 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-Transformb=[1,0.4*sqrt(2)];a=[1,-0.8*sqrt(2),0.64];[R,P,C]=residuez(b,a);

19

Page 20: 14670_LMECE303 Latest

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:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

50

100

150

Normalized Frequency ( rad/sample)

Phas

e (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-20

-10

0

10

20

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

1 1.5 2-0.5

0

0.5

1

1.5

2magnitude

1 1.5 2-0.25

-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2

0.25Angle

20

Page 21: 14670_LMECE303 Latest

Experiment no 6AIM : 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.

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

Page 22: 14670_LMECE303 Latest

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

Page 23: 14670_LMECE303 Latest

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

23

Page 24: 14670_LMECE303 Latest

Experiment no 7AIM : 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

Page 25: 14670_LMECE303 Latest

OBSERVATION TABLE Formula used: m f = δ / f m

where δ = k Vm fc K is the proportionality constant

25

Page 26: 14670_LMECE303 Latest

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

Page 27: 14670_LMECE303 Latest

Result

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

Block Diagram

Source programMVI A, 90H : Initialize Port A as input andOUT CR : Port B as OutputSTART: MVI A, 00 : Make all scan lines zeroOUT PBBACK: IN PACPI FF : Check for key releaseJNZ BACK : If not, wait for key releaseCALL DELAY : Wait for key debounce

27

Page 28: 14670_LMECE303 Latest

BACK 1: IN PACPI FF : Check for key pressJZ BACK 1 : If not, wait for key pressCALL DELAY : Wait for key debounceMVI L, 00H : Initialize key counterMVI C, 08HMVI B, FEH : Make one column lowNEXTCOL: MOV A, BOUT PBMVI D, 08H : Initialize row counterIN PA : Read return line statusNEXTROW: RRC : Check for one rowJNC DISPLAY : If zero, goto display else continueINR L : Increment key counterDCR D : Decrement row counterJNZ NEXTROW : Check for next rowMOV A, BRLC : Select the next columnMOV B, ADCR C : Decrement column countJNZ NEXTCOL : Check for last column if not repeatJMP START : Go to startINTERFACING SCHEME

Delay subroutine:Delay: LXI D, CountBack: DCX DMOV A, DORA EJNZ BackRETFLOWCHART

28

Page 29: 14670_LMECE303 Latest

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

Page 30: 14670_LMECE303 Latest

Experiment 9AIM 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, repeatHLT : 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

Page 31: 14670_LMECE303 Latest

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

Page 32: 14670_LMECE303 Latest

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

32

Page 33: 14670_LMECE303 Latest

segment data inputs to the display and port B provides a means of selecting a display position at 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 = 01HPC = 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

Page 34: 14670_LMECE303 Latest

Experiment 11Aim: 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

Page 36: 14670_LMECE303 Latest

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

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

36