You are on page 1of 36

St.

Thomas’ College of Engineering &


Technology

Department of Electrical Engineering

Project Report

On
“Application of Orthogonal Hybrid function for the
Analysis and Synthesis of Control System”

By
Aninda Chatterjee (Roll No-14)

Spandan Chatterjee (Roll No-15)

Amitava Paul (Roll No-41)

Aritra Purkait (Roll No-44)

Srideep Saha (Roll No-49)

Sangramjit Sarkar (Roll No-55)

UNDER THE GUIDANCE OF


Ms. ANINDITA GANGULY

MAY 2013
St. Thomas’ College of Engineering &
Technology

Department of Electrical Engineering

CERTIFICATE OF APPROVAL

The project entitled ‘Application of Orthogonal Hybrid Function for the Analysis and
Synthesis of Control System’submitted by Aritra Purkait ,Sangramjit Sarkar,Amitava
Paul, Aninda Chatterjee, Spandan Chatterjee ,Srideep Saha done under my supervision
and guidance is accepted for partial fulfillment of the requirement to award the
degree of Bachelor of Technology in Electrical Engineering of St. Thomas’ College of
Engineering & Technology under West Bengal University of Technology, Kolkata.

This is to certify that the work embodied in this project has not been
submitted elsewhere for any other degree.

Prof. P.K. Pradhan Anindita Ganguly External Examiner


H.O.D EE Project guide
ACKNOWLEDGEMENT
We would like to express our gratitude to our project guide Ms. Anindita
Ganguly who has always been a source of motivation and firm support while carrying
out the project. We would like to convey our gratitude to Sujit Kumar Biswas(SKB),
Jadavpur University and part-time faculty of STCET, for the various suggestions which
helped us in ironing out the problems in our hardware circuit ; to Mr. Lekhan Saha,
Electrical Engineering Department, STCET and Ramanath Datta(RND), Electronics &
Communication Department, STCET for allowing us access to the instruments at all
times. We want to thank Mr.Shamik Rudra(SRU), STCET for sourcing hard to find
components for us. Also we want to thank Dr. Bimal Sen(BBS) for his support and
encouragement throughout the project.

We would also like to convey our sincerest gratitude and indebtedness to all
other faculty members and staff of the Department of Electrical Engineering,
St.Thomas’ College of Engineering and Technology, who guided us at appropriate
times, without which it would have been difficult on our project work.

(Aninda Chatterjee, 14)

(Spandan Chatterjee, 15)

(Amitava Paul, 41)

(Aritra Purkait, 44)

(Srideep Saha, 49)

(Sangramjit Sarkar, 55)


INDEX
Serial Particulars Page No
no.
1 Introduction 1

2 Objective 4

4 Methodology 4

5 Block Diagram 6

6 MATLAB model 8

7 Circuit Diagram 10

8 Response of Hardware and Software model 14

9 Result Analysis 16

10 Problems Encountered 21

11 Limitations 22

12 Future Extension 23

13 Conclusion 23

14 References 24

15 Appendix
Component List 25
Code 26
Datasheets 31
Introduction: - Analysis and synthesis are two fundamental problems of control
engineering. Analysis is the process or technique by which we are able to find the
response of a system excited by given input. In simple words it the method to find
the response when the excitation and the mathematical model of the system are
known to us. On the other hand, synthesis or design is to identify the mathematical
model of the system from the input-output relationship.

Fig1-Analysis Problem: i/p & system are known but o/p is unknown

Fig2-Synthesis Problem: i/p & o/p are known but system is unknown

In orthodox method, there are different ways of system analysis and synthesis based
on different convenient mathematical tools. This project is based on a new way of
system analysis and that is-Hybrid Function (HF) method. This method has a lot
potential for successful system identification. Digital computing has revolutionized
the field of modern technology. Since HF based computation involves working with
samples instead of actual analog signal it proves to be very simple and numerically
accurate. In the circumstances where only certain sample values are available in lieu
of the actual waveshape of the signal HF method is quite advantageous to be used.

1|Page
An introduction to Hybrid Function:- Prior to Introduction to Hybrid function its
essential first to define the notion of orthogonal function sets.

A time function f(t) defined over the time interval [0, T ) may be represented by an
orthogonal function set S(t) as


n  0
c nS n(t )

where, Cn’s are the coefficients of different members of the orthogonal set.

The members of the function set S(t) are said to be orthogonal in the interval
0≤ t < T if for any positive integral values of n and m, we have

T
0
S m ( t ) S n ( t ) dt   mn
where, δmn = 0 for m ≠ n and when m = n, δmn = a constant.

Some common examples of orthogonal function sets are sinusoidal function set. Its
usefulness is well justified by the idea given by Fourier that any periodic function can
be realized as summation of infinite no of sinusoids. But let’s have a look at some of
the other kinds of orthogonal function sets which are very useful in digital
computation.

A set of four Sample–and–Hold functions, over a period T, is defined as

A set of four Triangular functions, over a period T, is defined as

where, i = 0, 1, 2, 3, m = 4 and h = T/m

2|Page
Fig3- A set of SHF with 4 members Fig4- A set of TF with 4 members

Now we are in a position to describe Hybrid Function (HF) and using it how we can
approximate any square integrable continuous time function f(t).

Consider any arbitrary continuous time function


f(t) as shown in the figure. The function is
sampled at three points marked as A, C, E. Here
C0BFO and C1DGF are the SAMPLE & HOLD and
C0BC1, C1DC2 are the TRIANGULAR FUNCTIONS.

Hence determining the values of C0, C1 and C2


we can approximate the original continuous
time function f(t) by two piecewise linear
segments AC and BC between the interval O and
G.

This discussion unveils the essence of HF


technique of function approximation which is
the ability to produce such approximated signal
Fig5-HF based approximation of f(t) in laboratory by employing very simple and cost-
effective hardware components

3|Page
Hence in general, if we consider a function f(t) in an interval t Є [0,T). Considering
(m+1) equidistant samples of the function with a sampling period h (i. e., T = mh), we
can write

Here S(m)(t) : mth co-efficient of SHF (Sample and Hold Function).


& T(m)(t) : mth co-efficient of TF (Triangular Function).

An important and interesting is that the realization of any function f(t) requires only
sampling the signal at an equal intervals (and obviously obeying Nyquist Sampling
Theorem) i.e we don’t have to solve the integrals like Fourier series expansion to find
the co-efficient of the corresponding basis functions. This is one of the great
advantages of working with HF.

Objective: - Objective of this project is to analysis any LTI system using HF method.
To do this standard test signals like sine wave, step, ramp and others are used. In HF
method only knowing the samples of i/p to the plant and the plant transfer function
we can accurately calculate the samples of the o/p waveform. This is justified using
hardware model.

Methodology: - Main idea is to first realize the actual continuous time input signal
into HF domain. It is done by sampling the actual signal and then joining these
sample points to construct a piecewise linear waveform. This piecewise linearly
joined waveform is the HF approximation of the actual signal. This signal is fed to the
system and the response is observed in DSO. On the other hand, the samples of the
input waveform are stored in microcontroller memory and using these samples & the
transfer function of the system we can compute the samples of the response using
HF based algorithm as indicated in ref [10]. Using these computed samples we
attempt to reconstruct the response using HF mathematics and compare the results
graphically as well as numerically.

4|Page
Piecewise Plant Response Sampler (ADC)
Excitation
linear wave

Fig6-Practical model

Excitation Sampler (ADC) HF based algorithm Samples of Response


Fig7-Mathematical model

The input signal may be any arbitrary random signal but for analysis standard test
signals like step, ramp, parabola, and sinusoidal are considered. Here First attempt is
made based on sinusoidal waveform because it has both positive and negative swing.

Since the input is of a known (sinusoidal wave) nature, instead of actually sampling
the wave at the initial stage the samples are pre-calculated for a 1Hz sine wave and
directly used to construct the SHF (Sample and Hold Function) or ZOH (Zero order
wave) as explained later.

System or Plant is initially taken as 1st order RC circuit for the sake of simplicity and
then it is further this way of analysis is extended for 2nd order RC circuit.

5|Page
Block Diagram:-

Continuous Sampler Controller Linear


Signal (I/P) (ADC) (uC) DAC Joiner

Sampler
(ADC) Load

1. Continuous Signal
A continuous signal is input into the system. It may be a known signal (sine
wave, triangular wave, square wave etc) or a random signal.
This signal can have both positive and negative value (e.g a sine wave).

2. Sampler(ADC)
The continuous waveform is converted into a digital waveform by quantizing
the input with a fixed time delay between each measurement.
The ADC present inside the microcontroller was used here. It can only
measure voltages lying between 0 – 5 V. So the input signal has to be
attenuated so that its peak to peak value is less than 5 V. Some amount of
positive voltage is injected into the signal so that the entire signal becomes
positive.

Continuous Voltage Sampler


Signal (I/P) Attenuator Level Shifter (ADC)

3. Controller
The controller controls the sampling rate of the ADC and stores the samples in
memory. It performs some signal processing operations and then outputs the
result through the DAC.
4. DAC
An 8 bit R-2R ladder DAC is used is used to convert the digital samples into
analog output.

6|Page
5. Linear Joiner
O/p of the DAC is piecewise linearly joined together to reconstruct an
approximate version of the original input signal (continuous wave). This
piecewise linearly joined waveform is the HF approximation of the actual
continuous time i/p signal.

6. Load
The piecewise linearly joined wave is fed to the load (1 st order circuit or 2nd
order RC circuit has been used in this experiment) and the response is viewed
using a Digital Storage Oscilloscope.

7. Sampler(ADC)
The output of the load is sampled using an ADC for hybrid function analysis.
Since the output of the Load will have both positive and negative
voltages, the output is attenuated and level shifted so that the whole signal
lies in the positive plane and its peak to peak value is less than 5V just like in
stage 2.

Voltage Sampler
Load Attenuator Level Shifter (ADC)

Linear Joiner: - this block requires special attention because it is actually the signal
reconstruction block which is the heart of this project. The philosophy of signal
reconstruction from the sampled versions of the input signal is explained here from
the HF point of view.

1st we have to approximate the continuous function by sample and hold functions. It
is done by sampling by using an ADC (when the samples are not given but the actual
continuous signal is available) and then converting into a ZOH (Zero Order Hold)
signal using a microcontroller & DAC. In the next stage the TRAINGULAR function
approximation is done with the help of integrator. After these two stages finally we
get the piecewise linear HF based approximation of the original wave.

7|Page
MATLAB-SIMULINK block diagram model for 1st order system: -

Fig8- MATLAB-SIMLINK block diagram model for 1st order system

Since sampling time is chosen as 100ms and 10 samples of ZOH sine wave is taken to
create a 1Hz sine wave we need the value of the RC to set as 100ms hence the time
constant is 1/RC=0.1 as shown in the ‘Linear Interpolator’ block.

To accurately join any two consecutive corner points of the ZOH sine wave, it is
essential to integrate the voltage difference between the next and the present
sampling point. Hence a comparator block is used prior to the ‘Linear Interpolator
Block’.

The peak to peak voltage o/p from the microcontroller can be maximum 5 volt which
can’t be negative. Hence, at the final stage, the signal ground is shifted by -2.5 V to
ensure the voltage swing both below and above the ground line.

The ‘1st order Plant’ block is the system which is to be fed by the approximated
signal.

8|Page
MATLAB-SIMULINK block diagram model for 2nd order system: -

Fig9- MATLAB-SIMLINK block diagram model for 2nd order system

Rest of the things in this block is same except the transfer function. This transfer
function is constructed as cascading following stages. Note each of these stages is
observed as described in details later in circuit diagram section. Transfer Function1
and Transfer function2 are easily realized through simple 1st order RC circuits.

Fig10- MATLAB-SIMLINK block diagram model of 2nd order plant

9|Page
Circuit Diagram: - The detailed circuit Diagram is shown below which
incorporates all the blocks described above.

Fig11-Circuit Diagram of the entire scheme

Fig12-Non inverting summer used as voltage level shifter

At the leftmost of this diagram there is a differential amplifier with unity gain. It is
used to shift the voltage of the waveform input to the integrator. This waveform is
obtained by finding the differences of the corresponding samples of the actual

10 | P a g e
waveform in the microcontroller and passing it through a DAC in order to get the TF
realization of the actual continuous wave. The Integration time constant is set as 0.1
by setting product R2C2 as 0.1 as the sampling rate was 0.1sec. 3rd op-amp is the part
of the integrator which is used as a unity gain inverter. Now comes to the stage to
inputting the piecewise linear wave to the plant (in the diagram 1st order plant is
shown and 2nd order plant is shown later). To avoid loading effect the 4th op-amp
shown in the circuit diagram is used as a unity gain buffer. After getting the response,
to shift the voltage level of the response finally by 2.5 volt an adder (in the non-
inverting mode) is used.

Fig13-Circuit Diagram of the 2nd order plant

Block diagram given in Fig. 10 can be helpful to understand this circuit diagram of the
2nd order plant. Initial gain block has been realized using the difference amplifier
where 4.7Kohm and 1kohm resistances are used to provide gain 4.7 of this gain
block. Two series RC circuits are used to implement the two transfer functions as
shown on the Fig.10. 2nd and 3rd op-amps are used as buffers for successful cascading
of the blocks.

11 | P a g e
12 | P a g e
Snapshot of hardware circuit:-

Fig 15 – 2 x 8 bit DAC and microcontroller

Fig16- Linear joiner and 2nd order plant

13 | P a g e
I/P and reconstructed waveform for MATLAB-SIMULINK model: -

Fig17 – ZOH original sine wave of frequency 1Hz Fig18 – ZOH shifted sine

Fig19 – Integrator o/p-Piecewise Linear wave Fig 20– Piecewise linear wave fed to RC ckt.

14 | P a g e
I/P and reconstructed waveform for hardware model: -

Fig21- ZOH sine wave Fig22 -Piecewise linearly joined


wave

Response (O/P) of 1st order plant: -

Fig23 - Response of 1st order plant for MATLAB- Fig24- Response of 1st order plant for
SIMULINK model hardware model

15 | P a g e
Response (O/P) of 2nd order plant: -

Fig25 - Response of 2nd rder plant for MATLAB- Fig26 - Response of 2nd order plant for
SIMULINK model hardware model

Result analysis: -

Fig27 –Plot of Responses of 1ST order plant using direct samples of the MATLAB-SIMULINK response (blue
trace)
&
samples computing using HF algorithm (red trace)

16 | P a g e
Fig28 –Plot of Responses of 2nd order plant using direct samples of the MATLAB-SIMULINK response (blue trace)
&
samples computing using HF algorithm (red trace)

The above two plots show the comparative study between the responses which are
obtained by joining the direct samples of the responses of the MATLAB-SIMULINK
model (i.e ideal model) and by computing those samples as described in ref [10]
using HF based algorithm. As these two different coloured (red and blue) plots
almost merge together (as thus it is difficult to distinguish them is some portions of
the plot) the error is marginal. Detailed error tables and corresponding error plots
are shown next.

In the error analysis it is found that the absolute error is within 10%.This can also be
reduced to a greater extent by enhancing the sampling rate.

17 | P a g e
Error table of 1st order plant for sampling at 0.1s-

Sampling instants Direct Samples of Samples of o/p y(t) Percentage error


(s) o/p y(t) via HF

0.0 0.000000 0.000000 ------------


0.1 -1.382500 -1.520419 -9.976054
0.2 -1.408437 -1.498227 -6.375129
0.3 -0.548372 -0.595966 -8.679117
0.4 0.603735 0.646812 -7.134959
0.5 1.624526 1.705697 -4.996622
0.6 2.051280 2.094293 -2.096853
0.7 1.522355 1.595167 -4.782816
0.8 0.403800 0.428194 -6.041072
0.9 -0.905658 -0.959006 -5.890467
1.0 -1.979414 -2.085004 -5.334416

Percentage error plot for 1st order plant-

Fig29 – Percentage error curve for 1st order plant.

18 | P a g e
Error table of 2nd order plant for sampling at 0.1s-

Sampling instants Direct Samples of o/p Samples of o/p y(t) Percentage error
(s) y(t) via HF

0.0 0.000000 0.000000 ------------


0.1 0.005825 0.005319 8.673346
0.2 0.041968 0.039642 5.541809
0.3 0.122168 0.116489 4.648369
0.4 0.237913 0.227906 4.206037
0.5 0.361861 0.347673 3.920711
0.6 0.458571 0.441581 3.705013
0.7 0.498419 0.480860 3.523008
0.8 0.469358 0.453612 3.354649
0.9 0.382011 0.369830 3.188681
1.0 0.266138 0.258073 3.030310

Percentage error plot for 2nd order plant-

Fig30 – Percentage error curve for 2nd order plant.

19 | P a g e
Comparative study of the performance of the actual hardware model and the HF
based algorithmic computation method-

Two curves of the 1st order responses are plotted and shown in the fig-29. One curve
of the response of the 1st order plant (shown by solid trace) is plotted by collecting the
actual samples values of the response using ADC. This set of values is tabulated below-

ADC reading ADC (V) Offset(V) Actual(V)


145 0.71 2.40 -1.70
133 0.65 2.40 -1.75
232 1.13 2.40 -1.27
417 2.04 2.40 -0.37
616 3.01 2.40 0.61
748 3.66 2.40 1.25
759 3.71 2.40 1.30
642 3.14 2.40 0.73
437 2.14 2.40 -0.27
218 1.07 2.40 -1.34
90 0.44 2.40 -1.96
92 0.45 2.40 -1.96
201 0.98 2.40 -1.42
393 1.92 2.40 -0.48
597 2.92 2.40 0.51
728 3.56 2.40 1.15
737 3.60 2.40 1.20
616 3.01 2.40 0.61
408 1.99 2.40 -0.41
193 0.94 2.40 -1.46
75 0.37 2.40 -2.04
85 0.42 2.40 -1.99
203 0.99 2.40 -1.41
399 1.95 2.40 -0.45
603 2.95 2.40 0.54
729 3.56 2.40 1.16
729 3.56 2.40 1.16
603 2.95 2.40 0.54
389 1.90 2.40 -0.50
176 0.86 2.40 -1.54
72 0.35 2.40 -2.05
86 0.42 2.40 -1.98
212 1.04 2.40 -1.37

20 | P a g e
The other curve of response of 1st order plant is plotted by computing the samples of
the response using HF based algorithm.

Fig31 – Plot of Responses of 1st order plant using direct samples of the HARDWARE response (solid trace)
&
samples computing using HF algorithm (dotted trace)

Here the two curves deviate quite a lot and hence the error is appreciable. This is due
the hardware model. There are some problems encountered in hardware models
resolving those problems will lead to better result. Such problems are discussed in
the section ‘Problems encountered’ [(iii) and (iv)].

Problems Encountered

I. Since the whole circuit was constructed on a Bread board, various types of
problems were encountered over the course of the experiments. Most of the
problems were due to loose connections of the single strand wires used for
connecting the various stages of the circuit.
II. Initially, an Atmel AT89S52 microcontroller (8051 derivative) was used as the
controller. But at startup, it had to be reset since sometimes it started to
execute the program from the middle. This is a known problem with the 8051
architecture. And also at startup, it took some time to provide stable output
from the DAC. Due to these problems, we shifted to using an Atmel ATmega
8L microcontroller which has a much modern architecture and has none of the
above mentioned problems. Also, it has an integrated 6 channel, 10 bit ADC.
So we could eliminate the external ADC.

21 | P a g e
III. The output of the DAC is totally positive and so to make it resemble the
original input wave (which can have both positive and negative values), we
used a voltage level shifter to shift the level downwards by 2.5V. This was
done by using a 10k multi turn potentiometer connected to the inverting pin
of the first stage of the linear joiner. During the course of the experiment, we
found that the voltage shift that was set using the pot would drift upwards or
downwards by a small value. This introduced an error in the output of the
linear joiner.
IV. In the integrator stage of the linear joiner circuit, we had used an electrolytic
capacitor. Electrolytic capacitors have very large thermal drift. So the output
of the integrator would shift during the time the circuit was on. This was
remedied by using a Tantalum capacitor. Tantalum capacitors have much
lower temperature drift.
V. The output of the linear joiner sometimes used to drift upwards or
downwards on its own. At that time, we had connected the input of the
different stages of the circuit to the ground directly. This was causing an
imbalance in the input offset current. This problem was overcome by
grounding the input through a resistance. The value of the resistance was the
Thevenin equivalent of the resistances used in the circuit as seen by the input
pin.

The problems (iii) and (iv) are the probable reasons for appreciable error
encountered in fig-29.

Limitations

I. The main focus of the experiment was on the reconstruction of the signal and
not too much time was devoted to ensuring that the samples taken by the
ADC is free of noise. A primitive method of filtering out noise was used (using
capacitors as a low pass filter). Also since the circuit was constructed on a vero
board, noise from the electrical circuit in the room, static charge on our
fingers, was injected into it. If a professional grade PCB could be constructed
and other advanced methods of noise filtering could be used, then the
samples would have been much more accurate.
II. Due to the level shifts used in various parts of the circuit, errors creep in into
the final output.
III. The circuit gives quite accurate results for input signals which have both
positive and negative voltage swings (e.g sine wave). But for the signals which
lie totally in the positive half (e.g ramp), it is not that accurate.

22 | P a g e
Future extension: -

The entire process of analysis was primarily initiated based on a a sine wave i/p and
the detailed study ,corresponding error computation and plotting of the response of
actual hardware model were done based on the fact that a 1 st order plant is being
excited by a sine wave. Such detailed studies needed to carried out for 2nd order
hardware model and also by exciting the system using other waveforms such as
ramp, parabola, exponential, arbitrary waveform etc. The reconstruction circuit
including some parts of the entire scheme should have to be changed for such other
types of signals where the signal has no negative excursion and has only positive
values.

The second most important part of the project was aimed to perform the SYNTHESIS
studies using actual hardware model. This was not successfully done and also
excluded from this report due to lack of time at the end.

Conclusion: - Since digital technology has changed the face of the modern technical
era by its ease and efficiency, mathematical computation and related signal
processing for control system engineering and other branches of engineering &
technology in digital domain is of great discussion nowadays. In this context, its
worthwhile to mention HF based mathematics has immense potential to improve
this digital computation technique. It’s a versatile, simple, easy to understand and
implement theory. This project is an attempt to unravel these mathematical utilities
of HF theory by a practical hardware circuit model (1st order and 2nd order). This
attempt has been partially successful (due to the problems encountered and the
limitations discussed above) with encouraging results that will motivate us to do
further improvement and related research work in this field.

23 | P a g e
References:

[1] Deb, A., Sarkar, G., Bhattacharjee, M., and Sen, S., A new set of piecewise
constant orthogonal functions for the analysis of linear SISO systems with sample-
and-hold, J. Franklin Instt., vol. 335B, no. 2, pp. 333-358, 1998.

[2] Deb, A., Sarkar, G., and Sengupta A., Triangular orthogonal functions for the
analysis of continuous time systems, Anthem Press, London, 2011.

[3] Deb, A., Sarkar, G., Mandal, P., Biswas A., Ganguly A. and Biswas D., Transfer
function identification from impulse response via a new set of orthogonal hybrid
functions (HF), Applied Mathematics and Computation, Vol 218, Issue 9, pp. 4760-
4787, 1 Jan, 2012.

[4] Deb, A., Sarkar, G., Ganguly, A. and Biswas, A., Approximation, integration and
differentiation of time functions using a set of orthogonal hybrid functions (HF) and
their application to solution of first order differential equations, Applied
Mathematics and Computation, Vol 218, Issue 9, pp. 4731-4759, 1 Jan, 2012.

[5] Beauchamp, K. G., Walsh and related orthogonal functions with an introduction to
sequency theory, Academic Press, London, 1984.

[6] Uffenbeck, J., Microcomputers and microprocessors--The 8080, 8085 and Z-80
programming, Interfacing and Troubleshooting, 3rd edition, PHI, New Delhi, 2005.

[7] Mazidi, Muhammad Ali, The 8051 microcontroller and embedded systems, 2nd
edition, Pearson Education, 2008.

[8] Atmel Atmega8 datasheet, Atmel Corporation, USA, 2011.

[9] Hanselman, D. and Littlefield, B., Mastering MATLAB 7, Pearson Education, Delhi,
2005.

[10] Deb, A., Ganguly, A., Sarkar, G., Biswas, A., Computation of Convolution via A
New Set of Orthogonal Hybrid Functions (HF) for Linear Control System Analysis and
Identification , presented at IEEE, INDICON 2012.

24 | P a g e
Appendix

Component Quantity Price/piece (Rs.)


Atmega 8L 1 80
Capacitor
1000uF (electrolytic) 1 2
100uF (electrolytic) 5 2
10uF (electrolytic) 5 2
1uF (electrolytic) 5 2
0.1uF (ceramic) 6 5(per dozen)
10uF (tantalum) 1 10
Resistance
1M ohm 1 20(per 100 pieces)
20k ohm (metal film) 20 1
10k ohm (metal film) 20 1
4.7k ohm 5 20(per 100 pieces)
1k ohm 5 20(per 100 pieces)
10k trim pot (multi turn) 2 12
OP07 6 20
LM358 3 10
Connectors 5 2 (per pin)

Pin Configuration:

LM358

Atmega 8L
25 | P a g e
Code:-

/*--------------------------------------- code for Atmega 8L --------------------------------------------------*/


/*-------------- written & compiled in AVR Studio 4.18 & WinAVR20100110 ----------------------*/

#define F_CPU 1000000UL


#define MAX 10 //MAX = 11 for ramp, 10 for sine wave
#include<avr/io.h>
#include<util/delay.h>

void main()
{ DDRD = 0xFF; //Set all pins of port D as Output
DDRB = 0xFF; //Set all pins of port B as Output

/* _________________ D E C L A R A T I O N _________________ */

volatile unsigned char i=0;

unsigned char output_result[MAX];

unsigned char output[] = {0, 24, 88,167,231,255,231,167,88,24}; //cos wave


//unsigned char output[] = {0,35,60,95,120,165,185,215,235,250,0}; //ramp wave
//unsigned char output[]={255,210,171,140,115,94,77,63,51,42,35,28,23,19,16,
13,10,8}; //negative exp wave
//unsigned char output[] = {51,54,57,69,77,84,93,103,114,120,142,154,170,188,
208,229,254}; //exp wav
//unsigned char output[] = {0,40, 250, 100, 80, 150, 30}; //general wave

/* _________________ P R O G R A M _________________ */
output_result[0] = 127; //max level = 255, ground = 127, min level = 0
for(i=1; i<10; i++)
output_result[i] = output[i] - output[i-1] + 127;

//output_result[MAX-1] = 0;

/* ___________________ O U T P U T ____________________ */
while(1)
{
for(i=0;i<MAX;i++)
{ PORTD = output[i];
PORTB = output_result[i];
_delay_ms(100);
}
}
}

26 | P a g e
/*-------------------------------- PC side data collection program ----------------------------------------*/
/*------------------------------------ written in Arduino v1.0.4 ---------------------------------------------*/
/*------------------------------------------ www.arduino.cc ---------------------------------------------------*/

// adc0 used for measuring the voltage of the output of the LOAD
//adc1 used for measuring the voltage of the voltage offset provided to level shifter
int adc0, adc1, i = 0;

void setup()
{ Serial.begin(9600);
Serial.println("Starting Program");
delay(1000);
Serial.println(" ");
adc1 = analogRead(1);
Serial.print(adc1);
Serial.println(" ");
Serial.print("Analog value = ");
}
void loop()
{ delay(100);
adc0 = analogRead(0); //measure the value every 0.1 sec

Serial.print(adc0); //sends the value to the computer via USB port


Serial.println(" ");
i++;

if(i%10 == 0)
{ adc1 = analogRead(1); //reads the value of offset every 10 samples
Serial.print("Offfset = "); //this gives an idea of the external noise
Serial.print(adc1); //affecting the system
Serial.println(" ");
}
}

MATLAB Code:-

%-------------------------------------------------- file1.m ---------------------------------------------------------


% A program to calculate the o/p samples of a given input samples for a given
% system using HF method.
% Transfer func: g(t) =10*exp(-t*10) for 1st order and
=1.5538*exp(-t*0.75).*sin(1.5124*t) for 2nd order.
% Input : r(t)= sin(2*pi*t)

%Total time span : T=4s


%step size : h= 0.1s
%No of samples : m= 40

clc
T=4;

27 | P a g e
m=40;
h=T/m;
t=0:h:T;

g=10*exp(-t*10);
r=sin1(:,2); % sin1= Input samples of a sine wave input used in simulink model.
%sin1 is matrix of dimension with 2columns, 1st column
%contains the value of time samples an 2nd ol contains
%the values of the amplitude samples .

yd=y_sin1(:,2); % yd : The output samples obtained by directly sampling the continous o/p.
%y_sin1 : The samples of the o/p used in simulink model.
yd=yd' ;

for i=1:2*m;
if i<m+1;
R(i)=2*r(i+1)+r(i);
end
if i==m+1;
R(i)=r(2)+2*r(1);
end
if i>m+1;
R(i)=r(i-m+1)+4*r(i-m)+r(i-m-1);
end
end
R;
for i=2:m+1
y1=[];
y1(i-1)=g(1)*R(i-1);
y2=[];
for p=2:i
y2(p-1)=g(p)*R(m+i-p+1);
z=sum(y2);
y2=[];
y2(p-1)=z;
end
y(i-1)=(h/6)*(y1(i-1)+y2(i-1));
end
y=[0 y];

err=((yd-y )./yd);
err=err*100;

fprintf('\n\t\tSampling instants\t\tDirect samples of o/p y(t) \t\t\tSamples of o/p y(t) via


HF\t\t \tPercentage Error')
fprintf('\n\t\t\t\t\t(s)\t\t\t\t\t\t\t\t\t (yd) \t\t\t\t\t\t\t\t\t\t\t\t\t(y)\t\t\t\t\t\t\t \t\t err')
for i=1:m
fprintf('\n\t\t\t%f\t\t\t\t\t\t\t %f \t\t\t\t\t\t\t\t\t\t\t%f\t\t\t\t\t\t\t
%f',t(i),yd(i),y(i),err(i));

28 | P a g e
end
figure(1)
plot(t,y,'r')
hold on
plot (t,yd)
hold off
figure(2)
plot(t,abs(err),'r')
clear all

%-------------------------------------------------- file2.m ---------------------------------------------------------


% A pragram to plot the responses of using the o/p samples computed by HF method and
%collected by ADC.
% Transfer func: g(t)=10*exp(-t*10).
% Input : r(t)= sin(2*pi*t)
%Total time span : T=4s
%step size : h= 0.1s
%No of samples : m= 40

clc
T=4;
m=40;
h=T/m;
t=0:h:T;

g=10*exp(-t*10);
r=sin1(:,2); % sin1= Input samples of a sine wave input used in simulink model.
%sin1 is matrix of dimension with 2 columns, 1st column
%contains the value of time samples an 2nd col contains
%the values of the amplitude samples .

yd=y_sin1(:,2); % yd : The output samples obtained by directly sampling the continous o/p.
%y_sin1 : The saples of thr o/p used in simulink model.
yd=yd' ;

for i=1:2*m;
if i<m+1;
R(i)=2*r(i+1)+r(i);
end
if i==m+1;
R(i)=r(2)+2*r(1);
end
if i>m+1;
R(i)=r(i-m+1)+4*r(i-m)+r(i-m-1);
end
end
R;
for i=2:m+1
y1=[];

29 | P a g e
y1(i-1)=g(1)*R(i-1);
y2=[];
for p=2:i
y2(p-1)=g(p)*R(m+i-p+1);
z=sum(y2);
y2=[];
y2(p-1)=z;
end
y(i-1)=(h/6)*(y1(i-1)+y2(i-1));
end
y=[0 y];

plot(t,y,'r')
hold on

y_s=[-1.70 %y_s=o/p samples collected by ADC.


-1.75
-1.27
-0.37
0.61
1.25
1.30
0.73
-0.27
-1.34
-1.96
-1.96
-1.42
-0.48
0.51
1.15
1.20
0.61
-0.41
-1.46
-2.04
-1.99
-1.41
-0.45
0.54
1.16
1.16
0.54
-0.50
-1.54
-2.05
-1.98

30 | P a g e
-1.37
-0.39
0.60
1.17
1.14
0.47
-0.57
-1.61];

m=length(y_s)-1;
h1=0.1;
T1=m*h;
t1=0:h1:T1;
plot(t1,y_s)

Component Datasheet:-

31 | P a g e
32 | P a g e

You might also like