208
Geethanjali College of Engineering & Technology Cheeryal(V),R.R(Dist) Basic Simulation Lab ECE – II Year - I semester [2015 -2016] Department of Electronics and Communication Engineering Geethanjali College of Engineering & Technology Cheeryal (V), R.R.(Dist)

BS_Manual modified.doc

Embed Size (px)

Citation preview

Page 1: BS_Manual   modified.doc

Geethanjali College of Engineering & Technology

Cheeryal(V),R.R(Dist)

Basic Simulation Lab

ECE – II Year - I semester

[2015 -2016]

Department of Electronics and Communication EngineeringGeethanjali College of Engineering & Technology

Cheeryal (V), R.R.(Dist)

In-charge HOD-ECE Mr.R.Odaiah Prof. Assoc. Professor

Page 2: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

BASIC SIMULATION LAB

CONTENTS

S.No LIST OF EXPERIMENTS: Page No

1. a) Introduction, 08 b) Basic operations on matrices. 16 2. Generation on various signals and Sequences 22

(periodic and aperiodic), such as unit impulse, unit step, square, sawtooth, triangular, sinusoidal, ramp, sinc.

3. Operations on signals and sequences such as addition, 31 multiplication, scaling, shifting, folding, computation of energy and average power.

4. Finding the even and odd parts of signal/sequence 38 and real and imaginary part of signal.

5. Convolution between signals and sequences. 436. Auto correlation and cross correlation between signals 467. Verification of linearity and time invariance

properties of a given continuous /discrete system and sequences. 498. Computation of unit sample, unit step and sinusoidal 53

response of the given LTI system and verifying its physical Realizability and stability properties.

9. Gibbs phenomenon. 55 10. Finding the Fourier transform of a given Signal and plotting 56 its magnitude and phase spectrum.11. Waveform synthesis using Laplace Transform. 5912. Locating the zeros and poles and plotting the 62

pole zero maps in s-plane and z-plane for the given transfer function.

13. Generation of Gaussian Noise(real and complex), 64 computation of its mean,

14. Sampling theorem verification . 66 15. Removal of noise by auto correlation/cross correlation. 7116. Extraction of periodic signal masked by noise 75

using correlation.17. Verification of Weiner-Khinchine relations 7818. Checking a random process for stationarity in wide sense. 80

Geethanjali College of Engineering & Technology Page 1

Page 3: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

CYCLE –I

1. Introduction about MATLAB/Scilab. Basic operations on Matrices.2. Generation on various signals and Sequences (Periodic and a periodic), such as unit impulse, unit step, Square, saw tooth, triangular, sinusoidal, ramp, sinc.3. Operations on signals and sequences such as addition, Multiplication, scaling, shifting, folding, computation of Energy and average power.4. Finding the Even and Odd parts of signal/sequence And real and imaginary part of signal.5. Convolution between signals and sequences.6. Auto correlation and cross correlation between signals and sequences.7. Verification of linearity and time invariance properties of a given Continuous /discrete system.8. Computation of unit sample, unit step and sinusoidal Response of the given LTI system and verifying its physical Realizability and stability properties.9 . Gibb’s phenomenon.10. Finding the Fourier transform of a given Signal and plotting its magnitude and phase spectrum.

CYCLE –II

11. Waveform synthesis using Laplace Transform.

12. Locating the zeros and poles and plotting the pole zero maps in S-plane and z-plane for the given transfer function.

13. Generation of Gaussian Noise (real and complex), computation of its mean, M.S value and its Skew, Kurtosis and PSD, Probability Distribution Function.14. Sampling theorem verification.

15. Removal of noise by auto correlation/cross correlation.

16. Extraction of periodic signal masked by noise using Correlation.

17. Verification of Weiner-Khinchine relations.

18. Checking a random process for stationarity in wide sense.

Geethanjali College of Engineering & Technology Page 2

Page 4: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

II . Additional Experiments:

19. To find the mean and variance of discrete random variable.

20. To find a moment generating function of a discrete random variable.

III . Design experiments:

21. To Design Half wave rectifier

22. To Design Zener break down characteristics

IV . Open experiments:

23. Implementation of Decimation Process. 24. Implementation of Interpolation Process.

Geethanjali College of Engineering & Technology Page 3

Page 5: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

GEETHANJALI COLLEGE OF ENGINEERING ANDECHNOLOGY DEPARTMENT OF Electronics and Communication Engineering

(Name of the LAB) : Basic Simulation LabProgramme : UG

Branch: ECE Version No : 03Year: II Updated on :10/06/2015Semester: I No.of pages :86Classification status (Unrestricted / Restricted )Distribution List :

Prepared by : 1) Name :Dr.P.Sri Hari 1) Name :

2) Sign : 2) Sign :3) Design :Professor 3) Design : Assoc.Prof4) Date : 01-06-2015 4) Date : 30/06/2014

Verified by :

1) Name :L.Kavya2) Sign :3) Design :

Date:07/07/2014

* For Q.C Only:

1) Name:S.Vijayalakshmi

2) Sign:

3) Design:

4) Date:07/08/2014Approved By: 1) Name : Dr.P.Sri Hari

2)Designation: HOD-ECE 3)Sign : 4)Date :

Geethanjali College of Engineering & Technology Page 4

Page 6: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

ECE DEPARTMENT

Vision of the Department

To impart quality technical education in Electronics and Communication Engineering

emphasizing analysis, design/synthesis and evaluation of hardware/embedded software

using various Electronic Design Automation (EDA) tools with accent on creativity,

innovation and research thereby producing competent engineers who can meet global

challenges with societal commitment.

Mission of the Department

i. To impart quality education in fundamentals of basic sciences, mathematics,

electronics and communication engineering through innovative teaching-learning

processes.

ii. To facilitate Graduates define, design, and solve engineering problems in the field of

Electronics and Communication Engineering using various Electronic Design

Automation (EDA) tools.

iii. To encourage research culture among faculty and students thereby facilitating them to

be creative and innovative through constant interaction with R & D organizations and

Industry.

iv. To inculcate teamwork, imbibe leadership qualities, professional ethics and social responsibilities in students and faculty.

Program Educational Objectives of B. Tech (ECE) Program:

I. To prepare students with excellent comprehension of basic sciences, mathematics

and engineering subjects facilitating them to gain employment or pursue

postgraduate studies with an appreciation for lifelong learning.

II. To train students with problem solving capabilities such as analysis and design

with adequate practical skills wherein they demonstrate creativity and innovation

that would enable them to develop state of the art equipment and technologies of

multidisciplinary nature for societal development.

III. To inculcate positive attitude, professional ethics, effective communication and

interpersonal skills which would facilitate them to succeed in the chosen

profession exhibiting creativity and innovation through research and development

both as team member and as well as leader.

Geethanjali College of Engineering & Technology Page 5

Page 7: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Program Outcomes of B.Tech ECE Program:

1. An ability to apply knowledge of Mathematics, Science, and Engineering to solve

complex engineering problems of Electronics and Communication Engineering

systems.

2. An ability to model, simulate and design Electronics and Communication

Engineering systems, conduct experiments, as well as analyze and interpret data

and prepare a report with conclusions.

3. An ability to design an Electronics and Communication Engineering system,

component, or process to meet desired needs within the realistic constraints such

as economic, environmental, social, political, ethical, health and safety,

manufacturability and sustainability.

4. An ability to function on multidisciplinary teams involving interpersonal skills.

5. An ability to identify, formulate and solve engineering problems of

multidisciplinary nature.

6. An understanding of professional and ethical responsibilities involved in the

practice of Electronics and Communication Engineering profession.

7. An ability to communicate effectively with a range of audience on complex

engineering problems of multidisciplinary nature both in oral and written form.

8. The broad education necessary to understand the impact of engineering solutions

in a global, economic, environmental and societal context.

9. A recognition of the need for, and an ability to engage in life-long learning and

acquire the capability for the same.

10. A knowledge of contemporary issues involved in the practice of Electronics and

Communication Engineering profession

11. An ability to use the techniques, skills and modern engineering tools necessary for

engineering practice.

12. An ability to use modern Electronic Design Automation (EDA) tools, software

and electronic equipment to analyze, synthesize and evaluate Electronics and

Communication Engineering systems for multidisciplinary tasks.

13. Apply engineering and project management principles to one's own work and also to manage projects of multidisciplinary nature.

Geethanjali College of Engineering & Technology Page 6

Page 8: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

INSTRUCTIONS TO THE STUDENTS :

1) Attend Laboratory in-time with formal dress and ID Card.2) Must come with completed observation and record.3) Cell-Phones are strictly prohibited in the laboratory.4) Ready for viva-voice of the completed experiments.5) Must take signature of lab-in charge on observation, after the completion of experiment on the same day.6) Completed records must sign with lab-in charge within six working days.

Programme Educational Objectives of ECE Programme:

PEO 1. Graduates will excel in professional career and/or higher education by acquiring knowledge in Mathematics, Science, Engineering principles and Computational skills.

PEO 2. Graduates will analyze real life problems, design Electronic systems appropriate to the requirement that are technically sound, economically feasible and socially acceptable in all signal processing application areas.

PEO 3.Graduates will exhibit professionalism, ethical attitude, communication skills, team work in their profession, adopt to current trends by engaging in lifelong learning and participate in Research & Development.

Programme Outcomes of ECE Programme:

PO 1. An ability to apply the knowledge of Mathematics, science and engineering in Electronics and Communications.

PO 2. An ability to Analyze signals and develop programming skills, as well as analyze & Interpret Data .

PO 3. An ability to develop a program or process to meet desired needs with in realistic constraints such as economic, environmental, social, defense, health and safety, manufacturability.

PO 4. An ability to identify different sampling rates such as multi- rate signal processing.

PO 5. An ability to Identify, Formulate & Solve problems in the areas of signal Processing Applications in Electronics and Communication Engineering.

PO 6. An understanding of professional and ethical responsibility.

PO 7. An ability to communicate effectively with satellite communication systems.

Geethanjali College of Engineering & Technology Page 7

Page 9: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

OBJECTIVES AND OUT COMES:

1. Basic operations on matrices.

Objective: To generate basic matrix of the order n/n in MATLAB and perform basic operations on matrices Using MATLAB Software.Outcome: The Students will able to understand the process of generating various Matrices and performing various operations such as addition, subtraction, multiplication on Matrices using MATLAB/SCILAB

2. Generation on various signals and Sequences (Periodic and aperiodic), Such as unit impulse, unit step, square, saw tooth, triangular, sinusoidal, ramp, sinc.

Objective: To generate different types of signals and Sequences Using MATLAB Software.Outcome: The Student able to understand how to draw different signals in MATLAB.

3. Operations on signals and sequences such as addition, Multiplication, scaling, shifting, folding, computation of Energy and Average power.

Objective: To perform arithmetic operations different types of signals Using MATLAB Software.Outcome: The Student must be able to understand how to operate signals and how to use signal operations using the properties

4. Finding the Even and Odd parts of signal/sequence and Real and imaginary part of signal.

Objective: To generate even and odd parts of signals Using MATLAB Software.

Outcome: The Student must be able to understand how to draw even and odd signals. 5. Convolution between signals and sequences.

Objective: To find the output with linear convolution operation Using MATLAB Software.Outcome: The Student must be able to understand how two signals are multiplied in time domain and the same two signals are how convolved in frequency domain Using MATLAB.

6. Auto correlation and cross correlation between signals and sequences.

Objective: To compute auto correlation and cross correlation between signals and sequences Using MATLAB Software.

Geethanjali College of Engineering & Technology Page 8

Page 10: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Outcome: The Student must be able to understand the similarity between two signals of the same and different Using MATLAB.

7. Verification of linearity and time invariance properties of a given Continuous /discrete system

Objective: To compute linearity and time invariance properties of a given continuous /discrete system.Outcome: The Student must be able to understand how to test a given signal linearity and non linearity in MATLAB.

8. Computation of unit sample, unit step and sinusoidal response of the given LTI system and verifying its physical reliability and stability properties.

Objective: To perform computation of LTI systems. Outcome: The Student must be able to understand the realization LTI systems of basic signals and sequences using MATLAB.

9. Gibbs phenomenon. Objective: To verify the Gibbs Phenomenon.Outcome: The Student must be able to understand application of Gibbs phenomenon

using MATLAB

10. Finding the Fourier transform of a given Signal and plotting its magnitude and phase spectrum.

Objective: To find the Fourier transform of a given signal and plotting its magnitude and phase spectrumOutcome: The Student must be able to understand domain transformation from time to frequency in imaginary i.e. w-plane using MATLAB.

11. Waveform synthesis using Laplace Transform.

Objective: To perform waveform synthesis using Laplace Transform of a given signal.Outcome: The Student must be able to understand the time domain to frequency domain in s-plan using MATLAB

12. Locating the zeros and poles and plotting the pole zero maps in s-plane and z-plane for the given transfer function.

Objective: To plot the zeros and poles in s-plane and z-plane for the given transfer function.Outcome: The Student must be able to understand plotting and difference between s- and z- plane plotting using MATLAB.

Geethanjali College of Engineering & Technology Page 9

Page 11: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

13. Generation of Gaussian Noise (real and complex), computation of its mean, M.S value and its Skew, Kurtosis and PSD, Probability Distribution Function.

Objective: To analyze the Gaussian density and Distribution Functions.Outcome: The Student must be able to understand the edge for single observed image using sobel edge detection and canny edge is detected.

14. Sampling theorem verification.

Objective: To verify sampling theorem.Outcome: The Student must be able to understand sampling rate changes and minimum sampling rate using MATLAB.

15. Removal of noise by auto correlation/cross correlation.

Objective: Removal of Noise by auto correlation/cross correlation.Outcome: The Student must be able to understand this experiment that the removal of noise by auto correlation/cross correlation using MATLAB.

16. Extraction of periodic signal masked by noise using correlation.

Objective: To extract a periodic signal masked by noise using correlation.

Outcome: The Student must be able to understand the experiment that the Extraction of periodic signal masked by noise using correlation using MATLAB. 17. Verification of Weiner-Khinchine relations.

Objective: To verify of Wiener– Khinchine relation.

Outcome: The Student must be able to understand the Weiner-Khinchine Relation using MATLAB. 18. Checking a random process for stationary in wide sense.

Objective: Checking a random process for stationary in wide sense.

Outcome: The Student must be able to understand the experiment of checking a random process for stationary in wide sense using MATLAB.

INTRODUCTION

Geethanjali College of Engineering & Technology Page 10

Page 12: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

The tutorials are independent of the rest of the document. The primarily objective is to help you learn quickly the first steps. The emphasis here is “learning by doing”. Therefore, the best way to learn is by trying it yourself. Working through the examples will give you a feel for the way that MATLAB operates. In this introduction we will describe how MATLAB handles simple numerical expressions and mathematical formulas.

The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to provide easy access to matrix software developed by the LINPACK (linear system package) and EISPACK (Eigen system package) projects.

MATLAB [1] is a high-performance language for technical computing. It integrates computation, visualization and programming environment. Furthermore, MATLAB is a modern programming language environment: it has sophisticateddata structures contains built-in editing and debugging tools , and supports object-oriented programming These factors make MATLAB an excellent tool for teaching and research.

MATLAB has many advantages compared to conventional computer languages (e.g., C, FORTRAN) for solving technical problems. MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. The software package has been commercially available since 1984 and is now considered as a standard tool at most universities and industries worldwide.

It has powerful built-in routines that enable a very wide variety of computations. Italso has easy to use graphics commands that make the visualization of results immediately available. Specific applications are collected in packages referred to astoolbox. There are toolboxes for signal processing, symbolic computation, control theory, simulation, optimization, and several other fields of applied science and engineering.

BASIC FEATURES

As we mentioned earlier, the following tutorial lessons are designed to get you started quickly in MATLAB. The lessons are intended to make you familiar with the basics ofWe urge you to complete the exercises given at the end of each lesson.A minimum MATLAB sessionThe goal of this minimum session (also called starting and exiting sessions) is to learn the first steps:

How to log on Invoke MATLAB Do a few simple calculations How to quit MATLAB

Starting MATLAB:After logging into your account, you can enter MATLAB by double-clicking on the MATLAB shortcut icon (MATLAB 7.0.4) on your Windows desktop. When you start MATLAB, a special window called the MATLAB desktop appears. The desktop is a

Geethanjali College of Engineering & Technology Page 11

Page 13: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

window that contains other windows. The major tools within or accessible from the desktop are:

The Command Window The Command History The Workspace The Current Directory The Help Browser

The Start button

Geethanjali College of Engineering & Technology Page 12

Page 14: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Figure 1.1: The graphical interface to the MATLAB workspaceWhen MATLAB is started for the first time, the screen looks like the one that shownin the Figure 1.1. This illustration also shows the default configuration of the MATLAB desktop. You can customize the arrangement of tools and documents to suit your needs.

Now, we are interested in doing some simple calculations. We will assume that you have sufficient understanding of your computer under which MATLAB is being run. You are

Geethanjali College of Engineering & Technology Page 13

Page 15: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

now faced with the MATLAB desktop on your computer, which contains the prompt (>>) in the Command Window. Usually, there are 2 types of prompt:

>> for full version EDU> for educational versionNote: To simplify the notation, we will use this prompt, >>, as a standard prompt sign,though our MATLAB version is for educational purpose.

Using MATLAB as a calculator

As an example of a simple interactive calculation, just type the expression you want toevaluate. Let’s start at the very beginning. For example, let’s suppose you want to calculate the expression, 1 + 2 × 3. You type it at the prompt command (>>) as follows,

>> 1+2*3ans = 7You will have noticed that if you do not specify an output variable, MATLAB uses adefault variable ans, short for answer, to store the results of the current calculation. Note that the variable ans is created (or overwritten, if it is already existed). To avoid this, youmay assign a value to a variable or output argument name. For example

>> x = 1+2*3x =7will result in x being given the value 1 + 2*3=7. This variable name can alwaysbe used to refer to the results of the previous computations. Therefore, computing 4result in

>> 4*xans =28.0000Before we conclude this minimum session, Table 1.1 gives the partial list of arithmeticOperators.

Basic arithmetic operatorsSymbol Operation Example

+ Addition 2 + 3 - Subtraction 2 - 3

* Multiplication 2*3 / Division 2/3

3 Quitting MATLAB

To end your MATLAB session, type quit in the Command Window, or select FileMATLAB in the desktop main menu.

Geethanjali College of Engineering & Technology Page 14

Page 16: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Getting startedAfter learning the minimum MATLAB session, we will now learn to use some additional operations.

1 Creating MATLAB variablesMATLAB variables are created with an assignment statement. The syntax of variable assignment is

variable name = a value (or an expression)

For example,

>> x = expression

where expression is a combination of numerical values, mathematical operators, variables, and function calls. On other words, expression can involve:

manual entry built-in functions user-defined functions

Overwriting variable

Once a variable has been created, it can be reassigned. In addition, if you do not wish to see the intermediate results, you can suppress the numerical output by putting a semicolon (;) at the end of the line. Then the sequence of commands looks like this:

>> t = 5;>> t = t+1

t =6Error messagesIf we enter an expression incorrectly, MATLAB will return an error message. For example, in the following, we left out the multiplication sign, *, in the following expression

>> x = 10;>> 5x??? 5x

Error: Unexpected MATLAB expression

Making corrections

Geethanjali College of Engineering & Technology Page 15

Page 17: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

To make corrections, we can, of course retype the expressions. But if the expression islengthy, we make more mistakes by typing a second time. A previously typed command can be recalled with the up-arrow key When the command is displayed at the command prompt, it can be modified if needed and executed.

Controlling the hierarchy of operations or precedence

Let’s consider the previous arithmetic operation, but now we will includeexample, 1 + 2×3 will become (1 + 2) ×3>> (1+2)*3ans =9

and, from previous example>> 1+2*3ans =7

By adding parentheses, these two expressions give di errant results: 9 and 7 The order in which MATLAB performs arithmetic operations is exactly that taught

in high school algebra courses Exponentiations are done first, followed by multiplications anddivisions, and finally by additions and subtractions. However, the standard order of precedence of arithmetic operations can be changed by inserting parentheses. For example, the result of 1 +2×3 is quite deferent than the similar expression with parentheses (1+2) ×3. The results are 7 and 9 respectively. Parentheses can always be used to overrule priority and their use is recommended in some complex expressions to avoid ambiguity.Therefore, to make the evaluation of expressions unambiguous, MATLAB has established a series of rules. The order in which the arithmetic operations are evaluated is given in Table 1.2. MATLAB arithmetic operators obey the same precedence rules as those in Hierarchy of arithmetic operations Precedence Mathematical operationsFirst The contents of all parentheses are evaluated first, starting from the innermost parentheses and working outward Second All exponentials are evaluated, working from left to right Third All multiplications and divisions are evaluated, workingfrom left to right Fourth All additions and subtractions are evaluated, startingfrom left to rightmost computer programs. For operators of equal precedence, evaluation is from left to right Now, consider another example:

???

In MATLAB, it becomes>> 1/(2+3^2)+4/5*6/7ans =0.7766.or, if parentheses are missing,>> 1/2+3^2+4/5*6/7ans =10.1857.

Geethanjali College of Engineering & Technology Page 16

Page 18: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

So here what we get: two different results. Therefore, we want to emphasize the importance of precedence rule in order to avoid ambiguity.

Controlling the appearance of floating point number

MATLAB by default displays only 4 decimals in the result of the calculations, for example -163. 6667, as shown in above examples. However, MATLAB does numerical calculations in double precision, which is 15 digits. The command format controls how the results of computations are displayed. Here are some examples of the different formats together with the resulting outputs>> format short>> x=-163.6667

If we want to see all 15 digits, we use the command format long

>> format long>> x= -1.636666666666667e+002

To return to the standard format, enter format short, or simply format There are several other formats. For more details, see the MATLAB documentation, or type help format Note - Up to now, we have let MATLAB repeat everything that we enter at the prompt (>>). Sometimes this is not quite useful, in particular when the output is pages en length. To prevent MATLAB from echoing what we type, simply enter a semicolon (;) at the end of the command. For example,

>> x=-163.6667;

and then ask about the value of x by typing,

>> x x =-163.6667Managing the workspace

The contents of the workspace persist between the executions of separate commands. There-fore, it is possible for the results of one problem to have aneect on the next one. To avoid this possibility, it is a good idea to issue a clear command at the start of each new independent calculation >> clearThe command clear or clear all removes all variables from the workspace. Thisfrees up system memory. In order to display a list of the variables currently in the memory type>> who

while, whos will give more details which include size, space allocation, and class of the variablesKeeping track of your work session

It is possible to keep track of everything done during a MATLAB session with the

Geethanjali College of Engineering & Technology Page 17

Page 19: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

diary command.

>> diary

or give a name to a created file

>> diary Filename

where Filename could be any arbitrary name you choose

The function diary is useful if you want to save a complete MATLAB session. Theysave all input and output as they appear in the MATLAB window. When you want to stop the recording, enter diary off. If you want to start recording again, enter diary on. The file that is created is a simple text file. It can be opened by an editor or a word processing program and edited to remove extraneous material, or to add your comments. You can use the function type to view the diary file or you can edit in a text editor or print. This command is useful, for example in the process of preparing a homework or lab submission.

Entering multiple statements per line

It is possible to enter multiple statements per line. Use commas (,) or semicolons (;) toEnter more than one statement at once. Commas (,) allow multiple statements per lineWithout suppressing output

>> a=7; b=cos(a), c=cash (a)b =0.6570c =548.3170

Miscellaneous commandsHere are few additional useful commands:

•To clear the Command Window, type clc•To abort a MATLAB computation, type ctrl-c• To continue a line, type . . .Getting help

To view the online documentation, select MATLAB Help from Help menu or MATLAB Help directly in the Command Window. The preferred method is to use the Help Browser. The Help Browser can be started by selecting the? icon from the desktop toolbar. On the other hand, information about any command is available by typing>> help Command

Another way to get help is to use the look for command. The look for commandeersfrom the help command. The help command searches for an exact function name match, while the look for command searches the quick summary information in each function for a match. For example, suppose that we were looking for a function to takethe inverse of a matrix. Since MATLAB does not have a function named inverse, the command help inverse will produce nothing. On the other hand, the command look for

Geethanjali College of Engineering & Technology Page 18

Page 20: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

inverse will produce detailed information, which includes the function of interest, inv

>> look for inverse

Note - At this particular time of our study, it is important to emphasize one main point.Because MATLAB is a huge program; it is impossible to cover al l the detailsof each function one by one. However, we will give you information how to get help. Here are some examples

• Use on-line help to request info on a specific function

>> help sqrt

• In the current version (MATLAB version 7), the doc function opens the on-line version of the help manual. This is very helpful for more complex commands

>> doc plot

• Use look for to find functions by keywords. The general form is

>>lookfor Function Name

*** Common Procedure to all Programs in MATLAB

1. Click on the MATLAB Icon on the desktop.

2. MATLAB window open .

3. Click on the ‘FILE’ Menu on menu bar.

4. Click on NEW M-File from the file Menu.

5. An editor window open, start typing commands.

6. Now SAVE the file in directory.

7. Then Click on DEBUG from Menu bar and Click Run.

Geethanjali College of Engineering & Technology Page 19

Page 21: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO: 1

BASIC OPERATIONS ON MATRICES

Aim: To generate matrix and perform basic operation on matrices Using MATLAB

Software.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB Software

MATLAB on Matrices

//This Program explains about various One-Dimensional array/Matrix//Operations:

//Creating a One-Dimensional Array/Vector:

//Creating a vector from a Known list of numbers:

A=input('enter the Matrix/Vector Elements')enter the Matrix/Vector ElementsA = 1. 2. 3. 4.

//Creating a vector with constant spacing by specifying the first//term, spacing and the last term:

m=input('enter the first term')q=input('enter the spacing')//Default value of q is 1n=input('enter the last term')

B=[m:q:n]enter the first termm =2enter the spacingq = 0.1000enter the last termn =4

Geethanjali College of Engineering & Technology Page 20

Page 22: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

B = column 1 to 12 2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3. 3.1 column 13 to 21 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.

//Creating a vector with constant spacing by specifying the first and the last terms, and the number of terms:

a=input('enter the first element')b=input('enter the last element')c=input('enter the number of elements')

C=linspace (a,b,c)enter the first elementa =3.enter the last element6b =6.enter the number of elements5c =5.C = 3. 3.75 4.5 5.25 6.

//creating an All Zero Vectorm=input('enter the number of terms in the vector')D=zeros(1,m)enter the number of terms in the vectorm =5.D =0. 0. 0. 0. 0.

//creating a Vector consisting of all Onesn=input('enter the number of terms in the vector')E=ones(1,n)enter the number of terms in the vector6n =6.E =1. 1. 1. 1. 1. 1.

//Measuring the size(number of elements) of the vectorA=[1 2 3 4]l=length(A)A =1. 2. 3. 4.l = 4.

//Measuring the order of the vectorD=[1 1 1 1 1]

Geethanjali College of Engineering & Technology Page 21

Page 23: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

p=size(D)D =1. 1. 1. 1. 1.p =1. 5.disp('The number of rows is')The number of rows is disp(p(1)) 1. disp('The number of columns is')The number of columns is disp(p(2)) 5.

//Transpose of a MatrixA=[1 2 3 4]A1=A'A = 1. 2. 3. 4.A1 = 1. 2. 3. 4.

//Multiplying each element of the vector/Matrix with a constantk=input('enter the value of the Multiplying Constant')B=[3 4 5 6]

B1=k*Bk =3.B =3. 4. 5. 6.B1 =9. 12. 15. 18.%The above Multiplication operation can be done also as follows:B11=k.*B

//Finding the sum of elements of a MatrixA=[1 2.1 3.3 4]S=sum(A)A =1. 2.1 3.3 4.S =10.4B = 1. 2. 3. 4. 5. 6. 7. 8. 9. S1=sum(B) S1 = 45.

Geethanjali College of Engineering & Technology Page 22

Page 24: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//Finding the sum of each row and displaying in a columnS2=sum(B, 'c') S2 = 6. 15. 24.

//Finding the sum of each column and displaying in a rowS3=sum(B, 'r') S3 = 12. 15. 18.

//Finding the average of the elements of MatrixB=[2 3 4 5]Ave=mean(B)B =2. 3. 4. 5.Ave =3.5

//Finding the maximum and minimum values of a vectorA=[1 2 3 10.1 -1]A1=max(A)A2=min(A) A =1. 2. 3. 10.1 - 1. A1 =10.1A2= -1

//Finding the product of the elements of a MatrixA=[1 2 3 4]P=prod(A)A =1. 2. 3. 4.P =24.

//Checking the sign of the elements of a MatrixB=[-1 -2 3 4 -5 0]S=sign(B)//sign(B) returns 1 if the element of B is +ve, -1 if the element is –ve and zero if the element is zeroB = - 1. - 2. 3. 4. - 5. 0. S = - 1. - 1. 1. 1. - 1. 0.

//Finding the non zero elements of the MatrixA=[-1 2 0 0 2 3]S=find(A)//find(A) returns the indices of the non- zero elements of A A = -1. 2. 0. 0. 2. 3.S =1. 2. 5. 6.

Geethanjali College of Engineering & Technology Page 23

Page 25: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//Arranging the elements of a Matrix in ascending/descending orderA=[1 23 45 6 73]A1=gsort(A,’r’)A =1. 23. 45. 6. 73.A1 =1. 6. 23. 45. 73.

//mtlb_sort(A) also will do the sameA2=sort(A, ’c’)A1 = 73. 45. 23. 6. 1.

//Reshaping the MatrixA=[1 2 3 4]A1=matrix(A,4,1)A2=A(:)A3=matrix(A,2,2)A =1. 2. 3. 4.A1 =A2= 1. 2. 3. 4.A3 = 1. 3. 2. 4.

//Extending the Dimension of the MatrixA=[1 2 3]//Appending a RowA(2,:)=[4 5 6]A =1. 2. 3.A =1. 2. 3. 4. 5. 6.//Appending a ColumnA=[1 2 3]A(:,4)= 10A = 1. 2. 3. 10.

//Deleting the elements of a MatrixA=[1 2 3 4]A =1. 2. 3. 4.//Deleting the 4th column elementA(4)=[ ]A =1. 2. 3.

//Arithmetic operations//Addition of Two row matricesA=[1 2 3]B=[5 6 7]

Geethanjali College of Engineering & Technology Page 24

Page 26: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

S=A+BD=A-BA =1. 2. 3.B =5. 6. 7.S =6. 8. 10.D = -4. -4. -4.//Multiplication of Two MatricesA=[1 2 3]B=[2;3;4]C=A*B A =1. 2. 3.B = 2. 3. 4.C =20//Element wise MultiplicationA=[1 2 3]B=[3 4 5]C=A.*B A =1. 2. 3.B =3. 4. 5.C =3. 8. 15.//Element wise DivisionA=[1 2 3]B=[3 4 5]C=A./B A =1. 2. 3.B =4. 4. 6.C =0.25 0.4 0.5C1=A.\BC1=3. 2. 1.6666667//Raising each element of the matrix to 3rd powerA=[2 5 8]B=A.^3A =2. 5. 8.B =8. 125. 512.

//Relational OperatorsA=[1 2 3]B=[5 3 1]K=A>BK1=A<BA =1. 2. 3.B =5. 3. 1.K = F F TK1=T T F

A=[1 2 3]

Geethanjali College of Engineering & Technology Page 25

Page 27: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

B=[1 3 3]K=A<=BK1=A>=BK2=A==BA =1. 2. 3.B =1. 3. 3.K = T T TK1=T F TK2=T F T

A=[1 2 3]B=[1 3 3]K=A~=B( not equal to)A = 1. 2. 3. B = 1. 3. 3. K = F T F

//Logical OperatorsA=[1 2 3]B=[2 0 4]K=A|BK1=A&BA =1. 2. 3.B =2. 0. 4.x =T T Ty =T F T

A=[1 0 3]K=~AA=1. 0. 3.K =F T F

//These Programs explain various (MxN) Matrix Operations://Creating a One-Dimensional Array/Vector:

A=input('enter the Matrix Elements')enter the Matrix Elements[1 2 3;4 5 6;7 8 9]A = 1. 2. 3. 4. 5. 6. 7. 8. 9.//creating a Matrix consisting of all zerosA=zeros(3,2)A = 0. 0. 0. 0.

Geethanjali College of Engineering & Technology Page 26

Page 28: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

0. 0.

//creating a Matrix consisting of all OnesB=ones(4,2)B = 1. 1. 1. 1. 1. 1. 1. 1.//Creating an Identity MatrixA=eye(3,3)A = 1. 0. 0. 0. 1. 0. 0. 0. 1.

//Measuring the order of the vectorA=[1 2 3;4 5 6;2 3 -1]p=size(A)A = 1. 2. 3. 4. 5. 6. 2. 3. -1. p= 3. 3.disp('The number of rows is')The number of rows is disp(p(1)) 3.disp('The number of columns is')The number of columns is disp(p(2)) 3.

//Transpose of a MatrixA=[1 2 3 ;10 11 12; 34 45 89]A1=A'A = 1. 2. 3. 10. 11. 12. 34. 45. 89.A1 = 1. 10. 34. 2. 11. 45. 3. 12. 89.//Multiplying each element of the Matrix with a constantk=input('enter the value of the Multiplying Constant')B=[3 4 5 6;2 4 6 8]B1=k*Benter the value of the Multiplying Constant

Geethanjali College of Engineering & Technology Page 27

Page 29: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

k =4B = 3. 4. 5. 6. 2. 4. 6. 8.B1 = 12. 16. 20. 24. 8. 16. 24. 32.//The above Multiplication operation can be done also as follows:B11=k.*B

//Finding the sum of element of a MatrixA=[1 2 ;3 4;5 6]S=sum(A)A = 1. 2. 3. 4. 5. 6.S =21.

//Finding the average of the elements of MatrixB=[2 3 4;4 5 6]Ave=mean(B)B = 2. 3. 4. 4. 5. 6.Ave = 4.

//Finding the maximum and minimum values of a vectorA=[1 2 3; 10 2 -1]A1=max(A)A2=min(A) P=prod(A)A = 1. 2. 3. 10. 2. -1.A1 =10.A2 = -1.P = -120. %Checking the sign of the elements of a MatrixB=[-1 -2 3;4 -5 0]S=sign(B)//sign(B) returns 1 if the element of B is +ve, -1 if the element is –ve and zero if the element is zeroB =

Geethanjali College of Engineering & Technology Page 28

Page 30: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

-1. -2. 3. 4. -5. 0.S = -1. -1. 1. 1. -1. 0.//Finding the non zero elements of the MatrixA=[-1 2 0; 0 2 3]S=find(A)//find(A) returns the indices of the non- zero elements of A

A = -1. 2. 0. 0. 2. 3.S = 1. 3. 4. 6.// checking a matrix whether is empty or notA=[1 2 3 0]K= isempty(A)//isempty() returns a true value for an empty matrix A = 1. 2. 3. 0. K = F //Arranging the elements of a Matrix in ascending/descending orderA=[1 23 45; 6 7 3]A1=gsort(A,’r’)//each column of A is sortedA = 1. 23. 45. 6. 7. 3.A1 = 6. 23. 45. 1. 7. 3. A1=gsort(A, ’c’)//each row of A is sortedA1= 45. 23. 1. 7. 6. 3. A1=gsort(A,'g','i')//all the elements of A are sorted in increasing order A1 = 1. 6. 23. 3. 7. 45.A1=gsort(A,'g','d')// all the elements of A are sorted in decreasing order A1 = 45. 7. 3. 23. 6. 1.

Geethanjali College of Engineering & Technology Page 29

Page 31: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//Reshaping the MatrixA=[1 2 3 4;3 5 6 7]A1=matrix(A,4,2)A2=matrix(A,1,8)A = 1. 2. 3. 4. 3. 5. 6. 7.

A1 = 1. 3. 3. 6. 2. 4. 5. 7.A2 = 1. 3. 2. 5. 3. 6. 4. 7.//Extending the Dimension of the MatrixA=[1 2 3;4 5 6]//Appending a RowA(3,:)=[10 15 26] A= 1. 2. 3. 4. 5. 6. A = 1. 2. 3. 4. 5. 6. 10. 15. 26.//Appending a ColumnA(:,4)=[10;20;87]A= 1. 2. 3. 10. 4. 5. 6. 20. 10. 15. 26. 87.

//Appending an Intermediate row A=[1 2 3;4 5 6;7 8 9]A = 1. 2. 3. 4. 5. 6. 7. 8. 9.//Appending a row between 1st and 2nd rowsA=[A(1,:); 10 11 12;A(2,:);A(3,:)]A = 1. 2. 3. 10. 11. 12. 4. 5. 6. 7. 8. 9.//Appending a column between 2nd and 3rd columnA=[A(:,1) A(:,2) [10;12;15;16] A(:,3)]A = 1. 2. 10. 3.

Geethanjali College of Engineering & Technology Page 30

Page 32: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

10. 11. 12. 12. 4. 5. 15. 6. 7. 8. 16. 9.

//Deleting the row/column of a MatrixA=[1 2 3; 4 5 6]//Deleting the 2nd row A(2,:)=[ ]A = 1. 2. 3. 4. 5. 6.A = 1. 2. 3.//Deleting the 2nd columnA=[1 2 3; 4 5 6]A(:,2)=[ ]A = 1. 2. 3. 4. 5. 6.A =

1. 3. 4. 6.

//Arithmetic operations//Addition of Two row matricesA=[1 2 3;4 5 6]B=[5 6 7;10 11 12]S=A+BD=A-B

A = 1. 2. 3. 4. 5. 6.B = 5. 6. 7. 10. 11. 12.S = 6. 8. 10. 14. 16. 18.D = -4. -4. -4. -6. -6. -6.//Multiplication of Two MatricesA=[1 2 3;4 5 6]B=[5 6 3;10 11 12;3 4 6]C=A*BA =

Geethanjali College of Engineering & Technology Page 31

Page 33: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

1. 2. 3. 4. 5. 6.

B = 5. 6. 3. 10. 11. 12. 3. 4. 6.C = 34. 40. 45. 88. 103. 108. //Element wise MultiplicationA=[1 2 3;4 5 6]B=[3 4 5;3 2 1]C=A.*B A = 1. 2. 3. 4. 5. 6.B = 3. 4. 5. 3. 2. 1.C = 3. 8. 15. 12. 10. 6.//Element wise DivisionC=A./B C = 0.3333 0.5000 0.6000 1.3333 2.5000 6.0000

//Raising each element of the matrix to 4th powerA=[2 5 8;4 5 6]B=A.^4A = 2. 5. 8. 4. 5. 6.B = 16. 625. 4096. 256. 625. 1296.

//Relational OperatorsA=[1 2 3;10 3 5]B=[5 3 1;0 3 6]K=A>Bx=A<By=A<=BK1=A>=BK2=A==BK3=A~=B

Geethanjali College of Engineering & Technology Page 32

Page 34: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

A = 1. 2. 3. 10. 3. 5.B = 5. 3. 1. 0. 3. 6.

K = F F T T F Fx = T T F F F Ty = T T F F T TK1 = F F T T T FK2 = F F F F T F K3 = T T T T F T //Logical OperatorsA=[1 2 3;0 0 1;1 -1 0]B=[2 0 4;-1 2 -3;9 8 0]K=A|BK1=A&BA = 1. 2. 3. 0. 0. 1. 1. -1. 0.B = 2. 0. 4. -1. 2. -3. 9. 8. 0.K = T T T T T T T T F K1 = T F T F F T T T FA=[1 0 3;2 -1 0;3 2 -1]K=~A/k=not(A)A =

Geethanjali College of Engineering & Technology Page 33

Page 35: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

1 0 3 2 -1 0 3 2 -1K = F T F F F T F F F

Viva Questions:

1. Create a 3x4 Matrix and append a (i) row and (ii) column to the matrix

2. Create a 4x4 matrix and change its dimensions in to (i) 16x1 (ii)2x8 (iii) 8x2

3. Create a 5x6 Matrix and (i) find the number of elements of the matrix (ii) address all the elements of 4th column (iii) address all the elements of the 3rd row.

Geethanjali College of Engineering & Technology Page 34

Page 36: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO: 2

GENERATION ON VARIOUS SIGNALS AND SEQUENCES(PERIODIC AND APERIODIC), SUCH AS UNIT IMPULSE, UNIT STEP,

SQUARE, SAWTOOTH, TRIANGULAR, SINUSOIDAL, RAMP, SINC.

Aim: To generate different types of signals Using MATLAB Software.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB Software

THEORY If the amplitude of the signal is defined at every instant of time then it is called continuous signal. If the amplitude of the signal is defined at only at some instants of time then, it is called discrete signal. If the signal repeats itself at regular intervals of time, then it is called periodic signal. Otherwise,they are called aperiodic signals.

UNIT IMPULSE: a) Continous signal:

And

Also called unit impulse function.The value of delta function can also be defined in the sense of generalized function

f(t): Test Function

b) Unit Sample sequence: δ(n)= 1, n=0 0, n≠0i.e

Geethanjali College of Engineering & Technology Page 35

Page 37: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//Plotting an Unit Impulse Function

//This program plots unit Impulse function bounded between n1 and n2

n1=input('enter the value of n1')

n2=input('enter the value of n2')

t=[n1:n2];

i=find(t==0);

x=zeros(1,length(t));

x(i)=1;

plot2d3(t, x, style=4,rect=[-6 0 6 2])

xlabel('time')

ylabel('Stength')

legend('Delta function')

title('Plotting an unit impulse function')

xgrid

(OR)

n1=input('enter the value of n1')

n2=input('enter the value of n2')

t=[n1:n2];

x=zeros(1,length(t));

i=find(t==0);

x(i)=1;

plot2d3(t, x, style=5,rect=[-6 0 6 2])

xtitle("plot of an unit impulse", "time", "strength")

xgrid

legend('Delta function')

Geethanjali College of Engineering & Technology Page 36

Page 38: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2)Unit Step Function u(t):

b)Unit Step Sequence u(n): )=1, n ≥ 0 0, n < 0

fs=input('enter the sampling frequency')

Geethanjali College of Engineering & Technology Page 37

Page 39: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

T=1/fs;

t=-1*T:T/fs: T;

x=zeros(1,length(t));

i=find(t==0);

x(i:length(x))=1;

plot2d2(t, x, style=5,rect=[-T 0 1.5*T 2])

xtitle("plot Unit Step Signal fs=500", "time", "amplitude")

xgrid

legend(' Unit Step Signal')

\

//This Program generates a Unit Step Sequence

fs=input('enter the sampling frequency')

T=1/fs;

t=-1*T:T/fs: T;

x=zeros(1,length(t));

i=find(t==0);

Geethanjali College of Engineering & Technology Page 38

Page 40: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

x(i:length(x))=1;

plot2d3(t, x, style=5,rect=[-T 0 1.5*T 2])

xtitle("plot Unit Step sequence fs=10", "time", "amplitude")

xgrid

legend(' Unit Step Sequence')

Square waves:Like sine waves, square waves are described in terms of period, frequency and amplitude:

//This Program generates a Square Wave

fs=input('enter the sampling frequency')T=1/fs;c=input('enter the number of cycles to be plotted')t=0:T/fs:T;x=zeros(1,length(t));if modulo(length(t),2)==0 for i=1:length(t)/2 x(i)=1;

Geethanjali College of Engineering & Technology Page 39

Page 41: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

x(i+length(t)/2)=-1; end else for i=1:(length(t)-1)/2 x(i)=1; x(i+(length(t)-1)/2)=-1; x(length(t))=-1; end endt1=0:T/fs:c*T;y=x;x(1)=[];for i=1:c-1 y=[y x]endplot2d1(t1,y,style=5,rect=[0 -2 max(t1) 2])xtitle("",'time','amplitude')xgridlegend('Symmetrical square pulse/wave with fs=1000, No.of cycles=3')

SAW TOOTH:

It is defined as x(t)=t for 0<t<T; =0 elsewhere.

Geethanjali College of Engineering & Technology Page 40

Page 42: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program generates a Saw tooth pulse

fs=input('enter the value of sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));c=input('enter the duration of the pulse interms of number of time instances to be included')for i=2:c p(i)=p(i-1)+1;end plot2d1(t,p,style=5,rect=[0 0 T max(p)+100])xtitle("plot of sawtooth pulse;fs=1000; c=500", "time", "amplitude")legend('Sawtooth Pulse ')

//This program generates a Discrete Saw tooth pulse

fs=input('enter the value of sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));c=input('enter the duration of the pulse in terms of number of time instances to be included')for i=2:c p(i)=p(i-1)+1;

Geethanjali College of Engineering & Technology Page 41

Page 43: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

end plot2d3(t,p,style=-4,rect=[0 0 T max(p)+10])xtitle("plot of Discrete sawtooth pulse;fs=100; c=50", "time", "amplitude")legend(‘discrete sawtooth pulse’)

//This program generates Saw tooth pulse Train

fs=input('enter the value of sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));k=input('enter the number of cycles to be plotted')c=input('enter the duration of the pulse interms of number of time instances to be included')for i=2:c p(i)=p(i-1)+1;end t1=0:T/fs:k*T;p1=zeros(1,length(t1));p1(1:length(p)-1)=p(1:length(p)-1);p(1)=[];for i=1:k-1 p1(i*length(p)+2:(i+1)*length(p)+1)=p endplot2d1(t1,p1,style=5,rect=[0 0 k*T max(p)+1])xtitle("plot of Sawtooth pulse Train;fs=100; c=50; 3 cycles", "time", "amplitude")legend('Sawtooth Pulse Train')

Geethanjali College of Engineering & Technology Page 42

Page 44: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program generates Discrete Saw tooth pulse Train

s=input('enter the value of sampling frequency')k=input('enter the number of cycles to be plotted')T=1/fs;t=0:T/fs:k*T;p=zeros(1,length(t));x=length(t);disp(x)c=input('enter the duration of the pulse in each cycle interms of number of time instances to be included such that k.c<x')for i=1:k for j=2+(i-1)*c:(i-1)*c+c p(j)=p(j-1)+1; endendplot2d3(t,p,style=-4,rect=[0 0 k*T max(p)+1])xtitle("plot of Discrete Sawtooth pulse Train;fs=10; c=100; 3 cycles", "time", "amplitude")legend('Discrete Sawtooth Pulse Train')

Geethanjali College of Engineering & Technology Page 43

Page 45: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Triangle wave:

//This program generates a Triangular Pulse

fs=input('enter the sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));for i=2:((length(t)-1)/2)+1 p(i)=p(i-1)+1; p(length(t)-(i-1))=p(i);end

Geethanjali College of Engineering & Technology Page 44

Page 46: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

plot2d1(t,p,style=5,rect=[0 0 T max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")xgridlegend('Triangular Pulse')

//This program generates a Discrete Triangular Pulse

fs=input('enter the sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));for i=2:((length(t)-1)/2)+1 p(i)=p(i-1)+1; p(length(t)-(i-1))=p(i);endplot2d3(t, p, style=-4,rect=[0 0 T max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")legend('Triangular Pulse'

Geethanjali College of Engineering & Technology Page 45

Page 47: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program generates a Triangular Pulse Train

fs=input('enter the sampling frequency')k=input('enter the number of cycles to be plotted')T=k/fs;t=0:T/fs:T;p=zeros(1,length(t));for i=2:((length(t)-1)/2)+1 p(i)=p(i-1)+1; p(length(t)-(i-1))=p(i);endt1=0:T/fs:k*T;p1=zeros(1,length(t1));p1(1:length(p)-1)=p(1:length(p)-1);p(1)=[];for i=1:k-1 p1(i*length(p)+2:(i+1)*length(p)+1)=p endplot2d1(t1,p1,style=5,rect=[0 0 k*T max(p)+1])xtitle("plot of triangular pulse Train;fs=10;3 cycles", "time", "amplitude")xgridlegend('Triangular Pulse Train')

Geethanjali College of Engineering & Technology Page 46

Page 48: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program generates a Discrete Triangular Pulse Train

fs=input('enter the sampling frequency')k=input('enter the number of cycles to be plotted')T=k/fs;t=0:T/fs:T;p=zeros(1,length(t));for i=2:((length(t)-1)/2)+1 p(i)=p(i-1)+1; p(length(t)-(i-1))=p(i);endt1=0:T/fs:k*T;p1=zeros(1,length(t1));p1(1:length(p)-1)=p(1:length(p)-1);p(1)=[];for i=1:k-1 p1(i*length(p)+2:(i+1)*length(p)+1)=p endplot2d3(t1,p1,style=5,rect=[0 0 k*T max(p)+1])xtitle("plot of triangular pulse Train;fs=10;3 cycles", "time", "amplitude")xgridlegend('Triangular Pulse Train')

Geethanjali College of Engineering & Technology Page 47

Page 49: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Ramp Signal: It is defined as x(t)=t for t≥0 = 0 elsewhere

//This program generates ramp Signalt=0:0.1:1;x=0;for i=2:length(t) x(i)=x(i-1)+2;endplot2d1(t, x, style=5,rect=[0 0 max(t) max(x)])xgridxtitle("plot of Ramp Signal", "time", "amplitude")

Geethanjali College of Engineering & Technology Page 48

Page 50: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

legend(' Ramp Signal ')

//This program generates discrete ramp signal

t=0:0.1:1;x=0;for i=2:length(t) x(i)=x(i-1)+2;endplot2d3(t, x, style=-4,rect=[0 0 max(t) max(x)])xgridxtitle("plot of Discrete Ramp Signal", "time", "amplitude")legend(' Discrete Ramp Signal ')

Geethanjali College of Engineering & Technology Page 49

Page 51: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Sinusoidal Signal Generation

The sine wave or sinusoid is a mathematical function that describes a smooth repetitive oscillation. Its most basic form as a function of time (t) is x(t)=A.sin(wt+φ)

where:

A, the amplitude, is the peak deviation of the function from its center position. ω, the angular frequency, specifies how many oscillations occur in a unit time

interval, in radians per second φ, the phase, specifies where in its cycle the oscillation begins at t = 0.

//This program generates a Sinusoidal Pulse/Sinusoidal Pulse

Train

f=input('enter the frequency of the signal')

i=input('enter the no. of cycles to be plotted')

T=i/f;

t=0:T/f:T;

x=sin(2*%pi*f*t);

plot2d1(t, x, style=5,rect=[0 -2 T 2])

xtitle("plot of an sinusoidal pulse Train fs=1000,i=3", "time",

"amplitude")

xgrid

legend(' Sinusoidal Pulse Train')

Geethanjali College of Engineering & Technology Page 50

Page 52: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program generates a Discrete Sinusoidal Pulse /

Discrete Sinusoidal Pulse Train

f=input('enter the frequency of the signal');

i=input('enter the no.of cycles to be plotted')

T=i/f;

t=0:T/f:T;

x=sin(2*%pi*f*t);

plot2d3(t, x, style=5,rect=[0 -2 T 2])

xtitle("plot of Discrete sinusoidal pulse Train fs=50,i=2", "time",

"amplitude")

xgrid

legend(' Discrete Sinusoidal Pulse Train')

Geethanjali College of Engineering & Technology Page 51

Page 53: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

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 2π and height 1. The following equation defines the sinc function:

The sinc function has a value of 1 when x is equal to zero.

//This program generates sinc waveform

f=input('enter the frequency')i=input('enter the number of cycles to be plotted')T=i/f;t=-T:T/f:T;i=find(t==0);x1=sin(2*%pi*f*t);x1(i)=1;

Geethanjali College of Engineering & Technology Page 52

Page 54: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

x2=2*%pi*f*t;x2(i)=1;x=x1./x2; plot2d1(t,x,style=-4,rect=[-T -max(x)-0.5 T max(x)+0.5])xgridxtitle("plot of sampling function f=500 ; 5 cycles", "time", "amplitude")legend(' Sampling Function ')

CONCLUSION: In this experiment, various basic signals are generated.

Exersize questions:Generate the following signals:

1.x(t)=e-t

2.x(t)= t 2 / 2

3. Rectangular Pulse

4. signum function sgn(t)= 1 t > 0

0 t=0

-1 t<0

5.Complex exponential signal x(t)= exp(-jwt)

Geethanjali College of Engineering & Technology Page 53

Page 55: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

VIVA QUESTIONS1. What is a singular Function2. Define deterministic and Random Signal3. Define Delta Function4. Define Periodic and Aperiodic Signal5. Explain about sifting property of Impulse function.

EXP.NO: 3

Geethanjali College of Engineering & Technology Page 54

Page 56: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

OPERATIONS ON SIGNALS AND SEQUENCES SUCH AS ADDITION, MULTIPLICATION, SCALING, SHIFTING, FOLDING, COMPUTATION OF ENERGY AND AVERAGE POWER

Aim: To perform arithmetic operations different types of signals Using MATLAB

Software.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB Software

Basic Operation on Signals:

Time Shifting :

1.//This function generates the Advanced/Delayed unit

impulse

function

n1=input('enter the value of n1<0')n2=input('enter the value of n2>0')n=input('enter the value of n lying between n1 and n2 and not equal to zero')t=[n1:n2];x=zeros(1,length(t));y=x;i=find(t==0);x(i)=1;i=find(t==n);y(i)=1; subplot(2,1,1)plot2d3(t,x,style=-4,rect=[n1 0 n2 2])xtitle("", "time", "amplitude")legend('Unit Impulse function') subplot(2,1,2)plot2d3(t,y,style=-4,rect=[n1 0 n2 2])xtitle("", "time", "amplitude")if n>0 legend('Delayed Unit Impulse by 3 units')elselegend('Advanced Unit Impulse by 3 units ') end

Geethanjali College of Engineering & Technology Page 55

Page 57: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Geethanjali College of Engineering & Technology Page 56

Page 58: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2.//This Program generates a shifted Unit Step Signalfs=input('enter the sampling frequency')T=1/fs;t=-1*T:T/fs:T;x=zeros(1,length(t));x1=x;x2=x;i=find(t==0);x(i:length(x))=1;k=input('enter the amount of positive shift required in between -T and +T')i=find(t==k);x1(i:length(x))=1;j=input('enter the amount of negative shift required in between -T and +T')i=find(t==j);x2(i:length(x))=1;subplot(3,1,1)plot2d1(t,x,style=2,rect=[-T 0 T 2])xtitle("", "time", "amplitude")legend('Unit Step signal with fs=1000') subplot(3,1,2)plot2d1(t,x1,style=2,rect=[-T 0 T 2])xtitle("", "time", "amplitude")legend('Unit Step sgnal delayed by 0.0005sec')subplot(3,1,3)plot2d1(t,x2,style=2,rect=[-T 0 T 2])xtitle("", "time", "amplitude")legend('Unit Step sgnal advanced by 0.0005sec')

Geethanjali College of Engineering & Technology Page 57

Page 59: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

3.//This program generates a shifted sinusoidal pulse

f=input('enter the sampling frequency')T=1/ft=0:T/f:T;x=sin(2*%pi*f*t);b= input('select a value for b which is greater than one')t1=-1*b*T:T/f:b*T;p=zeros(1,length(t1));q=p;i=find(t1==0);p(i:i+length(t)-1)=x;k=input('enter the amount of shift required which is bounded by -b.T and +b.T')j=find(t1==k)q(j:j+length(t)-1)=x;if k<0subplot(2,1,1)plot2d1(t1,p,style=2,rect=[min(t1),min(p),max(t1),max(p)])xtitle("", "time", "amplitude")legend('sinusoidal pulse with f=500,b=2') subplot(2,1,2)plot2d1(t1,q,style=2,rect=[min(t1),min(p),max(t1),max(p)])xtitle("", "time", "amplitude")legend('sinusoidal pulse advanced by 0.002sec')

Geethanjali College of Engineering & Technology Page 58

Page 60: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

elsesubplot(2,1,1)plot2d1(t1,p,style=2,rect=[min(t1),min(p),max(t1),max(p)])xtitle("", "time", "amplitude")legend('sinusoidal pulse with f=500,b=2') subplot(2,1,2)plot2d1(t1,q,style=2,rect=[min(t1),min(p),max(t1),max(p)])xtitle("", "time", "amplitude")legend('sinusoidal pulse delayed by 0.002sec')end

Geethanjali College of Engineering & Technology Page 59

Page 61: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Signal Addition and Multiplication :

Addition: any two signals can be added to form a third signal,

z (t) = x (t) + y (t)

1.//This program adds two sinusoidal signals of different duration

f1=input('enter the frequency of the first signal')i=input('enter the no.of cycles of the first signal to be plotted')T1=i/f1;t1=0:T1/f1:T1;p1=sin(2*%pi*f1*t1);subplot(3,1,1)plot2d1(t1,p1,style=5,rect=[0 -max(p1)-0.5 T1 max(p1)+0.5])xtitle( "","time", "amplitude")legend('f=10 Hz, 1 cycle')f2=input('enter the frequency of the second signal');j=input('enter the no.of cycles of the second signal to be plotted')

Geethanjali College of Engineering & Technology Page 60

Page 62: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

T2=j/f2;t2=0:T2/f2:T2;p2=sin(2*%pi*f2*t2);subplot(3,1,2)plot2d1(t2,p2,style=5,rect=[0 -max(p2)-0.5 T2 max(p2)+0.5])xtitle("","time", "amplitude")legend('f=20 Hz, 2 cycles')t=[t1 t2];t=gsort(t,'g','increase')for i=2:length(t)if t(i)==t(i-1)t(i)=%piendendx=find(t==%pi);t(x(1:length(x)))=[];if length(t1)>length(t2) p=zeros(1,length(t1))for i=1:length(t1) for j=1:length(t2) if t1(i)==t2(j) p(i)=p2(j); end end endp(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)-length(p)-1),2)); p1(length(p1)+1:length(p))=0;P=p+p1;elsep=zeros(1,length(t2))for i=1:length(t2) for j=1:length(t1) if t2(i)==t1(j) p(i)=p1(j); end end endp(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)-length(p)-1),2)); p2(length(p2)+1:length(p))=0;P=p+p2; endsubplot(3,1,3)plot2d1(t,P, style=5,rect=[0 -max(P)-0.5 max(t) max(P)+0.5])xtitle("", "time", "amplitude")legend('Sum of two Sinusoidal Signals')

Geethanjali College of Engineering & Technology Page 61

Page 63: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2.//This Program adds to step signals of same duration

fs=input('enter the sampling frequency')T=1/fs;t=-1*T:T/fs: T;x1=zeros(1,length(t));x2=x1;i=find(t==0);x1(i:length(x1))=1;x2(i:length(x2))=2subplot(3,1,1)plot2d1(t, x1, style=5,rect=[-T 0 1.5*T 2])xtitle("", "time", "amplitude")xgridlegend(' Unit Step Signal with fs=500')subplot(3,1,2)plot2d1(t, x2, style=5,rect=[-T 0 1.5*T 3])xtitle("", "time", "amplitude")xgridlegend(' Step Signal height 2 and fs=500')

Geethanjali College of Engineering & Technology Page 62

Page 64: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

subplot(3,1,3)plot2d1(t, x1+x2, style=5,rect=[-T 0 1.5*T 4])xtitle("", "time", "amplitude")xgridlegend('sum of 2 Step Signals')

3.//This Program adds two Discrete Triangular pulses of

different

duration

fs1=input('enter the sampling frequency')T1=1/fs1;t1=0:T1/fs1:T1;p1=zeros(1,length(t1));for i=2:((length(t1)-1)/2)+1 p1(i)=p1(i-1)+1; p1(length(t1)-(i-1))=p1(i);endsubplot(3,1,1)plot2d3(t1, p1, style=-4,rect=[0 0 T1 max(p1)+1])xtitle("", "time", "amplitude")legend('Triangular Pulse fs=10')fs2=input('enter the sampling frequency')T2=1/fs2;t2=0:T2/fs2:T2;p2=zeros(1,length(t2));

Geethanjali College of Engineering & Technology Page 63

Page 65: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

for i=2:((length(t2)-1)/2)+1 p2(i)=p2(i-1)+1; p2(length(t2)-(i-1))=p2(i);endsubplot(3,1,2)plot2d3(t2, p2, style=-4,rect=[0 0 T2 max(p2)+1])xtitle("", "time", "amplitude")legend('Triangular Pulse fs=20')t=[t1 t2];t=gsort (t,'g', 'increase')for i=2:length(t)if t(i)==t(i-1)t(i)=%piendendx=find(t==%pi);t(x(1:length(x)))=[];if length(t1)>length(t2) p=zeros(1,length(t1))for i=1:length(t1) for j=1:length(t2) if t1(i)==t2(j) p(i)=p2(j); end end endp(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)-length(p)-1),2)); p1(length(p1)+1:length(p))=0;P=p+p1;elsep=zeros(1,length(t2))for i=1:length(t2) for j=1:length(t1) if t2(i)==t1(j) p(i)=p1(j); end end endp(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)-length(p)-1),2)); p2(length(p2)+1:length(p))=0;P=p+p2; endsubplot(3,1,3)plot2d3(t,P, style=-4,rect=[0 0 max(t) max(P)+1])xtitle("", "time", "amplitude")legend('Sum of two Triangular Pulses')

Geethanjali College of Engineering & Technology Page 64

Page 66: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Multiplication of Signals

Multiplication of two signals can be obtained by multiplying their values at every respective time instants. z (t) = x (t) .y (t)

1.//This program multiplies two discrete ramp signals of

unequal

Duration

t1=0:0.1:1;p1=zeros(1,length(t1));for i=2:length(t1) p1(i)=p1(i-1)+2;endsubplot(3,1,1)plot2d3(t1,p1,style=-3,rect=[0 0 max(t1) max(p1)])xgridxtitle ("", "time", "amplitude")legend('Discrete Ramp Signal-1 ')t2=0:0.1:2;p2=zeros(1,length(t2));for i=2:length(t2) p2(i)=p2(i-1)+2;endsubplot(3,1,2)plot2d3(t2,p2,style=-3,rect=[0 0 max(t2) max(p2)])xgridxtitle ("", "time", "amplitude")

Geethanjali College of Engineering & Technology Page 65

Page 67: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

legend('Discrete Ramp Signal-2 ')t=[t1 t2];t=gsort (t, 'g', 'increase')for i=2:length(t)if t(i)==t(i-1)t(i)=%piendendx=find(t==%pi);t(x(1:length(x)))=[ ];if length(t1)>length(t2) p=zeros(1,length(t1))for i=1:length(t1) for j=1:length(t2) if t1(i)==t2(j) p(i)=p2(j); end end endp(length(p)+1:length(t))=p2(flipdim(length(p2):-1:length(p2)-(length(t)-length(p)-1),2)); p1(length(p1)+1:length(p))=0;P=p.*p1;elsep=zeros(1,length(t2))for i=1:length(t2) for j=1:length(t1) if t2(i)==t1(j) p(i)=p1(j); end end endp(length(p)+1:length(t))=p1(flipdim(length(p1):-1:length(p1)-(length(t)-length(p)-1),2)); p2(length(p2)+1:length(p))=0;P=p.*p2; endsubplot(3,1,3)plot2d3(t, P, style=-3,rect=[0 0 max(t) max(P)])xtitle("", "time", "amplitude")legend('Product of Two ramp signals')

Geethanjali College of Engineering & Technology Page 66

Page 68: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//2.This Program multiplies two step signals of equal duration

fs=input('enter the sampling frequency')T=1/fs;t=-1*T:T/fs: T;x1=zeros(1,length(t));x2=x1;i=find(t==0);x1(i:length(x1))=2;x2(i:length(x2))=4;subplot(3,1,1)plot2d1(t, x1, style=-4,rect=[-T 0 1.5*T 3])xtitle("", "time", "amplitude")xgridlegend(' Step Signal with height 2 and fs=500')subplot(3,1,2)plot2d1(t, x2, style=-4,rect=[-T 0 1.5*T 5])xtitle("", "time", "amplitude")xgridlegend(' Step Signal with height 4 and fs=500')subplot(3,1,3)plot2d1(t, x1.*x2, style=-4,rect=[-T 0 1.5*T 10])xtitle("", "time", "amplitude")xgridlegend('Product of 2 Step Signals')

Geethanjali College of Engineering & Technology Page 67

Page 69: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Time reversal(Folding about Y-axis):Time reversal of a signal x(t) can be obtained by folding the signal about t=0 i.e. Y-axis. y(t)=x(-t)

1.//This Program generates a Unit Step Signal Folded about y-axis

fs=input('enter the sampling frequency')T=1/fs;t=-1*T:T/fs:T;x=zeros(1,length(t));i=find(t==0);x(i:length(x))=1;subplot(2,1,1)plot2d1(t,x,style=2,rect=[min(t),0,max(t),2])xtitle("", "time", "amplitude")legend('Unit Step signal with fs=1000') x=zeros(1,length(t));j=find(t==min(t));x(j:i)=1;subplot(2,1,2)plot2d1(t,x,style=2,rect=[min(t),0,max(t),2])xtitle("", "time", "amplitude")legend('Unit Step signal folded about Y-axis')

Geethanjali College of Engineering & Technology Page 68

Page 70: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2.//This program generates a saw Tooth pulse folded about y-axis

fs=input('enter the sampling frequency')T=1/fs;t= -1*T:T/fs: T;p=zeros(1,length(t));c=input('enter the number of samples to be included')i=find(t==0);for j=i+1:i+c p(j+1)=p(j)+1;endsubplot(2,1,1)plot2d1(t,p,style=2,rect=[min(t),0,max(t),max(p)+3])xtitle("", "time", "amplitude")legend('Sawtooth pulse with fs=1000, c=200')p1=zeros(1,length(t));p1(i-c:i-1)=flipdim(p(i+1:i+c),2)subplot(2,1,2)plot2d1(t,p1,style=2,rect=[min(t),0,max(t),max(p1)+3])xtitle("", "time", "amplitude")legend('Sawtooth pulse folded about Y-axis')

Geethanjali College of Engineering & Technology Page 69

Page 71: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Signal Amplification/Attuation : Y(n)=ax(n) if a < 1 attnuationa >1 amplification

% Amplitude scaling

clc;clear all;close all;t = [0:.01:1]; % independent (time) variable A = 8; % amplitude f1 = 2; % create a 2 Hz sine wave lasting 1 sec s1 = A*sin(2*pi*f1*t); subplot(3,1,1);plot(s1);xlabel('t');ylabel('amplitude');title('input signal');s2=2*s1;subplot(3,1,2);plot(s2);xlabel('t');ylabel('amplitude');title('amplified input signal');s3=s1/2;subplot(3,1,3);plot(s3);xlabel('t');ylabel('amplitude');

Geethanjali College of Engineering & Technology Page 70

Page 72: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

title('atteniated input signal');% Amplitude scaling for sequencesclc;clear all;close all;n=0:1:6;s1 = [1 2 3 3 1 1 1];subplot(3,1,1);stem(n,s1);xlabel('n');ylabel('amplitude');title('input signal');s2=4*s1;subplot(3,1,2);stem(n,s2);xlabel('t');ylabel('amplitude');title('amplified input signal');s3=s1/4;subplot(3,1,3);stem(n,s3);xlabel('t');ylabel('amplitude');title('atteniatedinput signal');

Time scalling:

The Time scalling of a signal x(t) can be accomplished by replacing t by ‘at’ where ’a’ is a scaling factor. Y(t)=x(at) ; a= arbitrary constant

If a<1 the signal y(t) is expanded x(t) If a>1 the signal y(t) is compressed x(t)1.// This program generates Time scaled version of a

Triangular

Pulse

fs=input('enter the sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));p1=p;for i=2:((length(t)-1)/2)+1 p(i)=p(i-1)+1; p(length(t)-(i-1))=p(i);endc=input('enter the scaling factor')t1=t./c;if c<1

Geethanjali College of Engineering & Technology Page 71

Page 73: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

subplot(2,1,1)plot2d1(t,p,style=1,rect=[0 0 1+T/c max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")xgridlegend('Triangular Pulse') subplot(2,1,2)plot2d1(t1,p,style=1,rect=[0 0 1+T/c max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")xgrid legend('c=0.2,Expanded Triangular Pulse')elsesubplot(2,1,1)plot2d1(t,p,style=1,rect=[0 0 T max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")xgridlegend('Triangular Pulse') subplot(2,1,2) plot2d1(t1,p,style=1,rect=[0 0 T max(p)+1])xtitle("plot of triangular pulse fs=10", "time", "amplitude")xgridlegend('c=2, Compressed Triangular Pulse')end

Geethanjali College of Engineering & Technology Page 72

Page 74: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2.// This program generates Time scaled version of a

Sawtooth

Pulse

fs=input('enter the sampling frequency')T=1/fs;t=0:T/fs:T;p=zeros(1,length(t));k=input('enter the duration of the pulse interms of number of time instances to be included')for i=2:k p(i)=p(i-1)+1;end c=input('enter the scaling factor')t1=t./c;if c<1 subplot(2,1,1)plot2d1(t,p,style=1,rect=[0 0 0.001+T/c max(p)+1])xtitle("", "time", "amplitude")xgridlegend('Sawtooth Pulse with with fs=100,k=50') subplot(2,1,2)plot2d1(t1,p,style=1,rect=[0 0 0.001+T/c max(p)+1])

Geethanjali College of Engineering & Technology Page 73

Page 75: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

xtitle("", "time", "amplitude")xgrid legend('c=0.2,Expanded Sawtooth Pulse')elsesubplot(2,1,1)plot2d1(t,p,style=1,rect=[0 0 T max(p)+1])xtitle("", "time", "amplitude")xgridlegend('Sawtooth Pulse with fs=100,k=50') subplot(2,1,2) plot2d1(t1,p,style=1,rect=[0 0 T max(p)+1])xtitle("", "time", "amplitude")xgridlegend('c=2, Compressed Triangular Pulse')end

Geethanjali College of Engineering & Technology Page 74

Page 76: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

ENERGY AND POWER SIGNA L:A signal can be categorized into energy signal or power signal:

energy signal has a finite energy, 0 < E < ∞. And Power=0

Energy signals have values only in the limited time duration.

Energy of Continuous Signals

Energy of Discrete Signals

power signal has a finite Power, 0 < P< ∞. And Energy =∞

Power of Continuous Signals

Geethanjali College of Engineering & Technology Page 75

Page 77: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Power of Discrete Signals

Computation of Energy:1.//This program generates a sinusoidal Pulse and computes its Energyf=input('enter the value of the frequency')T=1/f;t=0:T/f:T;x=(sin(2*%pi*f*t));x1=abs(x);E1=x1.*x1;E=sum(E1);plot2d3(t,x,style=2,rect=[0,-1,T,1])xtitle("", "time", "amplitude")legend('Discrete Sinusoidal Pulse with fs=10 and its energy is 5 joules')disp('Energy of the generated signal in joules is')disp(E)

Geethanjali College of Engineering & Technology Page 76

Page 78: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2.//This Program generates a rectangular pulse and finds its energy

f=input('enter the sampling frequency')T=1/f;t=-T:T/f:T;x=zeros(1,length(t));c=input('enter the duration of the rectangular pulse in therms of number of samples to included')i=find(t==0);x(i:i+c-1)=0.25;E=sum(x.*x);plot2d(t,x,style=2,rect=[-T 0 T 0.5])xtitle("", "time", "amplitude")legend('Rectangular Pulse with fs=100, c=50 and with energy=3.125 Joules')disp('Energy of the generated signal measured in joules is')disp(E)

Energy of the generated signal measured in joules is 3.125

Computation of Average Power:1.//This program generates a Periodic sinusoidal signal and computes its average powerf=input('enter the frequency of the signal');i=input('enter the no.of cycles to be plotted')T=i/f;t=0:T/f:T;x=sin(2*pi*f*t);

Geethanjali College of Engineering & Technology Page 77

Page 79: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

y=input('enter the number of cycles(<=i) over which average power is to be computed')%z is the length of one cyclez=(length(t)-1)/i;x1=abs(x);x2=x1.*x1;p=(1/(y*z))*sum(x2(1:y*z));disp('The average power of the generated signal measured in watts is ')disp(p)

CONCLUSION: In this experiment the various operations on signals have been implemented.

Exercise questions: Sketch the following questions using MATLAB1. x(t)= u(-t+1)2. x(t)=3r(t-1)3. x(t)=U(n+2-u(n-3)4. x(n)=x1(n)+x2(n)where x1(n)=1,3,2,1,x2(n)=1,-2,3,25. x(t)=r(t)-2r(t-1)+r(t-2)6. x(n)=2δ(n+2)-2δ(n-4), -5≤ n ≥5.7. X(n)=1,2,3,4,5,6,7,6,5,4,2,1 determine and plot the following sequence

a. x1(n)=2x(n-5-3x(n+4))b. x2(n)=x(3-n)+x(n)x(n-2)

VIVA QUESTIONS

1.Differentiate between Energy and Power of a signal 2.Define Continuous and Discrete Time Signals

3.Classify the following in to energy or power signals (i) x(t)=exp(-at).u(t) (ii) x(t)=u(t) (iii) x(t)=exp(at)

4.What are the Different operations performed on the independent variable of a Signal?

Geethanjali College of Engineering & Technology Page 78

Page 80: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO: 4

FINDING THE EVEN AND ODD PARTS OF SIGNAL/SEQUENCE AND REAL AND IMAGINARY PART OF SIGNAL

Aim: Program for finding even and odd parts of signal.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB/Scilab Software

THEORY :

Geethanjali College of Engineering & Technology Page 79

Page 81: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Even and Odd Signal.

Even Signal: A signal is referred to as an even if it is identical to its time-reversed counterpart; x(t) = x(-t).

Odd Signal: A signal is odd if x(t) = -x(-t). An odd signal will be 0 at t=0, in other words, odd signal passes the origin.

Even signals are symmetric around vertical axis, and Odd signals are symmetric about origin

Any signal may be decomposed into a sum of its even part, xe(t), and its odd part, xo(t), as follows:

//This program finds the even and odd part of a given sequence

1.x(n)=δ(n)+2δ(n-1)+3δ(n-2)+4δ(n-3)

x=input('enter the sequence')n=input('enter the time indices')n1=-flipdim(n,2);m=[min(n1):max(n)];x1=zeros(1,length(m));k=find(m==min(n));x1(k:length(m))=x;x2=flipdim(x1,2);xe=0.5*(x1+x2);xo=0.5*(x1-x2);subplot(3,1,1)plot2d3(n,x,style=-4,rect=[min(n)-1 min(x)-1 max(n)+1 max(x)+1])xtitle("", "time", "amplitude")legend(' The given sequence x(n)= [1 2 3 4] at n=[0 1 2 3]')xgridsubplot(3,1,2)plot2d3(m,xe,style=-4,rect=[min(m)-1 min(xe)-1 max(m)+1 max(xe)+1])xtitle("", "time", "amplitude")legend('Even part of the given sequence')xgridsubplot(3,1,3)

Geethanjali College of Engineering & Technology Page 80

Page 82: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

plot2d3(m,xo,style=-4,rect=[min(m)-1 min(xo)-1 max(m)+1 max(xo)+1])xtitle("", "time", "amplitude")legend('Odd part of the given sequence')xgrid

2.x(t)= Sin(2000πt)f=input('enter the frequency')T=1/f;t=0:T/f:T;x=sin(2*%pi*f*t);t1=-flipdim(t,2);t2=[min(t1):T/f:max(t)];x1=zeros(1,length(t2));k=find(t2==min(t));x1(k:length(t2))=x;x2=flipdim(x1,2);xe=0.5*(x1+x2);xo=0.5*(x1-x2);subplot(3,1,1)plot2d(t,x,style=-4,rect=[min(t) min(x)-0.5 max(t) max(x)+0.5])xtitle("", "time", "amplitude")xgridlegend('Sinusoidal pulse with fs=500')subplot(3,1,2)

Geethanjali College of Engineering & Technology Page 81

Page 83: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

plot2d(t2,xe,style=-4,rect=[min(t2) min(xe)-0.5 max(t2) max(xe)+0.5])xtitle("", "time", "amplitude")xgridlegend('Even part of the given sinusoidal pulse')subplot(3,1,3)plot2d(t2,xo,style=-4,rect=[min(t2) min(xo)-0.5 max(t2) max(xo)+0.5])xtitle("", "time", "amplitude")xgridlegend('Odd part of the given sinusoidal pulse')

Conclusion:The even and odd parts of signal/sequence signal are computed and plotted.

VIVA QUESTIONs.1.Define even and odd symmetry of a signal.2.Plot the even and odd parts of a unit step signal

Geethanjali College of Engineering & Technology Page 82

Page 84: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO: 5 LINEAR CONVOLUTION

Aim: To implement linear convolution of two signals/sequences.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB /Scilab Software

Theory:

Geethanjali College of Engineering & Technology Page 83

Page 85: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

If x(n)=δ(n), then output y(n) is known as impulse response of the system.y(n)=T[x(n)]==T[δ(n)]=h(n) . For a time invariant system, T[δ (n-k)]= h(n-k).x(n) can represented as weighted sum of impulses such as

For an LSI system, y(n)=T[x(n)]

=

--- Linear Convolution equation

Linear Convolution involves the following operations.1. Folding2. Multiplication3. Addition4. Shifting

These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input sequenceh[n ]= unit sample response of the system.y[ ]= Convoluted sum.

1.//This Program finds the convolution between two sequencesx=input('Enter the sequence x(n)')n1=input('Enter the time indices of x(n)')y=input('Enter the sequence y(n)')n2=input('Enter the time indices of y(n)')n=min(n1)+min(n2):max(n1)+max(n2);A=zeros(min(length(x),length(y)),length(x)+length(y)-1);if length(x)<length(y) for i=1:length(x) A(i,i:i+length(y)-1)=y(1,:); A(i,:)=x(i).*A(i,:); end

Geethanjali College of Engineering & Technology Page 84

Page 86: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

else for i=1:length(y) A(i,i:i+length(x)-1)=x(1,:); A(i,:)=y(i).*A(i,:); endendc=zeros(1,length(x)+length(y)-1);for i=1:min(length(x),length(y)) c(1,:)=c(1,:)+A(i,:);enddisp('The convolution of the given sequences is')disp(c)disp(‘ The Time index of the convolved sum is’)disp(n)subplot(3,1,1)plot2d3(n1,x,style=-4,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])xtitle("", "time", "amplitude")xgridlegend('Given sequence x(n)')subplot(3,1,2)plot2d3(n2,y,style=-4,rect=[min(n2)-1 min(y)-1 max(n2)+1 max(y)+1])xtitle("", "time", "amplitude")xgridlegend('Given sequence y(n)')subplot(3,1,3)plot2d3(n,c,style=-4,rect=[min(n)-1 min(c)-1 max(n)+1 max(c)+5])xtitle("", "time", "amplitude")xgridlegend('Convolution of x(n) and y(n)')

conv(a,b)- Returns the Convolution of two vectors “a” and “b”.

1.x(n)=δ(n)+δ(n-1)+δ(n-2) ; y(n)= δ(n)+δ(n-1)+δ(n-2)+ δ(n-3)

Enter the sequence x(n)x = 1 2 3Enter the time indices of x(n)n1= 0 1 2Enter the sequence y(n)y = 1 2 3 4

Geethanjali College of Engineering & Technology Page 85

Page 87: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

'Enter the time indices of y(n)n2=0 1 2 3

The convolution of the given sequences is1. 4. 10. 16. 17. 12.

2. Enter the sequence x(n)x = -1 2 3 -1Enter the sequence y(n) y = 2 5 4 -9The convolution of the given sequences is -2 -1 12 30 -11 -31 9The Time index of the convolved sum isn=0 1 2 3 4 5

2.//This Program finds the convolution between two rectangular Pulses of equal durationf1=input('enter the sampling frequency of the first signal')T1=1/f1;

Geethanjali College of Engineering & Technology Page 86

Page 88: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

t1=0:T1/f1:T1;x1=zeros(1,length(t1));j=input('enter the duration of the rectangular pulse in therms of number of samples to included')x1(1:j)=0.25;f2=input('enter the sampling frequency of the second signal')T2=1/f2;t2=0:T2/f2:T2;x2=zeros(1,length(t2));k=input('enter the duration of the rectangular pulse in therms of number of samples to included ') x2(1:k)=0.5;t=0:(t1(j)+t2(k))/(j+k):t1(j)+t2(k);A=zeros(min(j,k),j+k-1);if j<k for i=1:j A(i,i:i+k-1)=x2(1,1:k); A(i,:)=x1(i).*A(i,:); endelse for i=1:k A(i,i:i+j-1)=x1(1,1:j); A(i,:)=x2(i).*A(i,:); endendc=zeros(1,j+k-1);for i=1:min(j,k) c(1,:)=c(1,:)+A(i,:);endc(j+k)=0;for i=length(c)+1:length(t) c(i)=0;endsubplot(3,1,1)plot2d(t1,x1,style=5,rect=[0 min(x1) T1 max(x1)+0.5])xtitle("", "time", "amplitude")xgridlegend('Rectangular Pulse with fs=1000,j=750')subplot(3,1,2)plot2d(t2,x2,style=5,rect=[0 min(x2) T2 max(x2)+0.5])xtitle("", "time", "amplitude")xgridlegend('Rectangular Pulse with fs=1000,k=750')subplot(3,1,3)plot2d(t,c,style=5,rect=[0 0 max(t)+1000*((t1(j)+t2(k))/(j+k)) max(c)+25])xtitle("", "time", "amplitude")xgridlegend('Convolution of rectangular pulses of same duration')

Geethanjali College of Engineering & Technology Page 87

Page 89: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

3.// Convolution between two rectangular Pulses of unequal duration

Geethanjali College of Engineering & Technology Page 88

Page 90: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

CONCLUSION: In this experiment Linear convolution between signals/sequences have been implemented.

Applications: Convolution is used to obtain the response of an LTI system to an arbitrary input signal. VIVA QUESTIONS:1.Explain about the Graphical Interpreation of Convolution2. What is the result of f(t)*δ(t).3.If two sequences of length L amd M respectively are linearly convoled, what is the length of the linearly convolved sum of the two sequences?4. x(n) is extending from L to M and y(n) is extending from P to Q. Then, x(n)*y(n) extends from -------------

Exercise questions: perform convolution between the following signals 1. x(n)=[1 -1 4 ], h(n) = [ -1 2 -3 1]2 x(t)=e-3tu(t)-u(t-2) , y(t)= e -3t for 0 ≤ t ≤ 2

EXP.NO: 6

Geethanjali College of Engineering & Technology Page 89

Page 91: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

AUTO CORRELATION AND CROSS CORRELATION BETWEEN SIGNALS AND SEQUENCES.………………………………………………………………………………………………Aim: To compute auto correlation and cross correlation between signals and sequencesEQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB/Scilab Software

Theory:Correlations of sequences:

It is a measure of the degree to which two sequences are similar.

Cross correlation between two sequences x(n) and y(n) is defined as

The index l is called the shift or lag parameter

Autocorrelation is correlation of a signal with itself.

//This program finds the Auto/Cross Correlation between the given two sequences

**Cross correlation between two signals x(n) and y(n) is same as convolution between x(n) and y(-n).

Cross Correlation:x=input('Enter the sequence x(n)')n1=input('Enter the time indices of x(n)')y=input('Enter the sequence y(n)')n2=input('Enter the time indices of y(n)')n22=-flipdim(n2,2);y1=flipdim(y,2);n=min(n1)+min(n22):max(n1)+max(n22);A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);if length(x)<length(y1) for i=1:length(x) A(i,i:i+length(y1)-1)=y1(1,:); A(i,:)=x(i).*A(i,:); endelse for i=1:length(y1) A(i,i:i+length(x)-1)=x(1,:); A(i,:)=y1(i).*A(i,:);

Geethanjali College of Engineering & Technology Page 90

Page 92: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

endendc=zeros(1,length(x)+length(y1)-1);for i=1:min(length(x),length(y1)) c(1,:)=c(1,:)+A(i,:);enddisp('The Cross correlation between the given sequences is')disp(c)disp('The Time index of the Cross correlation is')disp(n)subplot(3,1,1)plot2d3(n1,x,style=-2,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])xtitle("", "time", "amplitude")xgridlegend('Given sequence x(n)',2)subplot(3,1,2)plot2d3(n22,y1,style=-2,rect=[min(n22)-1 min(y1)-1 max(n22)+1 max(y1)+1])xtitle("", "time", "amplitude")xgridlegend(' sequence y(-n)',3)subplot(3,1,3)plot2d3(n,c,style=-2,rect=[min(n)-1 min(c)-2 max(n)+1 max(c)+2])xtitle("", "time", "amplitude")xgridlegend('Cross correlation of x(n) and y(n)',3)

1.Enter the sequence x(n)x =1 3 5 7Enter the time indices of x(n) 0 1 2 3Enter the sequence y(n)y =5 7 1 3Enter the time indices of y(n) 0 1 2 3The Time index of the Cross correlation is - 3. - 2. - 1. 0. 1. 2. 3.The Cross correlation of the given sequences is 3 10 25 52 57 74 35

Geethanjali College of Engineering & Technology Page 91

Page 93: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2. Enter the sequence x(n)x = -1 -2 0 5Enter the time indices of x(n) 0 1 2 3Enter the sequence y(n)y = -5 2 0 1Enter the time indices of y(n) 0 1 2 3The Time index of the Cross correlation is - 3. - 2. - 1. 0. 1. 2. 3. The Cross correlation of the given sequences is -1 -2 -2 6 10 10 -25

Geethanjali College of Engineering & Technology Page 92

Page 94: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Auto Correlation:

**The correlation of a sequence with itself is referred to as Auto correlation

**To find the Autocorrelation of a sequence x(n), in the above program, in the place of y(n), enter x(n).

x=input('Enter the sequence x(n)')n1=input('Enter the time indices of x(n)')y=input('Enter the sequence y(n)=x(n)')n2=input('Enter the time indices of y(n)=n1')//y=x; n2=n1n22=-flipdim(n2,2);y1=flipdim(y,2);n=min(n1)+min(n22):max(n1)+max(n22);A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);if length(x)<length(y1) for i=1:length(x) A(i,i:i+length(y1)-1)=y1(1,:); A(i,:)=x(i).*A(i,:); endelse for i=1:length(y1)

Geethanjali College of Engineering & Technology Page 93

Page 95: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

A(i,i:i+length(x)-1)=x(1,:); A(i,:)=y1(i).*A(i,:); endendc=zeros(1,length(x)+length(y1)-1);for i=1:min(length(x),length(y1)) c(1,:)=c(1,:)+A(i,:);enddisp('The Autocorrelation of the given sequence x(n) is')disp(c)disp('The Time index of Auto correlation is')disp(n)subplot(3,1,1)plot2d3(n1,x,style=-2,rect=[min(n1)-1 min(x)-1 max(n1)+1 max(x)+1])xtitle("", "time", "amplitude")xgridlegend('Given sequence x(n)',2)subplot(3,1,2)plot2d3(n22,y1,style=-2,rect=[min(n22)-1 min(y1)-1 max(n22)+1 max(y1)+1])xtitle("", "time", "amplitude")xgridlegend(' sequence x(-n)',3)subplot(3,1,3)plot2d3(n,c,style=-2,rect=[min(n)-1 min(c)-2 max(n)+1 max(c)+10])xtitle("", "time", "amplitude")xgridlegend('Auto correlation of x(n)',2)

1.Enter the sequence x(n)x =1 3 5 7Enter the time indices of x(n) 0 1 2 3Enter the sequence y(n)=x(n)y = 1 3 5 7Enter the time indices of y(n)=n1 0 1 2 3The Time index of the correlation is - 3. - 2. - 1. 0. 1. 2. 3.The Autocorrelation of the given sequence x(n) is 7. 26. 53. 84. 53. 26. 7.

Geethanjali College of Engineering & Technology Page 94

Page 96: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program finds the Auto/Cross Correlation between the given two Sinusoidal signalsCross Correlation:

f1=input('enter the frequency of signal1')T1=1/f1;t1=0:T1/f1:T1;x=sin(2*%pi*f1*t1);f2=input('enter the frequency of signal2')T2=1/f2;t2=0:T2/f2:T2;y=sin(2*%pi*f2*t2);t22=-flipdim(t2,2);y1=flipdim(y,2);A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);if length(x)<length(y1) for i=1:length(x) A(i,i:i+length(y1)-1)=y1(1,:); A(i,:)=x(i).*A(i,:); endelse for i=1:length(y1) A(i,i:i+length(x)-1)=x(1,:); A(i,:)=y1(i).*A(i,:); end

Geethanjali College of Engineering & Technology Page 95

Page 97: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

endc=zeros(1,length(x)+length(y1)-1);for i=1:min(length(x),length(y1)) c(1,:)=c(1,:)+A(i,:);endt=linspace(min(t1)+min(t22),max(t1)+max(t22),length(c));subplot(3,1,1)plot2d3(t1,x,style=-2,rect=[min(t1) -1.1 max(t1) 1.1])xtitle("", "time", "amplitude")xgridlegend('Given signal x(t) with f=100')subplot(3,1,2)plot2d3(t22,y1,style=-2,rect=[min(t22) min(y1)-0.1 max(t22) max(y1)+0.1])xtitle("", "time", "amplitude")xgridlegend(' signal y(-t) with f=150',2)subplot(3,1,3)plot2d3(t,c,style=-2,rect=[min(t) min(c)-5 max(t) max(c)+5])xtitle("", "time", "amplitude")xgridlegend('Cross correlation of x(t) and y(t)',2)

Geethanjali College of Engineering & Technology Page 96

Page 98: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Auto Correlation:

**The correlation of a signal with itself is referred to as Auto correlation

**To find the Autocorrelation of a signal x(t), in the above program, in the place of y(t), enter x(t).

f1=input('enter the frequency of signal1')T1=1/f1;t1=0:T1/f1:T1;x=sin(2*%pi*f1*t1);f2=input('enter the frequency of signal2=f1')T2=1/f2;t2=0:T2/f2:T2;y=sin(2*%pi*f2*t2);t22=-flipdim(t2,2);y1=flipdim(y,2);A=zeros(min(length(x),length(y1)),length(x)+length(y1)-1);if length(x)<length(y1) for i=1:length(x) A(i,i:i+length(y1)-1)=y1(1,:); A(i,:)=x(i).*A(i,:); endelse for i=1:length(y1) A(i,i:i+length(x)-1)=x(1,:); A(i,:)=y1(i).*A(i,:); endendc=zeros(1,length(x)+length(y1)-1);for i=1:min(length(x),length(y1)) c(1,:)=c(1,:)+A(i,:);endt=linspace(min(t1)+min(t22),max(t1)+max(t22),length(c));subplot(3,1,1)plot2d(t1,x,style=5,rect=[min(t1) -1.1 max(t1) 1.1])xtitle("", "time", "amplitude")xgridlegend('Given signal x(t) with f=100')subplot(3,1,2)plot2d(t22,y1,style=5,rect=[min(t22) min(y1)-0.1 max(t22) max(y1)+0.1])xtitle("", "time", "amplitude")xgridlegend(' signal x(-t)',2)subplot(3,1,3)plot2d(t,c,style=5,rect=[min(t) min(c)-5 max(t) max(c)+5])xtitle("", "time", "amplitude")

Geethanjali College of Engineering & Technology Page 97

Page 99: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

xgridlegend('Auto correlation of x(t)',2)

CONCLUSION: In this experiment correlation(Auto/Cross) between signals/sequences have been implemented .

Applications: 1. Autocorrelation of a signal is used to find the Mean square value of a signal. 2.Autocorrelation is used in signal estimation in the presence of Noise.

VIVA QUESTIONS1.For what value of lag τ, Auto correlation of a signal is maximum and cross correlation of two signals is minimum.2.Define Power spectral density of a signal. How it is related to Autocorrelation of the Signal?3.What is the symmetry possessed by Auto correlation function of a signal?4.What is the relation between cross correlation Rxy(τ) and Ryx(τ)?

EXP.NO: 7

Geethanjali College of Engineering & Technology Page 98

Page 100: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

VERIFICATION OF LINEARITY AND TIME INVARIANCE PROPERTIES OF A GIVEN CONTINUOUS /DISCRETE SYSTEM.

Aim: To compute linearity and time invariance properties of a given continuous /discrete system

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

THEORY:

LINEARITY PROPERTY : Any system is said to be linear if it satisfies the superposition principalsuperposition principal state that Response to a weighted sum of input signal equal to the corresponding weighted sum of the outputs of the system to each of the individual input signals

Linearity: //This program checks the given system represented by its difference equation for Linearitya=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')x1=rand(1,10);x2=rand(1,10);i=input('enter the amplitude scaling factor for x1(n)')j=input('enter the amplitude scaling factor for x2(n)')h1=filter(a,b,i*x1);h2=filter(a,b,j*x2);h=h1+h2;h3=filter(a,b,i*x1+j*x2);error=max(abs(h-h3));//The limited numerical precision of MATLAB is %eps = 2.220D-16 if error<%eps disp('The system is linear')else disp('The system is non-linear')end

Geethanjali College of Engineering & Technology Page 99

Page 101: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

y = filter(b,a,X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a

1) The system is represented as y(n)=x(n)+x(n-1).enter the coefficient vector of input starting from the coefficient of x(n) terma =1 1enter the coefficient vector of output starting from the coefficient of y(n) termb =1enter the amplitude scaling factor for x1(n)i =2enter the amplitude scaling factor for x2(n)j =3The system is linear

2)The system is represented as y(n)=x2(n)a=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')x1=rand(1,10);x2=rand(1,10);i=input('enter the amplitude scaling factor for x1(n)')j=input('enter the amplitude scaling factor for x2(n)')h1=filter(a,b,(i*x1).^2);h2=filter(a,b,(j*x2).^2);h=h1+h2;h3=filter(a,b,(i*x1+j*x2).^2);error=max(abs(h-h3));if error<%eps disp('The system is linear')else disp('The system is non-linear')end

enter the coefficient vector of input starting from the coefficient of x(n) term a =1enter the coefficient vector of output starting from the coefficient of y(n) termb =1enter the amplitude scaling factor for x1(n)i =2enter the amplitude scaling factor for x2(n)

Geethanjali College of Engineering & Technology Page 100

Page 102: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

j =3The system is non-linear

rand(m1,m2,’uniform’) - generates arrays of random numbers whose elements are uniformly distributed in the interval (0,1).

Time Invariance:

//This program checks the given system for Time invariancea=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')n=input('enter the duration of the input')k=input('enter the amount of shift i.e a number between 1 and n required for the input')x=rand(1,n);x1=[x zeros(1,k)];x2=[zeros(1,k) x];y1=filter(a,b,x1);y2=filter(a,b,x2);y11=[zeros(1,k) y1];y11(length(y2)+1:length(y11))=[];error=max(abs(y2-y11));if error==0 disp('The system is Time invariant')else disp('The system is not Time Invariant')end

1. The system is y(n)= x(n)-3x(n-1)+x(n-2) enter the coefficient vector of input starting from the coefficient of x(n) terma =1 -3 1'enter the coefficient vector of output starting from the coefficient of y(n) term'b =1enter the duration of the inputn =10'enter the amount of shift i.e a number between 1 and n required for the input'k =1 The system is Time invariant2.The system is y(n)=0.9y(n-1)+x(n)enter the coefficient vector of input starting from the coefficient of x(n) terma =1

Geethanjali College of Engineering & Technology Page 101

Page 103: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the coefficient vector of output starting from the coefficient of y(n) term

b =1 -0.9enter the duration of the inputn = 10'enter the amount of shift i.e a number between 1 and n required for the input'

k =2 The system is Time Invariant

3. The Given system is y(n)= n.x(n)

i=input('enter the duration of the input')k=input('enter the amount of shift i.e a number between 1 and n required for the input')x=rand(1,i);n=1:i;n1=n;y=n.*x;x1=[zeros(1,k) x];n1(length(n)+1:length(x1))=0;y1=n1.*x1;n=[zeros(1,k) n];y2=n.*x1;error=max(abs(y1-y2));if error==0 disp('The system is Time invariant')else disp('The system is not Time Invariant')end

The given system is not Time Invariant

RESULT:- Various discrete systems are checked for Linearity and Time Invariance.

VIVA QUESTIONS

1.Define the Principle of Homogeneity of a system.2. Is the system y(n)=n2.x(n) (i) Linear (ii) Time invariantEXP.NO:8

COMPUTATION OF UNIT SAMPLE, UNIT STEP AND SINUSOIDAL RESPONSE OF THE GIVEN LTI SYSTEM AND VERIFYING ITS PHYSICAL REALIZABILITY AND STABILITY PROPERTIES.

Geethanjali College of Engineering & Technology Page 102

Page 104: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Aim: To Unit Step And Sinusoidal Response of the given LTI System And Verifying Its Physical Realizability And Stability Properties.

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

A system performs an operation on an input signal based on predefined criteria to produce a modified output signal. The input signal x(n) is the system excitation, and y(n) is the system response. The transform operation is shown as,

If the input to the system is unit impulse i.e. x(n) = δ(n), Sin(won) and Step sequence , the respective outputs of the system are referred to as Impulse response, Sinusoidal Response and Step Response respectively

Computation of Unit Sample response ://This program finds the unit sample response of the given discrete system a=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')n1=input('enter the lower limit of the range of impulse response')n2=input('enter the upper limit of the range of impulse response')n=[n1:n2];x=zeros(1,length(n));i=find(n==0);x(i)=1;h=filter(a,b,x);plot2d3(n,h,style=-4,rect=[n1 min(h)-1 n2 max(h)+1])xtitle("", "time", "amplitude")xgridlegend('Unit Sample response of the given discrete system y(n)-y(n-1)+0.9y(n-2)=x(n)')

Geethanjali College of Engineering & Technology Page 103

Page 105: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Computation of Unit Step response ://This program finds the unit step response of the given discrete systema=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')n1=input('enter the lower limit of the range of impulse response')n2=input('enter the upper limit of the range of impulse response')n=[n1:n2];x=zeros(1,length(n));i=find(n==0);x(i:length(x))=1;h=filter(a,b,x);plot2d3(n,h,style=-4,rect=[n1 min(h)-1 n2 max(h)+1])xtitle("", "time", "amplitude")xgridlegend('Unit Step response of the given discrete system y(n)-y(n-1)+0.9y(n-2)=x(n)')

Geethanjali College of Engineering & Technology Page 104

Page 106: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Computation of Sinusoidal response ://This program finds the Sinusoidal response of the given discrete system

a=input('enter the coefficient vector of input starting from the coefficient of x(n) term')b=input('enter the coefficient vector of output starting from the coefficient of y(n) term')f=input('enter the sampling frequency')T=1/f;t=0:T/f:T;x=sin(2*%pi*f*t);h=filter(a,b,x);subplot(2,1,1)plot2d3(t,x,style=-4,rect=[0 min(x)-1 T max(x)+1])xtitle("", "time", "amplitude")xgridlegend('Sinusoidal input(f=50) for the discrete system y(n)-y(n-1)+0.9y(n-2)=x(n)')subplot(2,1,2)plot2d3(t,h,style=-4,rect=[0 min(x)-1 T max(x)+1])xtitle("", "time", "amplitude")

Geethanjali College of Engineering & Technology Page 105

Page 107: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

xgridlegend('Sinusoidal(f=50) response of the discrete system y(n)-y(n-1)+0.9y(n-2)=x(n)')

Verifying the physical realizability and Staility of the given discrete system

For a system to be physically realizable, it must be causal.This can be checked as “The unit impulse response h(t)<0 for t<0”.A system is said to be BIBO stable, if every bounded input results in a bounded output. Foe BIBO stable system, the impulse response must be absolutely integrable/summable.

//This program checks the given discrete system for its physical realizability and Stabilitya=input('enter the coefficients of numerator in the order of decreasing order of the variable z')b=input('enter the coefficients of denominator in the order of decreasing order of the variable z')p=roots(a);q=roots(b);i=find(abs(q)<1);

Geethanjali College of Engineering & Technology Page 106

Page 108: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

R1=input('enter the lower bound of ROC')R2=input('enter the upper bound of ROC')if length(p)<=length(q) & R2==%inf disp('The system is causal')else disp('The system is not causal')endif R1<1&R2>1 | length(i)==length(q) disp('The system is stable')else disp('The system is unstable') end1.H(z)=z/(3z2-4z+1) ROC |z|>1enter the coefficients of numerator in the order of decreasing order of the variable za =1 0enter the coefficients of denominator in the order of decreasing order of the variable z b=3 -4 1enter the lower bound of ROCR1 =1enter the upper bound of ROCR2 =InfThe system is causal. The system is unstable2.H(z)=z/(3z2-4z+1) ROC 1/3<|z|<1enter the coefficients of numerator in the order of decreasing order of the variable za =1 0enter the coefficients of denominator in the order of decreasing order of the variable z b=3 -4 1enter the lower bound of ROCR1 =1/3enter the upper bound of ROCR2 =1The system is not causal. The system is unstable

3.H(z)= (z2-1.5z)/[z2-(5/6)z+1/6] ROC |z|>0.5enter the coefficients of numerator in the order of decreasing order of the variable za =1.0000 -1.5000 0enter the coefficients of denominator in the order of decreasing order of the variable zb =1.0000 -0.8333 0.1667enter the lower bound of ROCR1 =0.5000enter the upper bound of ROCR2 =inf. The system is causal. The system is stable

Geethanjali College of Engineering & Technology Page 107

Page 109: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

4.H(z)= (z2-1.5z)/(z2-(5/6)z+1/6) ROC 1/3< |z|<0.5enter the coefficients of numerator in the order of decreasing order of the variable za =1.0000 -1.5000 0enter the coefficients of denominator in the order of decreasing order of the variable zb =1.0000 -0.8333 0.1667enter the lower bound of ROCR1 =1/3enter the upper bound of ROCR2 =0.5. The system is not causal. The system is stable

5. H(z)=[2z2-2.5z]/[z2-2.5z+1] ROC 0.5<z<2The system is not causal. The system is stable

**A Discrete LTI system with a rational system function H(z) is causal if the ROC is exterior of a circle with a radius equal to the outermost pole i.e ROC should include “Infinity” i.e.

This is satisfied if H(z) does not have the order of the numerator is not greater than that of the denominator

**A Discrete LTI system is stable if and only if the ROC of the system function includes the unit circle, i.e.|z|=1

**For a causal system to be stable, all the poles must lie within the unit circle.

CONCLUSION: In this experiment computation of unit sample, unit step and

sinusoidal response of the given LTI system is implemented and the given systems are

checked for their physical realizability and stability.

VIVA QUESTIONS

1.Why Ideal LPF is not physically realizable?2.What is Paley-wiener criterion?3.For discrete system to be BIBO stable, what is the condition to be satisfied by its unit sample response?

EXP.NO: 9 GIBBS PHENOMENON

Aim: To verify the Gibbs Phenomenon.

Geethanjali College of Engineering & Technology Page 108

Page 110: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

Consider the approximation of symmetric rectangular pulse defined as

by a single function “sint”.

The approximation improves when a large number of mutually orthogonal functions are used.

The functions are mutually orthogonal over .

The given rectangular pulse is now approximated by a finite series of sinusoidal functions:

The constant =

=

The approximation is given by

The approximation will be better as the number of sinusoids used for approximation increases.

//This program verifies Gibb's Phenomenon

f=input('enter the sampling frequency')T=input('enter the duration over which the wave is to be plotted')t=linspace(0,T,f);p=zeros(1,length(t));q=p;for i=1:length(t)/2 p(i)=1; p(i+(length(t)/2))=-1;endn=input('enter the number of sinusoids')for i=0:n-1 k=1/(2*i+1);for j=1:length(t)

Geethanjali College of Engineering & Technology Page 109

Page 111: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

q(j)=(q(j)+(4/%pi)*k*sin((1/k)*t(j)));endendplot(t,p,'r',t,q,'k')xlabel("time")ylabel("Amplitude")legend(["Rectangular Pulse","Sinusoidal Signals"])title('f=1000 and Number of Sinusoids=')mtlb_axis([0 6 -2 2])

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 1

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 2

Geethanjali College of Engineering & Technology Page 110

Page 112: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 3

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 6

Geethanjali College of Engineering & Technology Page 111

Page 113: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 10

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 15

Geethanjali College of Engineering & Technology Page 112

Page 114: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 25

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 50

Geethanjali College of Engineering & Technology Page 113

Page 115: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 100

enter the sampling frequency 1000enter the duration over which the wave is to be plotted 2*%pienter the number of sinusoids 500

Geethanjali College of Engineering & Technology Page 114

Page 116: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

CONCLUSION: Gibbs phenomenon have been verified

VIVA QUESTIONS

1. What are Dirchlet Condition2. Define Fourier Series3. What is Half Wave Symmetry

EXP.NO: 10

Geethanjali College of Engineering & Technology Page 115

Page 117: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

FINDING THE FOURIER TRANSFORM OF A GIVEN SIGNAL AND PLOTTING ITS MAGNITUDE AND PHASE SPECTRUM

Aim: To find the Fourier transform of a given signal and plotting its magnitude and phase spectrum

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

Fourier Transform of signal f(t) is defined as

//This program finds the Fourier Transform of exp(-At)

//Defining the Time domain signal x(t)=exp(-At)A=input('enter the constant of decay')T=input('énter the increment for time axis')T1=input('enter the upper bound for time axis')t=0:T:T1;x=exp(-A*t);//Defining the Omega Axisf=input('enter the analog frequency')B=4; //a random integerb=0:B/1000:B;w=b*2*%pi*f/B;//Defining Fourier Transformft=x*exp(-%i*t'*w)*T;//Magnitude of Fourier Transforma=abs(ft);//computing phase spectrum[phase dB]=phasemag(ft);W=[-mtlb_fliplr(w) w(2:length(w))];FT=[mtlb_fliplr(a) a(2:length(a))]phase_plot=[-mtlb_fliplr(phase) phase(2:length(w))]subplot(3,1,1))plot2d(t,x,style=-4,rect=[min(t) min(x) max(t) max(x)])xgridxtitle('The given exponential signal with A=1,T=0.005,T1=5',"t","Amplitude")subplot(3,1,2)plot2d(W,FT,style=-4,rect=[min(W)-3.5 min(FT)-0.01 max(W)+3.5 max(FT)+0.01])xgridxtitle('Magnitude Spectrum with f=1',"W","Magnitude")

Geethanjali College of Engineering & Technology Page 116

Page 118: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

subplot(3,1,3)plot2d(W,phase_plot*%pi/180,style=-4,rect=[min(W) min(phase_plot*%pi/180) max(W) max(phase_plot*%pi/180)])xgridxtitle('Phase Spectrum ',"W","phase")

[phi,db]=phasemag(z [,mod])

Geethanjali College of Engineering & Technology Page 117

Page 119: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Arguments z -matrix or row vector of complex numbers. mod -character string mod='c' - "continuous" representation between -infinity and +360 degrees (default) mod='m' -representation between -360 and 0 degrees phi - phases (in degree) of z. db -magnitude (in Db)

Description: phasemag computes the phases and magnitudes of the entries of a complex matrix.

To obtain the phase between -%pi and %pi, use phi=atan(imag(z),real(z))

CONCLUSION: In this experiment the Fourier transform of a given signal and plotting

its magnitude and phase spectrum have been demonstrated using MATLAB.

VIVA QUESTIONS

1.What is the relation between Fourier Series and Fourier Transform?2. What is the condition for a signal to have Fourier Transform?3.How to find the area enclosed by f(t), from its Fourier Transform?

Use of Symbolic Mathematics in MATLAB:

Geethanjali College of Engineering & Technology Page 118

Page 120: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

sym Function: It is used to create a symbolic number, variable and object. The syntax is x=sym(‘x’).This creates the symbolic variable with name x and stores the result in x.syms Function: It is the shortcut for constructing a number of symbolic objects. The syntax is syms arg1 arg2 arg3. For example, syms p q rcreates three symbolic objects ‘p’, ‘q’, ‘r’. It is similar to three sym functions as syms p, syms q, syms r.

Example:1.X=sqrt(20)ans = 4.4721 When expressed as symbolic object, X=sqrt(sym(10)) ans = 10^(1/2)

2. sym t ans = t x=sin(t); diff(x) This command takes the derivative of x with respect to variable ‘t’ as there is only one variable ‘t’ in the expression.ans = cos(t) diff(x,2) This command takes the second derivative of x with respect to ‘t’.ans = -sin(t)

Exp:11 WAVEFORM SYNSTHESIS

Geethanjali College of Engineering & Technology Page 119

Page 121: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Aim: To perform waveform synthesis using Laplace Transforms of a given signal

Bilateral Laplace transform :

The bilateral Laplace transform is defined as follows:

%This program find the laplace transform of the given function f(t)syms tft=input('define the function')fs=laplace(ft);disp('The laplace Transform of the given function f(t) is')disp(fs)

1. f(t)= (-4/3)e-t+(1/3)e2t.define the function ft = -4/3*exp(-t)+1/3*exp(2*t) The laplace Transform of the given function f(t) is-4/3/(s+1)+1/3/(s-2) i.e. –(4/3).(1/(s+1))+(1/3).(1/(s-2)).

2. f(t)=t2.sin(t).define the function ft = t^2*sin(t) The laplace Transform of the given function f(t) is2/(s^2+1)^3*(-1+3*s^2).

3. f(t)=t2.e-2t.define the function ft = t^2*exp(-2*t) The laplace Transform of the given function f(t) is2/(s+2)^3

4. f(t)=3e-2t-2e-t.define the function ft = 3*exp(-2*t)-2*exp(-t) The laplace Transform of the given function f(t) is3/(s+2)-2/(s+1)

5. define the function ft = dirac(t)

Geethanjali College of Engineering & Technology Page 120

Page 122: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

The laplace Transform of the given function f(t) is 1

%This program finds the inverese laplace transform of given F(s)syms s t;fs=input('enter the Laplace Tranform ')ft=ilaplace(fs);disp('The inverse laplace Transform of the given F(s) is')disp(ft)

1.enter the Laplace Transform fs =1/(s+4)The inverse laplace Transform of the given F(s) isexp(-4*t) 2.enter the Laplace Transform fs =36/(s^2+3*s+36) The inverse laplace Transform of the given F(s) is8/5*15^(1/2)*exp(-3/2*t)*sin(3/2*15^(1/2)*t)

3.enter the Laplace Transform fs = (2*s^2+5*s+12)/(s^2+2*s+10)/(s+2)The inverse laplace Transform of the given F(s) isexp(-t)*cos(3*t)+exp(-2*t) 4. enter the Laplace Transform fs = 1/sThe inverse laplace Transform of the given F(s) is 1

5. enter the Laplace Transform fs = 1/s^3 The inverse laplace Transform of the given F(s) is 1/2*t^2

Waveform synthesis

Geethanjali College of Engineering & Technology Page 121

Page 123: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//(i)This program performs the wave form synthesis of a stair case waveform f=input('enter the sampling frequency')T=1/f;L=input('enter the lower bound for the time axis')U=input('enter the upper bound for the time axis')t=L:T:U;x=zeros(1,length(t));y=x;for i=find(t==0):find(t==1) x(i)=1;endx(find(t==1))=0;for i=find(t==1):find(t==2) x(i)=2;endx(find(t==2))=0;for i=find(t==2):find(t==3) x(i)=3;endz=find(diff(x)==1);y(z(1)+1:length(y))=1;subplot(4,1,1)plot2d2(t,x,style=5,rect=[L min(x) U max(x)+1])xtitle("","time","Amplitude")legend('u(t)+u(t-1)+u(t-2) with f=1000;L=-1;U=3')xgridsubplot(4,1,2)plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])xtitle("","time","Amplitude")legend('The First Constituent Step Function')xgridy=y-y;y(z(2)+1:length(y))=1;subplot(4,1,3)plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])xtitle("","time","Amplitude")legend('The Second Constituent Step Function')xgridy=y-y;y(z(3)+1:length(y))=1;subplot(4,1,4)plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])xtitle("","time","Amplitude")legend('The Third Constituent Step Function')xgrid

Geethanjali College of Engineering & Technology Page 122

Page 124: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

(ii) x(t)=2u(t)-3u(t-2)+2u(t-4)

f=input('enter the sampling frequency')T=1/f;L=input('enter the lower bound for the time axis <0')U=input('enter the upper bound for the time axis>4')t=L:T:U;x=zeros(1,length(t));y=x;for i=find(t==0):find(t==2) x(i)=2;endx(find(t==2))=0;for i=find(t==2):find(t==4) x(i)=-3;endx(find(t==4))=0;for i=find(t==4):find(t==U) x(i)=2;endz=find(diff(x)==2);y(z(1)+1:length(y))=2;subplot(4,1,1)plot2d2(t,x,style=5,rect=[L min(x)-1 U max(x)+1])xtitle("","time","Amplitude")legend('2u(t)-3u(t-2)+2u(t-4) with f=1000,L=-1,U=6')xgridsubplot(4,1,2)

Geethanjali College of Engineering & Technology Page 123

Page 125: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])xtitle("","time","Amplitude")legend('The First Constituent Step Function')xgridy=y-y;z=find(diff(x)==-5);y(z(1)+1:length(y))=-5;subplot(4,1,3)plot2d2(t,y,style=5,rect=[L min(y)-1 U max(y)])xtitle("","time","Amplitude")legend('The Second Constituent Step Function')xgridy=y-y;z=find(diff(x)==5);y(z(1)+1:length(y))=5;subplot(4,1,4)plot2d2(t,y,style=5,rect=[L min(y) U max(y)+1])xtitle("","time","Amplitude")legend('The Third Constituent Step Function',2)xgrid

(iii) x(t)=r(t)-2r(t-1)+r(t-2)

f=input('enter the sampling frequency')T=1/f;U=input('enter the upper bound for the time axis')t=0:T:U;//Finding the first Constitutent Rampx=t;//Finding the second constitutent Rampy=zeros(1,length(t));

Geethanjali College of Engineering & Technology Page 124

Page 126: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

z=y;i=find(t==1);j=length(i:length(t));y(i:i+j-1)=2*x(1:j)//Finding the third consrtitutent Rampi=find(t==2);j=length(i:length(t));z(i:i+j-1)=x(1:j);subplot(2,2,1)plot2d(t,x-y+z,rect=[0 0 U 1])xtitle('x(t)=r(t)-2r(t-1)+r(t-2) with fs=10 and U=3')xlabel('time')ylabel('Amplitude')xgridsubplot(2,2,2)plot2d(t,x,rect=[0 0 U 1])xtitle('Plot of the first constituent ramp signal')xlabel('time')ylabel('Amplitude')xgridsubplot(2,2,3)plot2d(t,-y,rect=[0 min(-y) U max(y)])xtitle('Plot of the second constituent ramp signal')xlabel('time')ylabel('Amplitude')xgridsubplot(2,2,4)plot2d(t,z,rect=[0 0 U 1])xtitle('Plot of the Third constituent ramp signal')xlabel('time')ylabel('Amplitude')xgrid

Geethanjali College of Engineering & Technology Page 125

Page 127: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

CONCLUSION: In this experiment Laplace Transforms of various signals was

computed and wave form synthesis was implemented.

Applications of Laplace transforms:1. Derive the circuit (differential) equations in the time domain, then transform

these ODEs to the s-domain; 2. Transform the circuit to the s-domain, then derive the circuit equations in the s-

domain (using the concept of "impedance").The main idea behind the Laplace

Transformation is that we can solve an equation (or system of equations)

containing differential and integral terms by transforming the equation in "t-

space" to one in "s-space". This makes the problem much easier to solve.

3. VIVA QUESTIONS

1. Define Laplace-Transform2. What is the Condition for Convergence of the L.T3. What is the Region of Convergence(ROC)4. State the Shifting property of L.T5. State convolution Property of L.T

Polynomials in Scilab.

Geethanjali College of Engineering & Technology Page 126

Page 128: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Polynomials can be defined by specifying their (i) roots (ii) coefficients.Ex. (i)p=poly([3 4], ”x”,”roots”)

p=12-7x+x2

(ii) p=poly([1 2],”x”,”coeff”)

p= 1+2x.

**In the above “poly”, ‘x’ represents the variable/symbol which is verified by varn() command.

varn(p) gives the answer as ‘x’.

**The variable ’x’ can be replaced by another variable as varn(p,’s’). The resulting polynomial will be in terms of ‘s’.

p=poly([1 2 3 4 5],"x", "coeff") p = 2 3 4 1 + 2x + 3x + 4x + 5x varn(p,"s") ans = 2 3 4 1 + 2s + 3s + 4s + 5s

**coeff(p) will give the coefficients of the polynomial p.

coeff(p) ans = 1. 2. 3. 4. 5.

**The coefficient can be extracted separately by referring to the index

coeff(p,4) ans =5 ** Polynomial Matrix x=poly(0,'s') x = s

Geethanjali College of Engineering & Technology Page 127

Page 129: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

-->p=[1 x; x x^2] p = 1 s 2 s s

**Derivative of a polynomial.

x=poly(0,'s') x = s derivat(x^2)ans = 2s **Integration of a polynomial.

x=integrate(‘expr’,’v’,x0,x1)

Argumentsexpr =Character string defining a Scilab expression.

v =Character string, the integration variable name

x0 =real number, the lower bound of integration

x1 =vector of real numbers, upper bounds of integration

x =vector of real numbers, the integral value for each x1(i).

&&&&&&&&

Geethanjali College of Engineering & Technology Page 128

Page 130: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO:12

LOCATING THE ZEROS AND POLES AND PLOTTING THE POLE ZERO MAPS IN S-PLANE AND Z-PLANE FOR THE GIVEN TRANSFER FUNCTION.

Aim: Pplotting the pole zero maps in s-plane and z-plane for the given transfer function

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

Z-transformsthe 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.

Bilateral Z-transform

The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the function X(z) defined as

Unilateral Z-transform

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.

The roots of the equation P(z) = 0 correspond to the 'zeros' of X(z)The roots of the equation Q(z) = 0 correspond to the 'poles' of X(z)

Consider the Transfer Function H(z) given as

Geethanjali College of Engineering & Technology Page 129

Page 131: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

PROGRAM:- ZEROS AND POLES IN S- PLANE ** s=poly(0,"s") is the seed for defining polynomials with symbol "s".

**Define the system Transfer function as a ratio of numerator(n) and denominator(d) polynomials using h=syslin(“dom”,n,d), where “dom” is the character string “c”-for continuous stem; “d”-for discrete system; “n”-for sampled system with sampling period “n”

**plzr(h) will give the pole-zero plot of the system.

//This program finds the poles and zeros of the given H(s) and gives the pole-zero plot in S-Plane s=poly(o,’s’);a=input('enter the numerator Polynomial’)b=input('enter the denominator Polynomial’))z=roots(a);p=roots(b);disp('The poles of the given H(s) are')disp(p)disp('The zeros of the given H(s)are')disp(z)h=syslin(“c”, a, b)plzr(h)

1.H(s)= (s2+5s+4)/(s2+8s+12) enter the numerator coefficients as a vector in the order of decreasing powers of sa = 2 4 + 5s + s

enter the denominator coefficients as a vector in the order of decreasing powers of sb = 2 12 + 8s + s The poles of the given H(s) are -6 -2The zeros of the given H(s) are -4

Geethanjali College of Engineering & Technology Page 130

Page 132: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

-1

2. H(s)= (s2+3s+4)/(s2+3s+12)enter the numerator coefficients as a vector in the order of decreasing powers of sa = 2 4 + 3s + s

enter the denominator coefficients as a vector in the order of decreasing powers of sb = 2 12 + 3s + s The poles of the given H(s) are -1.5000 + 3.1225i -1.5000 - 3.1225i

The zeros of the given H(s)are -1.5000 + 1.3229i -1.5000 - 1.3229i

Geethanjali College of Engineering & Technology Page 131

Page 133: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

//This program finds the poles and zeros of the given H(z) and gives the pole-zero plot in Z-Plane

z=poly(o,’z’);a=input('enter the numerator Polynomial’)b=input('enter the denominator Polynomial’))z=roots(a);p=roots(b);disp('The poles of the given H(z) are')disp(p)disp('The zeros of the given H(z)are')disp(z)h=syslin(“d”, a, b)plzr(h)

1.H(z)= z2/(z-1)(z2+3z+2) After expressing both numerator and denominator as negative powers of z, H(z)=z-1/(1+2z-1-z-2-2z-3)enter the numerator polynomiala = z2

enter the denominator polynomial

Geethanjali College of Engineering & Technology Page 132

Page 134: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

b = 2 3 - 2 - z + 2z + z The poles of the given H(z) are 1. - 2. - 1. The zeros of the given H(z)are 0 0

2. H(z)= z/(3z2-4z+1) enter the numerator coefficients as a vector starting from constanta = zenter the numerator coefficients as a vector starting from constant

Geethanjali College of Engineering & Technology Page 133

Page 135: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

b = 2 1 - 4z + 3z

The poles of the given H(z) are 1. 0.3333333 The zeros of the given H(z)are 0.

CONCLUSION: In this experiment the pole-zero plots pf continuous/Discrete systems were plotted.

VIVA QUESTIONS

1.What is the importance of poles and zeros of a system, with respect to the stability of

a

Geethanjali College of Engineering & Technology Page 134

Page 136: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

system?

2.If the pole of a continuous is lying in the left half of the S-Plane, what will be the

steady state value of its impulse response?

3. If the pole of a discrete system is lying within the unit circle, what about the

convergence of its unit sample response?

EXP.NO: 13 Generation of Gaussian Noise, Computation of its mean, mean square value, Skew, Kurtosis, and CDF

Geethanjali College of Engineering & Technology Page 135

Page 137: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

AIM: - To generate a Gaussian noise and to compute its Mean, Mean Square Value, Skew, Kurtosis, PSD, Probability Distribution function.

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab SoftwarePROGRAM:-

Generation of Gaussian Density Function://This program generates a Gaussian distributed random variable for a given value of mean and variancen1=input('enter the lower limit of range of values of x')n2=input('enter the higher limit of range of values of x')n3=input('enter the incremental value of the range')n=[n1:n3:n2];m=input('enter the mean of the random variable')v=input('enter the variance of the random variable')x=(1/(sqrt(2*%pi*v)))*exp(-((n-m).^2)/(2*v));plot2d(n,x,style=5,rect=[n1 0 n2 max(x)])xtitle('normal density')xlabel('x')ylabel('Density function')legend('mean=0,variance=4')xgrid

enter the lower limit of range of values of xn1 =-4enter the higher limit of range of values of xn2 =4enter the incremental value of the rangen3 =0.2000enter the mean of the random variablem = 0enter the variance of the random variablev =4

Y=grand(m,n,'nor',Av,Sd)- generates normally distributed random data with mean=Av and “Sd” is the standard deviation. 'mxn’ is the size of the data

Geethanjali College of Engineering & Technology Page 136

Page 138: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Generation of Cumulative Distribution Function of Gaussian Random Variable:

//This program generates a Gaussian distributed random variable for a given value of mean and variancefunction y=qfunc(x) y=0.5*erfc(x/sqrt(2));endfunctionn1=input('enter the lower limit of range of values of x')n2=input('enter the higher limit of range of values of x')n3=input('enter the incremental value of the range')n=[n1:n3:n2];m=input('enter the mean of the random variable')v=input('enter the variance of the random variable')x=(n-m)/sqrt(v);y=1-qfunc(x);plot2d(n,y,style=-4,rect=[n1 min(y) n2 max(y)+0.25])xgridxtitle('CDF of a Gausian Random Variable',"x","cdf")legend('mean=1,variance=4',"x","cdf",2)

1.enter the lower limit of range of values of x

Geethanjali College of Engineering & Technology Page 137

Page 139: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

n1 = -10enter the higher limit of range of values of xn2 =10enter the incremental value of the rangen3 = 0.02enter the mean of the random variablem =1enter the variance of the random variablev =4

Finding the Moments of the Gaussian Random Variable.//This program finds the mean, variance, skew and Kurtosis of a Gaussian distributed random variablen=input('enter the number of values taken by the random variable')rand('normal')y=rand(1,n);y1=zeros(1,length(y));M=mean(y);for i=1:length(y) y1(i)= ((y(i)-M).^2)/(length(y));endvariance=sum(y1);for i=1:length(y)

Geethanjali College of Engineering & Technology Page 138

Page 140: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

y1(i)=((y(i)-M).^3)/(length(y));endskew=sum(y1)/(variance^1.5);for i=1:length(y) y1(i)=((y(i)-M).^4)/(length(y));endkurtosis=sum(y1)/(variance^2);disp('The mean, variance, skew and kurtosis of the given normal distribution are "+string(M)+" "+string(variance)+" "+string(skew)+" "+string(kurtosis)+" respectively')

1. enter the number of values taken by the random variablen =100The mean, variance, skew and kurtosis of the given normal distribution are 0.0093114, 0.9415152, 0.0827996, 2.9007932 respectively 2. enter the number of values taken by the random variablen =1000The mean, variance, skew and kurtosis of the given normal distribution are -0.0044692, 0.9889842, 0.0277401, 2.7898307 respectively

Result: The pdf and CDF of a Gaussian Distributed random variable are plotted and its moment are computed.Viva Questions:1.Stae Central Limit Theorem.2.For what value of x, the Gaussian random variable X will have its maximum value?3. What is a standardized Gaussian Random Variable?

Geethanjali College of Engineering & Technology Page 139

Page 141: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.NO: 1414. Sampling theorem verification

AIM: -. To generate a MATLAB Program to verify sampling theorem.

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB SoftwareSampling Theorem: A bandlimited signal can be reconstructed exactly if it is sampled at a rate atleast twice the maximum frequency component in it." Figure 1 shows a signal g(t) that is bandlimited.

Figure 1: Spectrum of band limited signal g(t)

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

Proof: Let g(t) be a bandlimited signal whose bandwidth is fm(wm = 2πfm).

Figure 2: (a) Original signal g(t) (b) Spectrum G(w)δ (t) is the sampling signal with fs = 1/T > 2fm.

Geethanjali College of Engineering & Technology Page 140

Page 142: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Figure 3: (a) sampling signal δ (t) ) (b) Spectrum δ (w)

Let gs(t) be the sampled signal. Its Fourier Transform Gs(w) isgiven by

Figure 4: (a) sampled signal gs(t) (b) Spectrum Gs(w)

To recover the original signal G(w):1. Filter with a Gate function, H2wm(w) of width 2wmScale it by T.

Geethanjali College of Engineering & Technology Page 141

Page 143: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Figure 5: Recovery of signal by filtering with a fiter of width 2wm

Aliasing Aliasing is a phenomenon where the high frequency components of the sampled signal interfere with each other because of inadequate sampling ws< 2wm.

Figure 6: Aliasing due to inadequate sampling

Aliasing leads to distortion in recovered signal. This is thereason why sampling frequency should be atleast twice thebandwidth of the signal.Oversampling In practice signal are oversampled, where fs is significantlyhigher than Nyquist’s rate to avoid aliasing.

Figure 7: Oversampled signal-avoids aliasing

Geethanjali College of Engineering & Technology Page 142

Page 144: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

PROGRAM:%This Program samples the signal exp(-1000|t|)f=input('enter the frequency of the signal')T=1/f;t=-T:T/f:T;xa=exp(-1000*abs(t));%Sampling the given signalfs=input('enter the sampling frequency')Ts=1/fs;n=-150:150;xd=exp(-1000*abs(n*Ts));subplot(4,1,1)plot(t,xa,'k')subplot(4,1,2)plot(t,xa,'k')hold onstem(n,xd,'k')gtext('Ts=0.2msec')hold off%Signal recovery through zero order hold((ZOH) circuitsubplot(4,1,3)stairs(n,xd,'k')title('Reconstructed signal through ZOH')%signal recovery through first order hold(FOH) circuitsubplot(4,1,4)plot(n,xd,'k')title('Reconstructed signal through FOH')

stairs(X,Y) plots the elements in Y at the locations specified in X.

If the sampling frequency is much higher than the Nyquist’s rate, FOH interpolation provides an acceptable reconstruction.

Geethanjali College of Engineering & Technology Page 143

Page 145: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

1. enter the frequency of the signal

f =1000

enter the sampling frequency

fs =5000

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

x 10-3

0

0.5

1

-150 -100 -50 0 50 100 1500

0.5

1

Ts=0.2msec

-150 -100 -50 0 50 100 1500

0.5

1Reconstructed signal through ZOH

-150 -100 -50 0 50 100 1500

0.5

1Reconstructed signal through FOH

2. enter the frequency of the signal

f=1000

enter the sampling frequency

fs =10000

Geethanjali College of Engineering & Technology Page 144

Page 146: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

x 10-3

0

0.5

1

-150 -100 -50 0 50 100 1500

0.5

1

Ts=0.1msec

-150 -100 -50 0 50 100 1500

0.5

1Reconstructed signal through ZOH

-150 -100 -50 0 50 100 1500

0.5

1Reconstructed signal through FOH

CONCLUSION: In this experiment the sampling theorem have been verified

VIVA QUESTIONS

1. Define sampling Theorem2. What is Aliasing Effect3. what is Under sampling4. What is Over sampling

Geethanjali College of Engineering & Technology Page 145

Page 147: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.No:15

REMOVAL OF NOISE BY AUTO CORRELATION/CROSS CORRELATION

Aim: Removal of Noise by auto correlation/cross correlation

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

%This program estimates the signal in the presence of noise%Generation of the signalf=input('enter the frequency')T=1/f;t=0:T/f:T;x1=sin(2*pi*f*t);%Two cycles of the signalx11=[x1 x1];%Generation of noise uniformly distributed between -1 and +1y1=2*rand(1,length(t))-1;%Sum of signal plus noisex2=x1+y1;%Periodic (signal+noise)x=[x2 x2];%Generation of Unit impulse sequencep=zeros(1,length(t));for i=1:length(t) if t(i)>=0 p(i)=1;endend%periodic impulse train (length same as signal+noise) y=[p p];%Finding the cross Correlation between signal+Noise and the impulse train%Finding the cross correlation without shifting the impulse trainz=sum(x.*y);%For each iteration of correlation, the impulse train is shifted towards%right, i.e. each element of y is made zero. for i=2:length(x) y(i)=0; z1=sum(x.*y); z(i)=z1; end t1=0:T/f:2*T+T/f;subplot(3,1,1)plot(t1,x11,'k')

Geethanjali College of Engineering & Technology Page 146

Page 148: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

title('The Periodic signal')subplot(3,1,2)plot(t1,x,'k')title('Signal+noise')subplot(3,1,3)plot(t1,z,'k')title('The estimated signal')

1. enter the frequencyf =1000

0 0.5 1 1.5 2 2.5

x 10-3

-1

0

1The Periodic signal

0 0.5 1 1.5 2 2.5

x 10-3

-2

0

2Signal+noise

0 0.5 1 1.5 2 2.5

x 10-3

-500

0

500The estimated signal

2. enter the frequencyf =2000

Geethanjali College of Engineering & Technology Page 147

Page 149: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

0 0.2 0.4 0.6 0.8 1 1.2

x 10-3

-1

0

1The Periodic signal

0 0.2 0.4 0.6 0.8 1 1.2

x 10-3

-2

0

2Signal+noise

0 0.2 0.4 0.6 0.8 1 1.2

x 10-3

-1000

0

1000The estimated signal

CONCLUSION: in this experiment, the signal is extracted from a noisy environment, by removing the noise.

VIVA QUESTIONS

1. Define Auto-Correlation2. Define Cross-Correlation3. What is the Difference Between Convolution& Correlation

Geethanjali College of Engineering & Technology Page 148

Page 150: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.No:16

EXTRACTION OF PERIODIC SIGNAL MASKED BY NOISE USING CORRELATION

Aim: To extract a periodic signal masked by noise using correlation.

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB Software.PROGRAM:- MATLAB Program to detect the periodic signal masked by noise using Auto Correlation &Cross Correlation method is performed. clc;clear all; close all;t=0:0.01:10;s=cos(2*pi*3*t)+sin(2*pi*5*t); % periodic signalfigure;subplot(2,1,1);plot(t,s);axis([0 10 -2 2]);xlabel(' t ---->'),ylabel(' amp ----> '); title('the periodic signal');L=length(t);n=randn(1,L); % noise signalsubplot(2,1,2);plot(t,n);xlabel(' t ---->'),ylabel(' amp ----> '); title('the noise signal');L=length(t);f=s+n; % received signalfigure;subplot(2,1,1);plot(t,f);xlabel(' t ---->'),ylabel(' amp ----> '); title('the received signal');rxx=xcorr(f,s,200);subplot(2,1,2);plot(rxx);title('the Correlator output');

Geethanjali College of Engineering & Technology Page 149

Page 151: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Geethanjali College of Engineering & Technology Page 150

Page 152: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Application:

CONCLUSION: In this experiment, the Extraction of periodic signal masked by noise using correlation have been verified .

VIVA QUESTIONS

1.What are the applications of Auto Correlation?2.State the properties of Auto Correlation function.

Geethanjali College of Engineering & Technology Page 151

Page 153: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP.No:17

VERIFICATION OF WIENER–KHINCHIN RELATION

AIM: verification of wiener– khinchin relation

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB/Scilab Software

The Wiener–Khinchin theorem (also known as the Wiener–Khintchine theorem and sometimes as the Wiener–Khinchin–Einstein theorem or the Khinchin–Kolmogorov theorem) states that the power spectral density of a wide-sense-stationary random process is the Fourier transform of the corresponding autocorrelation function.[1][2][3]

Continuous case:

Where

is the autocorrelation function defined in terms of statistical expectation, and where is the power spectral density of the function . Note that the autocorrelation function is defined in terms of the expected value of a product, and that the Fourier transform of does not exist in general, because stationary random functions are not square integrable.

The asterisk denotes complex conjugate, and can be omitted if the random process is real-valued.

Discrete case:

Where

and where is the power spectral density of the function with discrete values . Being a sampled and discrete-time sequence, the spectral density is periodic in the frequency domain.

Geethanjali College of Engineering & Technology Page 152

Page 154: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

PROGRAM:

clc;clear all; close all;t=0:0.1:2*pi;x=sin(2*t);subplot(3,2,1);plot(x);au=xcorr(x,x);subplot(3,2,2);plot(au);v=fft(au);subplot(3,2,3);plot(abs(v));fw=fft(x);subplot(3,2,4);plot(fw);fw2=(abs(fw)).^2;subplot(3,2,5);plot(fw2);

output:

Geethanjali College of Engineering & Technology Page 153

Page 155: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

CONCLUSION: In this experiment the Weiner-Khinchine Relation have been verified using MATLAB.

VIVA QUESTIONS

1.State Wiener-Khinchine Relation2.Define Power Spectral Density of a signal3.How to find the power of a signal from its Auto correlation function?4.Give the relation between Power and Power Spectral Density of a signal.

Geethanjali College of Engineering & Technology Page 154

Page 156: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXP18.

CHECKING A RANDOM PROCESS FOR STATIONARITY IN WIDE SENSE.

AIM: Checking a random process for stationarity in wide sense.

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB Software

Theory:

a stationary process (or strict(ly) stationary process or strong(ly) stationary process) is a stochastic process whose joint probability distribution does not change when shifted in time or space. As a result, parameters such as the mean and variance, if they exist, also do not change over time or position..

Definition: Formally, let Xt be a stochastic process and let

represent the cumulative distribution function of the joint distribution of Xt at times t1…..tk. Then, Xt is said to be stationary if, for all k, for all τ, and for all t1…..tk

Weak or wide-sense stationarity

A weaker form of stationarity commonly employed in signal processing is known as weak-sense stationarity, wide-sense stationarity (WSS) or covariance stationarity. WSS random processes only require that 1st and 2nd moments do not vary with respect to time. Any strictly stationary process which has a mean and a covariance is also WSS.

So, a continuous-time random processx(t) which is WSS has the following restrictions on its mean function

and autocorrelation function

The first property implies that the mean function mx(t) must be constant. The second property implies that the correlation function depends only on the difference between t1 and t2 and only needs to be indexed by one variable rather than two variables. Thus, instead of writing,

we usually abbreviate the notation and write

Geethanjali College of Engineering & Technology Page 155

Page 157: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

This also implies that the autocovariance depends only on τ = t1 − t2, since

Stationary and Non Stationary Random Process:A random X(t) is stationary if its statistical properties are unchanged by a time shift in the time origin.When the auto-Correlation function Rx(t,t+T) of the random X(t) varies with time difference T and the mean value of the random variable X(t1) is independent of the choice of t1,then X(t) is said to be stationary in the wide-sense or wide-sense stationary . So a continous- Time random process X(t) which is WSS has the following properties

1) E[X(t)]=μX(t)= μX(t+T)

2) The Autocorrelation function is written as a function of T that is

3) RX(t,t+T)=Rx(T)

If the statistical properties like mean value or moments depends on time then the random process is said to be non-stationary. When dealing wih two random process X(t) and Y(t), we say that they are jointly wide-sense stationary if each pocess is stationary in the wide-sense.

Rxy(t,t+T)=E[X(t)Y(t+T)]=Rxy(T).

//This program checks the random process Acos(wt+theta) for Stationarity, where the random variable involved is uniform

syms A w theta t k p=sym(2);rv=input('enter the random variable')a=input('enter the lower limit of the density of the variable')b=input('enter the upper limit of the density of the variable')density=1/(b-a);x=input('enter the random process')y= int(x,rv,a,b);x1= ((A^p)/p)*(cos(a*w*t+a*theta+w*k)+cos(w*k));y1=int(x1,rv,a,b);disp('The density of the random variable over(0,2*pi)is')disp(density)disp('Mean of the process is')disp(y)disp('The Autocorrelation function of the process is')disp(y1)

Geethanjali College of Engineering & Technology Page 156

Page 158: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

1. The process is x(t)=Acos(wt+theta), where ‘theta’ is a uniform random variable over (0,2*pi). enter the random variablerv =theta enter the lower limit of the density of the variablea =0enter the upper limit of the density of the variableb =6.2832enter the random process x = A*cos(w*t+theta) The density of the random variable over (0,2*pi)is 0.1592Mean of the process is0 The Autocorrelation function of the process is 2*A^2*cos (w*k)*pi Since, the mean of the process is constant and the Autocorrelation function of the process is independent of time and is a function of ‘k’, the process is stationary.

2.The process is x(t)=Acos(wt+theta), where ‘w’ is a uniform random variable over (0,2*pi).

//This program checks the random process Acos(wt+theta), where the random variable involved is uniformsyms A w theta t k p=sym(2);rv=input('enter the random variable')a=input('enter the lower limit of the density of the variable')b=input('enter the upper limit of the density of the variable')density=1/(b-a);x=input('enter the random process')y= int(x,rv);x_Mean=subs(y,rv,b)-subs(y,rv,a)x1= ((A^p)/p)*(cos(a*w*t+a*theta+w*k)+cos(w*k));y1=int(x1,rv);x_Autocorrelation=subs(y1,rv,b)-subs(y1,rv,a);disp('The density of the random variable over(0,2*pi)is')disp(density)disp('Mean of the process is')disp(x_Mean)disp('The Autocorrelation function of the process is')disp(x_Autocorrelation)

enter the random variable rv = w enter the lower limit of the density of the variable0a =0

Geethanjali College of Engineering & Technology Page 157

Page 159: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

enter the upper limit of the density of the variable2*pib =6.2832enter the random processx =A*cos(w*t+theta)x_Mean = sin(2*pi*t+theta)*A/t-A/t*sin(theta)The density of the random variable over(0,2*pi)is 0.1592Mean of the process issin(2*pi*t+theta)*A/t-A/t*sin(theta) The Autocorrelation function of the process issin(2*k*pi)*A^2/k Since the mean of the process is not independent of time, the given process is not stationary.

CONCLUSION: In this experiment the process of checking a random process for stationary in wide sense have been verified .

ADDITIONAL

Geethanjali College of Engineering & Technology Page 158

Page 160: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

EXPERIMENTS

EXP:1

To find mean and variance of a discrete random variable

AIM:To find amean and variance of a discrete random variable

EQUIPMENTS:PC with windows (95/98/XP/NT/2000).MATLAB Software

Theory:

Random Variable

The outcome of an experiment need not be a number, for example, the outcome when a coin is tossed can be 'heads' or 'tails'. However, we often want to represent outcomes as numbers. A random variable is a function that associates a unique numerical value with every outcome of an experiment. The value of the random variable will vary from trial to trial as the experiment is repeated.

There are two types of random variable - discrete and continuous.

A random variable has either an associated probability distribution (discrete random variable) or probability density function (continuous random variable).

Examples

1. A coin is tossed ten times. The random variable X is the number of tails that are noted. X can only take the values 0, 1…. 10, so X is a discrete random variable.

2. A light bulb is burned until it burns out. The random variable Y is its lifetime in hours. Y can take any positive real value, so Y is a continuous random variable.

Expected Value

The expected value (or population mean) of a random variable indicates its average or central value. It is a useful summary value (a number) of the variable's distribution.

Stating the expected value gives a general impression of the behaviour of some random variable without giving full details of its probability distribution (if it is discrete) or its probability density function (if it is continuous).

Two random variables with the same expected value can have very different distributions. There are other useful descriptive measures which affect the shape of the distribution, for example variance.

Geethanjali College of Engineering & Technology Page 159

Page 161: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

The expected value of a random variable X is symbolised by E(X) or µ.

If X is a discrete random variable with possible values x1, x2, x3, ..., xn, and p(xi) denotes P(X = xi), then the expected value of X is defined by:

where the elements are summed over all values of the random variable X. If X is a continuous random variable with probability density function f(x), then the expected value of X is defined by:

ExampleDiscrete case : When a die is thrown, each of the possible faces 1, 2, 3, 4, 5, 6 (the xi's) has a probability of 1/6 (the p(xi)'s) of showing. The expected value of the face showing is therefore:

µ = E(X) = (1 x 1/6) + (2 x 1/6) + (3 x 1/6) + (4 x 1/6) + (5 x 1/6) + (6 x 1/6) = 3.5

Notice that, in this case, E(X) is 3.5, which is not a possible value of X.

Variance

The (population) variance of a random variable is a non-negative number which gives an idea of how widely spread the values of the random variable are likely to be; the larger the variance, the more scattered the observations on average.

Stating the variance gives an impression of how closely concentrated round the expected value the distribution is; it is a measure of the 'spread' of a distribution about its average value.

Variance is symbolised by V(X) or Var(X) or

The variance of the random variable X is defined to be:

where E(X) is the expected value of the random variable X.

Notes

a. the larger the variance, the further that individual values of the random variable (observations) tend to be from the mean, on average;

b. the smaller the variance, the closer that individual values of the random variable (observations) tend to be to the mean, on average;

c. taking the square root of the variance gives the standard deviation, i.e.:

d. the variance and standard deviation of a random variable are always non-negative.

MATLAB PROGRAM:

clear all;

Geethanjali College of Engineering & Technology Page 160

Page 162: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

close all;x=[1 2 3 4 5 6];n=length(x)m = (1/n)*sum(x)v = (1/n)*(x-m)*(x-m)'

RESULTS:

n = 6

m =3.5000

v = 2.9167

VIVA QUESTIONS

1.Define a moment generating function of a discrete random variable?

2. .Define a moment generating function of a continuous random variable?3. Define a characteristic function of a discrete random variable?

4. .Define a characteristic function of a continuous random variable 5 what are the properties of the characteristic function of a discrete random variable?

EXP 2.

To find a moment generating function of a discrete random variable

Geethanjali College of Engineering & Technology Page 161

Page 163: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

AIM:To find a moment generating functionof a discrete random variable

EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Theory:

In probability theory and statistics, the moment-generating function of a random variable is an alternative specification of its probability distribution (however, note that not all random variables have moment-generating functions). Thus, it provides the basis of an alternative route to analytical results compared with working directly with probability density functions or cumulative distribution functions. There are particularly simple results for the moment-generating functions of distributions defined by the weighted sums of random variables.

In addition to univariate distributions, moment-generating functions can be defined for vector- or matrix-valued random variables, and can even be extended to more general cases.

The moment-generating function does not always exist even for real-valued arguments, unlike the characteristic function. There are relations between the behavior of the moment-generating function of a distribution and properties of the distribution, such as the existence of moments.

In probability theory and statistics, the moment-generating function of a random variableX is

wherever this expectation exists.

always exists and is equal to 1.

A key problem with moment-generating functions is that moments and the moment-generating function may not exist, as the integrals need not converge absolutely. By contrast, the characteristic function always exists (because it is the integral of a bounded function on a space of finite measure), and thus may be used instead.

More generally, where , an n-dimensional random vector, one

uses instead of tX:

Geethanjali College of Engineering & Technology Page 162

Page 164: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

The reason for defining this function is that it can be used to find all the moments of the distribution.[1] The series expansion of etX is:

Hence:

where mn is the nth moment.

If we differentiate MX(t) i times with respect to t and then set t = 0 we shall therefore obtain the ith moment about the origin, mi.

MATLAB PROGRAM:

clear all;close all;s=0;t=1;x=[1 2 3 4 5 6];p=[1/6 1/6 1/6 1/6 1/6 1/6];for i=1:6 s= sum(exp(t*x(i)).*p(i))enddisp(s)

RESULT: s = 0.4530

s = 1.2315

VIVA QUESTIONS

1.Define a random variable ?

2. How to define of a discrete random variable?3. Give one example of a continuous random variable?4. Define variance of a random variable?5 Expected value of 1?

DESIGNEXPERIMENTS

Geethanjali College of Engineering & Technology Page 163

Page 165: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

Experiment 1To Design Half wave rectifier

AIM:To find the input current flowing through the diode and output voltage.

EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Theory:

During the positive half-cycle ofthe input voltage, the diode is forward-biased for all

instantaneous voltages greater than thediode cut-in voltage, V . Current flowing through the

diode during the positive half-cycleproduces approximately a half sine wave of voltages

across the load resistor, To simplify our discussions, we will assume that the diode is ideal

and that the peak input voltage is always much larger than the V of the diode. Hence, we

assumethat the zero of the rectified voltage coincides with the zero of the input voltage. On

the negativehalf-cycle of the input voltage, the diode is reverse-biased. Ignoring the reverse

leakage currentof the diode, the load current drops to zero, resulting in zero load voltage

(output voltage).

Design Problem.

A battery charging circuit is shown in Figure 9.10. The battery voltage is VB= 118. V. The source voltage is vs(t)=18 sin120πtV and the resistance is R = 100 Ω. Use MATLAB (a) to sketch the input voltage, (b) to plot the current flowing through the diode, (c ) to calculate the conduction angle of the diode, and (d) calculate the peak current. (Assume that the diode is ideal.)

Matlab code: diary ex9_5.dat% Baltery charging circuitperiod = 1/60; period2 = period*2;inc =period/100;npts = period2/inc;r=100;vb = 11.8;t = [];for i = 1:npts

Geethanjali College of Engineering & Technology Page 164

Page 166: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

t(i) = (i-1)*inc;vs(i) = 18*sin(120*pi*t(i)); if vs(i) >vbidiode(i) = (vs(i) -vb)/r; elseidiode(i) = 0; endendsubplot(211), plot(t,vs)%title('Input Voltage')xlabel('Time (s)')ylabel('Voltage (V)')text(0.027,10, 'Input Voltage')subplot(212), plot(t,idiode)%title('Diode Current')xlabel('Time (s)')ylabel('Current(A)')text(0.027, 0.7e-3, 'Diode Current')% conduction angletheta1 = asin(vb/18); theta2 = pi - theta1;acond = (theta2 -theta1)/(2*pi)% peak currentpcurrent = (18*sin(pi/2) - vb)/r% pcurrent = max(idiode)Diary

results:acond = 0.2724pcurrent =0.0620

Conclusion: The current flowing through the diode and output voltage are calculated and observed.

ViVa Questions:

1. What is Rectifier?

2. What is half wave Rectifier?

3. What is ripple?

4. What is the ripple factor of half wave rectifier?

5. What is the Efficiency of half wave rectifier?

Experiment 2

Geethanjali College of Engineering & Technology Page 165

Page 167: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

To Design Zener break down characteristics

AIM:To find the Zener break down characteristics.

EQUIPMENTS: PC with windows (95/98/XP/NT/2000). MATLAB Software

Theory:

A zener diode is a special kind of diode which allows current to flow in the forward direction

in the same manner as an ideal diode, but will also permit it to flow in the reverse direction

when the voltage is above a certain value known as the breakdown voltage, "zener knee

voltage" or "zener voltage".

The device was named after Clarence Zener, who discovered this electrical property.

Many diodes described as "zener" diodes rely instead on avalanche breakdown as the

mechanism. Both types are used. Common applications include providing a reference

voltage for voltage regulators, or to protect other semiconductor devices from momentary

voltage pulses.

Design Problem.

A zener diode voltage regulator circuit has the following data: 30 ≤ VS ≤ 35V; RL = 10K, RS = 2KVZ = -20+0.05I for -100 mA ≤ I < 0 Use MATLAB to (a) plot the zener breakdown characteristics, (b) plot the loadline for VS = 30V and VS = 35 V, (c) determine the output voltage when VS = 30V and VS = 35V

Matlab code:% Zener diode voltage regulator vs1 = -30; vs2 = -35; rl =10e3; rs = 2e3;i = -50e-3: 5e-3 :0; vz = -20 + 0.05*i; m = length(i); i(m+1) = 0; vz(m+1) = -10; i(m+2) = 0; vz(m+2) = 0; % loadlinesvt1 = vs1*rl/(rl+rs); vt2 = vs2*rl/(rl+rs); rt = rl*rs/(rl+rs);

Geethanjali College of Engineering & Technology Page 166

Page 168: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

l1 = vt1/20; l2 = vt2/20; v1 = vt1:abs(l1):0; i1 = (vt1 - v1)/rt; v2 = vt2:abs(l2):0; i2 = (vt2 - v2)/rt; % plots of Zener characteristics, loadlinesplot(vz,i,'b',v1,i1,'r',v2,i2,'g') axis([-30,0,-0.03,0.005]) title('Zener Voltage Regulator Circuit') xlabel('Voltage (V)') ylabel('Current (A)') text(-19.5,-0.025,'Zener Diode Curve') text(-18.6,-0.016, 'Loadline (35 V Source)') text(-14.7,-0.005,'Loadline (30 V Source)') % output voltage when vs = -30v ip1 = (vt1 + 20)/(rt + 0.05) vp1 = vt1 - rt*(vt1+20)/(rt + 0.05) % output voltage when vs = -35v ip2 = (vt2 + 20)/(rt + 0.05) vp2 = vt2 - rt*(vt2+20)/(rt + 0.05)

Results:ip1 = -0.0030vp1 = -20.0001ip2 = -0.0055vp2 = -20.0003

Conclusion: Zener break down characteristics observed.

ViVa Questions:

1. Zener Diode operates in which region?

2. What is the application of zener diode?

3. What is Voltage regulator?

4. Load Regulation?

OPEN EXPERIMENTS

Geethanjali College of Engineering & Technology Page 167

Page 169: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

1. IMPLEMENTATION OF DECIMATION PROCESS

AIM: To implementation of decimation of given sequence by factor M.

EQUIPMENTS: Operating System - Windows XP Constructor - Simulator Software - CCStudio 3 & MATLAB 7.5

THEORY :

Decimation is the process of reducing the sampling frequency of a signal to a lower sampling frequency that differs from the original frequency by an integer value. Decimation also is known as down-sampling. The lowpass filtering associated with decimation removes high-frequency content from the signal to accommodate the new sampling frequency.

Decimation is useful in applications in which the Nyquist frequency of a signal is much higher than the highest frequency of the signal. Decimation filters help you remove the excess bandwidth and reduce the sampling frequency of the signal. Decimation filters also help you reduce the computational resources required for processing and storing the signal. During the analog-to-digital (A/D) conversion process, decimation filters also can reduce the variance of quantization noise in a signal and maintain the signal power, thus improving the signal-to-noise ratio (SNR).

The following figure shows a typical M-fold decimation filter, where M is the integer value by which you want to decrease the sampling frequency. This filter contains a lowpass FIR filter H(z). This lowpass FIR filter is an anti-aliasing filter followed by anM-fold decimator. The decimator passes every Mth sample and discards the other samples. After this operation, the decimation filter changes the sampling frequency fs of the input signal x(n) to a new sampling frequency fs/M. The decimation filter then returns an output signal y(n) with the new sampling frequency. equation for decimation

To prevent aliasing, this system uses the lowpass filter H(z) before the M-fold decimator to suppress the frequency contents above the frequency fs/(2M), which is the Nyquist frequency of the output signal. This system produces the same results as an analog anti-aliasing filter with a cutoff frequency of fs/(2M) followed by an analog-to-digital (A/D) converter with a sampling frequency of fs/M. Because the system shown in the figure above is in the digital domain, H(z) is a digital anti-aliasing filter.

Geethanjali College of Engineering & Technology Page 168

Page 170: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

PROGRAM: (Without inbuilt function)

clc; close all; clear all; N=input(' input length of the sine seq'); M= input(' down sampling factor'); fi= input(' input signal freq'); % generation of sine sequence t=0:N-1; m=0:N*M-1; x=sin(2*pi*fi*m); %generate the down sample signal Y=x([1:m:length(x)]); Y([1:M:length(x)])=x; Subplot(2,1,1); Stem(n,x(1:M)); Title(' input sequence'); Xlable('time'); Ylabel('amplitude'); Subplot(2,1,2); Stem(n, Y); Title([' output sequence ',num2str(m)]); Xlable('time'); Ylabel('amplitude'); %Decimate a signal by a factor of four by using inbuilt function clc; clear all; close all; t = 0:.00025:1; % Time vector x = sin(2*pi*30*t) + sin(2*pi*60*t); y = decimate(x,4); subplot(1,2,1); stem(x(1:120)), axis([0 120 -2 2]) % Original signal title('Original Signal') subplot(1,2,2); stem(y(1:30)) % Decimated signal title('Decimated Signal') OUTPUT :

Geethanjali College of Engineering & Technology Page 169

Page 171: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

RESULT: The decimator for a given sequence is observed for chosen factor M. Hence the theory and practical is verified.

VIVA QUESTION:

1. What is the importance of decimation for a given signal/sequence?

2. What do you mean Aliasing? What is the condition to avoid aliasing for sampling?

3. How does poly phase filtering save computations in a decimation filter?

4. Give any practical application of decimation?

5. Which signals can be down sampled?

6. What happens if I violate the Nyquist criteria in down sampling or decimating?

7. Can we do decimate in multiple stages?

8. What are "decimation" and "downsampling"?

9. What is the "decimation factor"?

Geethanjali College of Engineering & Technology Page 170

Page 172: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

2. IMPLEMENTATION OF INTERPOLATION PROCESS

AIM: To implementation of interpolation for given sequence by factor L.

EQUIPMENTS: Operating System - Windows XP Constructor - Simulator Software - CCStudio 3 & MATLAB 7.5

THEORY: The process of increasing the sampling rate is called interpolation. Interpolation is upsampling followed by appropriate filtering. obtained by interpolating , is generally represented as: The simplest method to interpolate by a factor of L is to add L-1 zeros in between the samples, multiply the amplitude by L and filter the generated signal, with a so-called anti-imaging low pass filter at the high sampling frequency.

PROGRAME: Clc; Close all; Clear all; N=input(„ input length of the sine seq‟); L= input(„ up sampling factor‟); Fi= input(„ input signal freq‟); t=0:N-1; X=sin(2*pi*fi*t); Y=zeros(1,L*length(x)); Y([1:L:length(x)])=x; Subplot(2,1,1); Stem(n,x); Title(„ input sequence‟); Xlable(„time‟); Ylabel(„amplitude‟); Subplot(2,1,2); Stem(n, Y(1:length(x)); Title([„ output sequence „,num2str(L)]); Xlable(„time‟); Ylabel(„amplitude‟);

RESULT: The interpolation of given sequence is observed for factor value L. Hence the theory and practical are verified.

Geethanjali College of Engineering & Technology Page 171

Page 173: BS_Manual   modified.doc

Basic Simulation Lab Department of ECE

VIVA QUESTION:

1. How does polyphase filtering save computations in an interpolation filter?

2. Why do we need I&Q signals?

3. What is Interpolation and decimation filters and why we need it?

4. What are "upsampling" and "interpolation"?

5. Why interpolate is needed for any signal/sequence?

6. What is the "interpolation factor"?

7. Which signals can be interpolated?

8. Can interpolate will happens in multiple stages? If yes give reason?

9. Give any example of a FIR interpolator?

Geethanjali College of Engineering & Technology Page 172