Plot convolution of continuous signal (2024)

27 views (last 30 days)

Show older comments

Michelle Watson on 23 Jun 2020

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal

Commented: Jiahao CHANG on 23 Jun 2020

Open in MATLAB Online

I am trying to plot the convolution of 2 continuous signals. My figure has the correct shape, but the values are very large.

t= -2.5:.001:3.5;

he1 = (1-t).*(heaviside(t)-heaviside(t-1));

he2 = (t).*(heaviside(t+2)-heaviside(t-2));

m=conv(he1,he2);

subplot(224); plot(m); grid on;

xlabel('t'); ylabel('h_s(t), series (conv integral)');

When I try to plot

subplot(224); plot(t, m); grid on;

Error: Error using plot. Vectors must be the same length.

When I try to plot

subplot(224); plot(t, m(t)); grid on;

Error: Array indices must be positive integers or logical values.

When I try

^ Define functions @t, I get the same plot as below

Plot convolution of continuous signal (2)

Problem: bottom right figure.

How do I get my convolution plot to have the same values as the original functions?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

Jiahao CHANG on 23 Jun 2020

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#answer_455755

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#answer_455755

Open in MATLAB Online

Hi Michelle,

Your code

t= -2.5:.001:3.5;

he1 = (1-t).*(heaviside(t)-heaviside(t-1));

he2 = (t).*(heaviside(t+2)-heaviside(t-2));

m=conv(he1,he2);

subplot(224); plot(m); grid on;

xlabel('t'); ylabel('h_s(t), series (conv integral)');

gives you the wrong value of 't' because you didn't define the x vector so Matlab will display the length of the variable 'm'.

subplot(224); plot(t, m); grid on;

goes wrong because t and m are not in the same length. (t is 1*6001 and m is 1*12001)

So i suggest you to use

t1= -2.5:6/length(m):3.5-6/length(m);

And the code should be like

t= -2.5:.001:3.5;

he1 = (1-t).*(heaviside(t)-heaviside(t-1));

he2 = (t).*(heaviside(t+2)-heaviside(t-2));

m=conv(he1,he2);

t1= -2.5:6/length(m):3.5-6/length(m);

subplot(224); plot(t1,m); grid on;

xlabel('t'); ylabel('h_s(t), series (conv integral)');

Try this and tell me whether it is want you want;)

2 Comments

Show NoneHide None

Michelle Watson on 23 Jun 2020

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#comment_909970

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#comment_909970

Thanks for the information!

Yes the x-axis values are fixed. However, I'd like the y-axis to have the proper values as well. See the Desmos screencap below:

Plot convolution of continuous signal (5)

Also, could you elaborate on why exactly what your t1 variable does? Does it scale the length of m to fit the t values I set? If so, what is the purpose of the 6/length(m)? Why 6?

Is it possible to just have the convolution (m) already be scaled according to the signals that I input? (he1, he2)?

Why can he1 and he2 be plotted as a function of t? But when I try to plot m (which is a function of he1 which is a function of t), it gives these errors?

If this is not possible, how do I go about scaling m? Would I need to scale each value of me at each t value?

Thanks again!

Jiahao CHANG on 23 Jun 2020

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#comment_910033

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/553105-plot-convolution-of-continuous-signal#comment_910033

Open in MATLAB Online

For the y-axis value, if you want to achieve the same equation as you shown in this picture, setting variables by directly using these equations is easier.

Yes, t1 is a variable scale the length of m so that they could match. 6 is because your minimum time is -2.5 and max is 3.5 so the total time is 3.5-(-2.5)=6. In order to match the same length of m, you need to divide your time into length(m) pieces, each piece(or step) equals to 6/length(m). Because you already set the last number equals to 3.5, so maybe it is better to change that line as

t1= -2.5:6/(length(m)-1):3.5;

I'm not sure whether I understand this question or not. The length of convolution(m) equals to the length of he1+he2-1. You can see some examples of conv here.

he1 and he2 can plotted as a function of t is because for each t(i), you have and only have one he1(i) to match. However m has more values than he1 and t so that they can't match because the length are different. And Im not sure whether this is meaningful.

To understand this, you should know that the time you put

t= -2.5:.001:3.5;

is a discrete not continious.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Signal ProcessingSignal Processing ToolboxSpectral AnalysisSpectral Measurements

Find more on Spectral Measurements in Help Center and File Exchange

Tags

  • convolution
  • continuous

Products

  • MATLAB Coder

Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Plot convolution of continuous signal (7)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Plot convolution of continuous signal (2024)

References

Top Articles
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6448

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.