I need to scale the axes of a convolution function after plotting successive convolutions of x with itself. How do I scale the x axis for each so it has the correct support and how do I scale the convolutions to show that they are density functions?

20 views (last 30 days)
x=ones(1,20);
con0=conv(x,x);
con1=conv(x,con0);
figure(1);
plot(con0);
figure(2);
plot(con1);
Thanks in advance!
  2 Comments
Rik
Rik on 4 Feb 2020
Edited: Rik on 4 Feb 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
After every convolution the number of elements changes. Is this intentional?
If you use plot with only one input it will use the index as the x-value, so if you want a different axis you can simply supply an x-scale that suits you.
By 'showing that they are density distributions' do you mean they should be scaled to an area of 1?
GS25
GS25 on 4 Feb 2020
Thanks for your assistance. I'll take a look for next time.
The change in number of elements is intentional, I want to convolve 10 times, what I posted was a sample for the first two.
Yes that is exactly it, I need to find a way to scale the plot to an area of 1.
Thank you Rik.

Sign in to comment.

Accepted Answer

Rik
Rik on 4 Feb 2020
Something like the code below should be close to what you want. Addapt as needed.
y=ones(1,20);
N=10;
output=cell(N,1);
output{1}=conv(y,y);
for n=2:N
output{n}=conv(y,output{n-1});
end
figure(1);clf(1)
%determine number of subplots
a=floor(sqrt(N));a=max(a,1);
b=ceil(N/a);
for n=1:N
subplot(a,b,n)
con=output{n};
x=linspace(0,1,numel(con));
con=con/trapz(x,con);%scale to unit area
plot(x,con);
title(sprintf('iteration %d',n))
axis([min(x) max(x) 0 5])
end

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!