<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The conv function and implementation tradeoffs</title>
	<atom:link href="http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/</link>
	<description>Steve Eddins manages the Image &#38; Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.</description>
	<lastBuildDate>Fri, 10 Feb 2012 18:55:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22412</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 04 Dec 2009 18:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22412</guid>
		<description>Brad&#8212;You and I are thinking about the conv function very differently.  If I understand your comment, you are thinking of conv as an approximation to continuous-time convolution.  I think of conv as implementing discrete-time convolution.  It does this exactly; there are no approximations involved (other than the normal floating-point round-off issues).  I&#039;ve used discrete-time convolution about a gazillion times for signal and image processing in my work, and I don&#039;t think I&#039;ve ever used it to simulate or approximate continuous-time convolution.  The FFT-based method here is mathematically equivalent to discrete-time convolution, so there are no approximation issues there.</description>
		<content:encoded><![CDATA[<p>Brad&mdash;You and I are thinking about the conv function very differently.  If I understand your comment, you are thinking of conv as an approximation to continuous-time convolution.  I think of conv as implementing discrete-time convolution.  It does this exactly; there are no approximations involved (other than the normal floating-point round-off issues).  I&#8217;ve used discrete-time convolution about a gazillion times for signal and image processing in my work, and I don&#8217;t think I&#8217;ve ever used it to simulate or approximate continuous-time convolution.  The FFT-based method here is mathematically equivalent to discrete-time convolution, so there are no approximation issues there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22395</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Fri, 04 Dec 2009 00:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22395</guid>
		<description>one practical issue you might want to point users to is that when using conv if the data is not sampled at a high enough resolution then huge rounding errors can occur due to the numerical intergraton used in computing conv.  I havent tested to see if the fft method does the same but it probably does.  I usually interpolate the data by a factor of at least 4 before performing the conv function.</description>
		<content:encoded><![CDATA[<p>one practical issue you might want to point users to is that when using conv if the data is not sampled at a high enough resolution then huge rounding errors can occur due to the numerical intergraton used in computing conv.  I havent tested to see if the fft method does the same but it probably does.  I usually interpolate the data by a factor of at least 4 before performing the conv function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22312</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 10 Nov 2009 12:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22312</guid>
		<description>Francisco&#8212;Cache locality is always important, and changes in cache locality can certain change the location of the cross-over point in comparing the two algorithms.  It won&#039;t change the overall scaling, though.

Premature optimization is optimizating code before you know it is producing the correct answer, or before you know the code is actually a performance bottleneck.</description>
		<content:encoded><![CDATA[<p>Francisco&mdash;Cache locality is always important, and changes in cache locality can certain change the location of the cross-over point in comparing the two algorithms.  It won&#8217;t change the overall scaling, though.</p>
<p>Premature optimization is optimizating code before you know it is producing the correct answer, or before you know the code is actually a performance bottleneck.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francisco</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22309</link>
		<dc:creator>Francisco</dc:creator>
		<pubDate>Tue, 10 Nov 2009 03:03:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22309</guid>
		<description>Does caching play a role in the speed of conv vs. fft_conv? It would seem that a clever order of multiplications would increase cache locality greatly in the conv function. 

If not, do you even need to take cache locality into consideration for MATLAB, or is it just &quot;premature optimization&quot;?</description>
		<content:encoded><![CDATA[<p>Does caching play a role in the speed of conv vs. fft_conv? It would seem that a clever order of multiplications would increase cache locality greatly in the conv function. </p>
<p>If not, do you even need to take cache locality into consideration for MATLAB, or is it just &#8220;premature optimization&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22292</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Thu, 05 Nov 2009 16:01:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22292</guid>
		<description>If you look towards the end of the fftfilt program, you will see that there&#039;s a check to see if the inputs are real, an if so, to remove the imaginary part of the output, since it is only round-off.  One of many things to do so users don&#039;t get surprised.

--Loren</description>
		<content:encoded><![CDATA[<p>If you look towards the end of the fftfilt program, you will see that there&#8217;s a check to see if the inputs are real, an if so, to remove the imaginary part of the output, since it is only round-off.  One of many things to do so users don&#8217;t get surprised.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22287</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 03 Nov 2009 22:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22287</guid>
		<description>Mark&#8212;No problem about nextpow2.  I&#039;ve always thought that function name was confusing, and I usually look at the help for it whenever I use it.

About FFT complexity - yes, MATLAB uses O(L log L) algorithms for all sizes.  Running time is fastest for powers of two (the constant of proportionality is smallest), but time scales with (L log L) for composite and even for prime L.</description>
		<content:encoded><![CDATA[<p>Mark&mdash;No problem about nextpow2.  I&#8217;ve always thought that function name was confusing, and I usually look at the help for it whenever I use it.</p>
<p>About FFT complexity &#8211; yes, MATLAB uses O(L log L) algorithms for all sizes.  Running time is fastest for powers of two (the constant of proportionality is smallest), but time scales with (L log L) for composite and even for prime L.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Andrews</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22286</link>
		<dc:creator>Mark Andrews</dc:creator>
		<pubDate>Tue, 03 Nov 2009 21:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22286</guid>
		<description>Well, it would help if I read the documentation, wouldn&#039;t it? I thought nextpow2 returned the number 2^n, not the exponent n. My apologies.</description>
		<content:encoded><![CDATA[<p>Well, it would help if I read the documentation, wouldn&#8217;t it? I thought nextpow2 returned the number 2^n, not the exponent n. My apologies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Andrews</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22285</link>
		<dc:creator>Mark Andrews</dc:creator>
		<pubDate>Tue, 03 Nov 2009 21:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22285</guid>
		<description>Just some minor points, but I think

&lt;pre&gt;
K = 2^nextpow2(L);
&lt;/pre&gt;

should be

&lt;pre&gt;
K = nextpow2(L);
&lt;/pre&gt;

otherwise K is enormous :-)

Are you sure that the complexity of the FFT is O(L log L) regardless of L? I thought this was a lower bound for L a power of 2.</description>
		<content:encoded><![CDATA[<p>Just some minor points, but I think</p>
<pre>
K = 2^nextpow2(L);
</pre>
<p>should be</p>
<pre>
K = nextpow2(L);
</pre>
<p>otherwise K is enormous :-)</p>
<p>Are you sure that the complexity of the FFT is O(L log L) regardless of L? I thought this was a lower bound for L a power of 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22283</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 03 Nov 2009 19:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22283</guid>
		<description>To all&#8212;After almost four years of writing this blog, I still have no ability to predict which topics will draw reader comment!  ;-)

Peter&#8212;Most the comments people attempt to post here are desperate queries for help with homework or a graduate school research project (I don&#039;t let those through), so yours is admirably on topic.  ;-)

Your suggestion is a good one.  We can look into making some changes so that imfilter does not need to pad.  Just to set your expectations, though ... the feature change deadline for R2010a was some time ago, and we&#039;re already working on R2010b.

Jeremy and Chris&#8212;I tend to think of circular convolution and periodic boundary conditions as being basically the same issue, and it is not a reason to avoid using the DFT to compute convolution.  Here&#039;s the theory, for any reader who might be interested.  (Note that I&#039;m using mathematical notation here, not MATLAB syntax.)

If x[n] is nonzero only for 0 &lt;= n &lt;= P-1, and h[n] is nonzero only for 0 &lt;= n &lt;= Q-1, then the convolution y[n] = (x*h)[n] is nonzero only for 0 &lt;= n &lt;= L-1, where L = P + Q - 1. Further, y[n] for 0 &lt;= n &lt;= L-1 is exactly equal to the L-point circular convolution of x and h.  So my conv_fft in this post produces exactly the same thing (except possibly for floating-point round-off effects) as conv.

Overlap-and-add and similar methods were invented for a different reason. Consider the case where you want to filter a signal using FFT-based convolution, but you never have the entire signal at once.  For example, you are building a system to process an input audio stream.  Overlap-and-add allows you to perform FFT-based convolution on the input signal in chunks.</description>
		<content:encoded><![CDATA[<p>To all&mdash;After almost four years of writing this blog, I still have no ability to predict which topics will draw reader comment!  ;-)</p>
<p>Peter&mdash;Most the comments people attempt to post here are desperate queries for help with homework or a graduate school research project (I don&#8217;t let those through), so yours is admirably on topic.  ;-)</p>
<p>Your suggestion is a good one.  We can look into making some changes so that imfilter does not need to pad.  Just to set your expectations, though &#8230; the feature change deadline for R2010a was some time ago, and we&#8217;re already working on R2010b.</p>
<p>Jeremy and Chris&mdash;I tend to think of circular convolution and periodic boundary conditions as being basically the same issue, and it is not a reason to avoid using the DFT to compute convolution.  Here&#8217;s the theory, for any reader who might be interested.  (Note that I&#8217;m using mathematical notation here, not MATLAB syntax.)</p>
<p>If x[n] is nonzero only for 0 < = n <= P-1, and h[n] is nonzero only for 0 <= n <= Q-1, then the convolution y[n] = (x*h)[n] is nonzero only for 0 <= n <= L-1, where L = P + Q - 1. Further, y[n] for 0 <= n <= L-1 is exactly equal to the L-point circular convolution of x and h.  So my conv_fft in this post produces exactly the same thing (except possibly for floating-point round-off effects) as conv.</p>
</p><p>Overlap-and-add and similar methods were invented for a different reason. Consider the case where you want to filter a signal using FFT-based convolution, but you never have the entire signal at once.  For example, you are building a system to process an input audio stream.  Overlap-and-add allows you to perform FFT-based convolution on the input signal in chunks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cris Luengo</title>
		<link>http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22282</link>
		<dc:creator>Cris Luengo</dc:creator>
		<pubDate>Tue, 03 Nov 2009 17:50:49 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2009/11/03/the-conv-function-and-implementation-tradeoffs/#comment-22282</guid>
		<description>Also, going through the DFT you&#039;re assuming a periodic boundary condition, whereas conv assumes zeros outside the boundaries. This can be significant, especially when using large convolution kernels.

I&#039;m all for giving the user the option. It would be bad if you couldn&#039;t control which method is being used.</description>
		<content:encoded><![CDATA[<p>Also, going through the DFT you&#8217;re assuming a periodic boundary condition, whereas conv assumes zeros outside the boundaries. This can be significant, especially when using large convolution kernels.</p>
<p>I&#8217;m all for giving the user the option. It would be bad if you couldn&#8217;t control which method is being used.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

