Why can't I get convolution to work fine in MATLAB?

Convoying signals in MATLAB gives unexpected results every time. Take, for example, the following code, in which I am trying to check a function rect

against itself:

clc

clear all

x=-5:.01:5;

y=rectangularPulse(x);

C=conv(y,y);

plot(C)

      

The triangle function is correct, however it should be centered on 0, not 1000, and the amplitude should be 1, not 100. I'm sure this is just a misunderstanding of how the conv()

MATLAB function works ; if there is a way to do this that will create a triangle function that gos -1 to 1 with an amplitude of 1, please let me know how.

+3


source to share


1 answer


Part of the confusion here is that the signal y

you are dealing with is discrete, with its samples spaced 0.01

in x

. It also CONV

seems to be pulling a double function for polynomial multiplication. From the help:

If u and v are vectors of polynomial coefficients, their convolution is equivalent to multiplying two polynomials.

Convolution involves calculating the area below intersecting curves when one of them slides. CONV

does a discrete version of this by simply multiplying the overlapping sample points and essentially assuming a value of 1 for the spacing between samples (i.e. the width of the rectangular stripes approximating the area under the curve). To get true convolution, you must scale the resulting approximate area by the sampling distance 0.01

. Also, you will want to extract the center portion of the convolution using an argument 'same'

, so that you can plot the results versus x

, for example:



C = 0.01.*conv(y, y, 'same');
plot(x, C);

      

enter image description here

+2


source







All Articles