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)
Show older comments
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
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?
Accepted Answer
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
0 Comments
More Answers (0)
See Also
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!