8

Click here to load reader

Informe 2 senales

Embed Size (px)

DESCRIPTION

Programa en matlab sobre la convolución continua y discreta.

Citation preview

Page 1: Informe 2 senales

Abstract — this paper presents the development and creation of a Matlab program which purpose is to convolve an incoming signal with a specific system or transference signal, the program receives all kind of discreet incoming and transference signals and some specific combination of continuous signals. Also the program is designed for an easy use by any user, so the graphic interface is quite simple and wad made using a graphic user interface.

Index Terms—MATLAB, convolution, discreet signal, continuous signal.

I. INTRODUCTION

Convolution is a mathematical operator that modifies an incoming signal passing through system, it gives a new signal which represents the overlap area between the incoming and transference signal. Convolution has application in many fields such as digital image processing, analytical chemistry, electrical and electronic engineering, physics, etc. This, because convolution allows to get the response of a system in face of an external stimulus.

MATLAB is a powerful software which allows manipulation of matrices, creating user interfaces, plotting functions and data, and implementing algorithms. Is very used in the industry and in the academic field also in engineering.

This project uses the concept of convolution and the functionality of MATLAB for building a graphic user interface, easy to use and concordant with the rules for calculate the results of changing a signal.

II. THEORETICAL FRAMEWORK:

For developing the program the first step was learning the syntax and semantic of MATLAB, also were needed knowledge about convolution, the behavior of an incoming signal through a specific

system, keeping in mind that process for executing a convolution with a discreet signal compared with the continuous one is almost equal except for the

last step, the convolution gives a resulting signal y(t) or y[n] from the passing of the incoming signal x(t) or x[n] through the system (transference signal h(t) or h[n] ). For making a convolution is important to these steps:

1) Change the independent variable: the independent variables are changed for other ones, in this case k and T.

N Kt T

2) Invert the signal: for this is necessary make an independent variable operation (inversion) using the ordinate axis as pivot. It is important to keep in mind that any of the signals could be inverted but if the inversion is made in one signal, the other cannot be inverted.

h(T) h (-T) x(T) x(-T) or h[k] h[-k] x[k] x[-k]

3) Displace the transference signal: to avoid execute unnecessary operations from -∞ to ∞, the transference signal is displaced until it last datum signal matches with the first one of the incoming signal or vice versa if the incoming signal is inverted.

Rivero, Jesús. Muñoz, Ricardo y Pardo, Josh.

{jrivero.jesus,riricardo96, joshpc}@hotmail.com, gmail.com, rocketmail.com

Universidad Autónoma de Occidente

Matlab user interface for making discreet and continuous convolution

Page 2: Informe 2 senales

h[n – k] ; h(t - T) or x[n – k] ; x(t - T)

4) Make the convolution: as y(t) and y[n] have to be defined between -∞ and ∞ the integral is made with those limits.

The integral has to be fractionated in the quantity that transference and incoming signals require.

Y(t) = x(t) * h(t) = ∫−∞

[ x ( t ) ] [h ( t−T ) ]dt

There are two methods for solving the sum that gives y[n], graphical method and sliding method. As MATLAB does not understand easily images, in the code is used the second method, when the three first steps are done it consists in displace the inverted signal from the matching of the last datum of the inverted signal with the first datum of the other signal until the signals leaves to interpolate.

Y[n] = x[n]* h[n] = ∑k=−∞

( x [k ]) (h [ n−k ])

III. GRAPHIC USER INTERFACE DEVELOPMENT

In order to give to users an easy form of interaction with the software, GUIDE of Matlab was used for designing the aesthetic part of the program, so the user will communicate with the program by clicking buttons and writing with the keyboard. In figure 1 it's notorious the organization of the graphic user interface, at top left is the area designated to the discrete signals, there are four spaces to write, in h[n] Vector and x[n] EditTexts the user can introduce the transference function vector of the system and the input signal vector, and in the spaces at right the user should write what position in the horizontal axis occupies the first number from left to right, this with the purpose of creating the n vector for each vector(transference function and input signal).In bottom left part of the GUI is the area of continuous signals, there is a PopUpMenu where user can choose three options of making a convolution, first is the convolution having a transference function of a rectangular function and an input signal of one period of sine function. Second option is the convolution between a square

input signal and a ramp function for the transference signal. And the last option is for the operation between a rectangular function input signal and a ramp transference function.In the right side of the GUI are three Axes where user will see transference function, input signal and the result of the convolution in both cases, discreet and continuous signals.

For both kind of signals the user can see the

process of the convolution because in the Axes space the program shows the animation of the operations that the transference signal does, mirroring and shifting.

IV. CONVOLUTION CODE EXPLANATION

For the discreet signal firstly the inputs are read in form of text, then the numbers are separated with strsplit, a MATLAB command, after that the variables are converted to numbers.Having the value of the left limit of the vectors are created the n vectors of h[n] and x[n]. Also the n vector of the resulting signal is found by knowing that the length of that signal is the sum of the lengths of the transference function and the input signal minus one.Therefore both vectors were completed with zeros so they would be of the same length. Later the resulting vector y[n] is created and filled with a number of zeros equal to the length of the vector that had been declared. Afterward, the convolution is made by using a for loop, where the indexes of the y vector were modified with the following algorithm:

y(i)=y(i)+X(j)*H(i-j+1);

This means that each position of the y matrix is summed with the product between values in a specific index in X vector and the values in indexes in the H vector that change in a

Figure 1. Graphic user interface of the program

Page 3: Informe 2 senales

different way that the index in y. Is important to say that before the convolution algorithm is established an if conditional that avoid having an index with zero or negative indexes.

For the continuous signal the convolution as is explained in the theoretical framework an integral. So for this, firstly is declared for each of the three cases a function that is the product between the input signal and the transference function. Also are defined variables that are the time domain, that is to say the horizontal axis values of the resulting function.An analysis of each case was made, so in the program the functions were integrated in limits established by programmers. After the integrals, those functions had symbolic values, so they were replaced by the time domain. For plotting the resulting signal the horizontal concatenation was used, because the process of integration had been made for specific parts in which the limits were different. So all parts of the resulting signal were concatenated and the distinct time domainswere too.

V. ANIMATION CODE EXPLANATION

For discreet signals once defined the vectors for x[n] h[n] and y[n] the next step is plotting them, to begin h[n] is mirrored and redrawn while x[n] remained in the same position. A for loop was created with a domain from one to y[n] length and inside that another loop of the same kind was created with a domain from one to the length of x[n]. This was made with the purpose of plotting h[n] while it was shifted and at the same time with stem command in MATLAB the resulting signal of the convolution is graphed.

In continuous signals the process of mirroring and shifting h[n] is very similar, the indexes of the function vector is moved along horizontal axis. The different thing is the convolution plotting, because in this case the animation is made after the result of convolution is complete, so the program has to go over the indexes of the convolution vector and draw the values by using plot command in MATLAB.

VI. TESTING THE PROGRAM

For showing the results of the program some data is going to be introduced in the discreet part of the program, after that is going to be demonstrated one of the cases of the continuous convolution.

In table 1 it are the h[n] and x[n] vectors that are going to be put in the program, also there is the vector that should be the result of the convolution.

x[n] h[n] y[n]

(0,0.5,2,0) (0,1,1,1,0) (0,0,0.5,2.5,2.5,2,0,0,0)

Table 1: Testing values of h[n], x[n] and y[n]

In figure 2 is the resulting y[n] signal in the MATLAB program.

Figure 3. Transference function and input signal

Page 4: Informe 2 senales

For testing the continuous signal convolution first should be analyzed mathematically the operation in one of the cases in the program.In figure 3 are the graphs of both, the input signal and the transference function with a change of variable, so [n] was replaced by [τ].

Now in figure 4 is mirrored h[tau] signal and then shifted to a t position.

Then for five cases, depending of the position of the h[tau] function, the convolution results will be different. So for each case the analysis is going to depend of the limits in the function.Case I:In figure 5 is the representation of the movement of the right limit of the transference function from infinite to zero.

Here is not a result in the convolution because all the product in this range is zero.Case II:Now it begin to exist an area different of zero between the transference function and the input signal as is visible in the figure 6.The range of tau for this case is from zero to T, and the integral of convolution will be as in the following equation.

∫0

t

(1 ) (−tau+t )dtau=12

t 2

Case III:In this case the area is formed from zero to the value T of tau(horizontal axis), so the limits are different. The domain of tau is from T to 2T. The area between curves is seen in figure 7.

The integral for this case will be:

∫0

t

(1 ) (−tau+t )dtau=tT −T 2

2Case IV:

Figure 6. Tranference function and input

signal in the second case.

Figure 7.

Tranference function and input signal in the third case.

Figure 4.

Mirrored and shifted transference signal

Figure 5. Graphic representation of the transference function and inut signal.

Page 5: Informe 2 senales

Here the area can be taken from the left limit of the transference function to the value of T of tau as is notorious in figure 8.

The integral for this case will be:

∫t−2 T

T

(1 ) (−tau+t ) dtau=−t2

2+ tT +3

2T2

Case V:Again there won't be any area between the functions (see figure 9) so the convolution result will be zero.

Putting all results as one function a plot can be done, as is visible in figure 10.

Now in the figure 10 is the resulting signal in the program.

The difference are the values of the -y axis and -x axis, this is because MATLAB can not plot symbolic values, so in the program is established that T is equal to two.

VII. CONCLUSIONS

When trying to create algorithms to make the discreet variable convolution was essential to consider the use of loops for going over the values of the matrix and vectors.

MATLAB is not able to make a symbolic representation of a function, neither of doing a symbolic convolution.

Figure 8. Tranference function and input signal in the

fourth case.

Figure 10. Convolution result.

Figure 5. Graphic representation of the transference function and inut signal.

Figure 9. Tranference function and input signal in the

fifth case.