questions about convolution
-
- KVRist
- Topic Starter
- 64 posts since 31 May, 2016
i was reading about convolution but only today I think I understood it,so you take impulse response,flip it ( reverse in time ) and then add or subtract the impulse response waveform bit amplitude values to each sample of the signal you are trying to change,going from first sample to last,is that right?
for example you have signal 3 1 7 9 5 ....and you have filter with impulse response that is like 1 2 4 2 1 ( symtetric linear phase fir ),so you flip it,but this time its same becose its symetric even if you reverse it,and then you start adding the numbers as you shift the impulse response values from left to right,so first the 3 of signal will add 1 from impulse response,then the impulse is shifted one more sample to right so 2 is added to the first sample of the signal,then 4 2 1 and then nothing becose the impulse moved to the right far away so it doesnt affect the first sample of the signal anymore,do I understand it correctly?
if I understand it correctly,every EQ filter,like butterworth,fir linear phase.... can be recreated with the impulse reponse that have ringing after it pass throught filter
so you just run impulse through the filter,and with the result/output,the impulse now containing ringing,you can perfectly recreate the filter even if you knew nothing about the specific parameters of that filter right?
another big question I have,when you take these impulses through filter,so you can recreate/understand that filter,do you somehow remove the single sample impulse that you put into that filter? I mean,you have the impulse,imagine 10 is max amplitude,so its 0 0 10 0 0,then you run it through filter that will cut that impulse by 6db,that is 50% in linear scale.So you know that impulse was 10 and that it should be 5,becose the filter is going to cut it in half,what I mean by this,if you use that impulse response to recreate stuff,are you recreating it with the ringing + the left over of the impulse thats been cut or do you remove that impulse from the ringing thats around that impulse.
that could be done in this way,so you put pulse with amplitude 10 inside,you know it will cut it in half and also add pre and post ringning,so you make inverted impulse with amplitude of 5,and then phase cancel it with the filter impulse response output so you get ringing only.Or does this work in way that you must filter the impulse input so hard that its completly removed and output is pure rining and doesnt contain any remains from the input impulse?
for example you have signal 3 1 7 9 5 ....and you have filter with impulse response that is like 1 2 4 2 1 ( symtetric linear phase fir ),so you flip it,but this time its same becose its symetric even if you reverse it,and then you start adding the numbers as you shift the impulse response values from left to right,so first the 3 of signal will add 1 from impulse response,then the impulse is shifted one more sample to right so 2 is added to the first sample of the signal,then 4 2 1 and then nothing becose the impulse moved to the right far away so it doesnt affect the first sample of the signal anymore,do I understand it correctly?
if I understand it correctly,every EQ filter,like butterworth,fir linear phase.... can be recreated with the impulse reponse that have ringing after it pass throught filter
so you just run impulse through the filter,and with the result/output,the impulse now containing ringing,you can perfectly recreate the filter even if you knew nothing about the specific parameters of that filter right?
another big question I have,when you take these impulses through filter,so you can recreate/understand that filter,do you somehow remove the single sample impulse that you put into that filter? I mean,you have the impulse,imagine 10 is max amplitude,so its 0 0 10 0 0,then you run it through filter that will cut that impulse by 6db,that is 50% in linear scale.So you know that impulse was 10 and that it should be 5,becose the filter is going to cut it in half,what I mean by this,if you use that impulse response to recreate stuff,are you recreating it with the ringing + the left over of the impulse thats been cut or do you remove that impulse from the ringing thats around that impulse.
that could be done in this way,so you put pulse with amplitude 10 inside,you know it will cut it in half and also add pre and post ringning,so you make inverted impulse with amplitude of 5,and then phase cancel it with the filter impulse response output so you get ringing only.Or does this work in way that you must filter the impulse input so hard that its completly removed and output is pure rining and doesnt contain any remains from the input impulse?
-
- KVRAF
- 2256 posts since 29 May, 2012
I couldn't understand all the questions, but basically, yes that's what a 'linear and time invariant system' means. That's the basic assumption.
Yet on the other hand, many practical systems are neither linear nor time invariant. Many theoretical assumptions are violated and and resulting problems are handled. That's what music-dsp is all about.
Good luck in your quest
Yet on the other hand, many practical systems are neither linear nor time invariant. Many theoretical assumptions are violated and and resulting problems are handled. That's what music-dsp is all about.
Good luck in your quest
~stratum~
- KVRAF
- 12554 posts since 7 Dec, 2004
Convolution is when you take a signal (any signal) and multiply it with another signal.
For example:
You should see by this that what we are doing is replacing every individual sample (an impulse) with another signal (the impulse).
If the impulse is a single sample the output will be the original signal unchanged.
The impulse response of a filter is the complete "specific parameters" of the filter at that instant in time. Since the parameters may change during both the sample period as well as the period of the impulse response "ringing" you will only be able to recreate a single impulse response using such a sampled measurement.
In other words this only works correctly for LTI systems. Those are systems in which the "specific parameters" never change.
Note that this is how FIR filters are implemented.
Also note that convolution in the time domain is equal to multiplication in the Fourier/frequency domain. https://en.wikipedia.org/wiki/Convolution_theorem
Therefore for long convolutions an optimization is to convert the signal and impulse to the frequency domain first, then apply multiplication:
Now we're performing the transform itself plus N multiplications (one per signal sample) plus any overhead for overlap-add and so on; whereas in the time domain we were performing signal_length*impulse_length multiplications.
As for how you actually implement this: these details combined with the LTI issue should lead you to realize this stuff is entirely useless everywhere except for the implementation of very specific types of LTI filters. The most obvious example is a very long/complex EQ or more commonly a static "convolution reverb".
For example:
Code: Select all
impulse[N],
signal[N]
output[] convolve(signal[], impulse[length], length)
{
for (int i = 0; i < length; i++) {
output[i] = signal[i] * impulse[i];
}
return output;
}
for (int i = 0; i < N; i++) {
output[i] += convolve(signal + i, impulse, N);
}
If the impulse is a single sample the output will be the original signal unchanged.
The impulse response of a filter is the complete "specific parameters" of the filter at that instant in time. Since the parameters may change during both the sample period as well as the period of the impulse response "ringing" you will only be able to recreate a single impulse response using such a sampled measurement.
In other words this only works correctly for LTI systems. Those are systems in which the "specific parameters" never change.
Note that this is how FIR filters are implemented.
Also note that convolution in the time domain is equal to multiplication in the Fourier/frequency domain. https://en.wikipedia.org/wiki/Convolution_theorem
Therefore for long convolutions an optimization is to convert the signal and impulse to the frequency domain first, then apply multiplication:
Code: Select all
for i = 0 to signal length: output[i] = signal[i] * impulse[i];
As for how you actually implement this: these details combined with the LTI issue should lead you to realize this stuff is entirely useless everywhere except for the implementation of very specific types of LTI filters. The most obvious example is a very long/complex EQ or more commonly a static "convolution reverb".
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
Multiply in the spectral space, not in time space. You showed it quite well, there are 2 loops in time.aciddose wrote:Convolution is when you take a signal (any signal) and multiply it with another signal.
- KVRAF
- 12554 posts since 7 Dec, 2004
You're still multiplying the signals. Convolution is sort of a "higher order" multiply. Rather than multiplying by a scalar (scaling) we're multiplying by a vector (impulse) which replaces the existing "scalar impulses" (samples).
In fact you can implement the convolve() function as an operator overload of signal like so:
Then your implementation would look like this:
Multiplying a signal * signal = each sample by each scalar input
Multiplying a signal * impulse = each sample replaced by impulse multiplied by each scalar sample input
Both signal_t and FIR_t have the same underlying type and could be converted with a constructor cast: signal_t &signal = signal_t(impulse)
Therefore to re-purpose a signal as an impulse/FIR, you'd simply perform the opposite cast: FIR_t &impulse = FIR_t(signal)
Or, when using operator overloads:
output = input * FIR_t(impulse);
In fact you can implement the convolve() function as an operator overload of signal like so:
Code: Select all
signal_t
{
signal operator*(const signal_t &input, const FIR_t &impulse) const
{
...
}
}
Code: Select all
output = input * impulse;
Multiplying a signal * impulse = each sample replaced by impulse multiplied by each scalar sample input
Both signal_t and FIR_t have the same underlying type and could be converted with a constructor cast: signal_t &signal = signal_t(impulse)
Therefore to re-purpose a signal as an impulse/FIR, you'd simply perform the opposite cast: FIR_t &impulse = FIR_t(signal)
Or, when using operator overloads:
output = input * FIR_t(impulse);
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
There is a reason why it's never displayed as a multiplication. I agree that it's kind of a multiplication (especially since it is a multiplication spectral domain), but in all languages, we never use the multiplication symbol to express convolution, because it is something different. There is the concept of sliding time window that cannot be described by a multiplication symbol. In fact, if you try to represent the convolution as a multiplication, a matrix multiplication, the signal is the second operand, and the impulse is actually a "diagonal" matrix.
-
- KVRAF
- 2256 posts since 29 May, 2012
Apparently there is a tradition beyond programming language polymorphism in such abstractions https://en.wikipedia.org/wiki/Ring_(mathematics)
I agree that such notation is confusing, however. Math is often already confusing enough without any of that.
I agree that such notation is confusing, however. Math is often already confusing enough without any of that.
~stratum~
- KVRAF
- 12554 posts since 7 Dec, 2004
I don't have much trouble with it. It pays to keep in mind that convolution is awful.
You should find it confusing. It is.
The advantage of using this sort of abstraction is to limit what you can mess up. If you have to use c-style functional programming or write everything line-by-line without any abstraction there are a lot better odds you might make a mistake.
So long as we're still equally confused by what is actually going on, at least there is a lot less you might get wrong typing output = signal * fir
You should find it confusing. It is.
The advantage of using this sort of abstraction is to limit what you can mess up. If you have to use c-style functional programming or write everything line-by-line without any abstraction there are a lot better odds you might make a mistake.
So long as we're still equally confused by what is actually going on, at least there is a lot less you might get wrong typing output = signal * fir
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.
-
- KVRian
- 1273 posts since 9 Jan, 2006
I don't see how it's confusing. You could talk the hind legs off a donkey to avoid admitting a mistake.
It really isn't helpful to describe convolution as multiplication. Unless, as Miles said, you make it clear you're talking about the frequency domain.
It really isn't helpful to describe convolution as multiplication. Unless, as Miles said, you make it clear you're talking about the frequency domain.
-
- KVRAF
- 2256 posts since 29 May, 2012
It depends on how people choose to look at or understand things.I don't see how it's confusing. You could talk the hind legs off a donkey to avoid admitting a mistake.
If you consider it only as a formula, then it isn't confusing.
If you want to understand why the formula is the way it is, then it is.
There are two ways to proceed in that case: Either one reviews how such a formula was derived from more basic things, or imagine a geometric interpretation of what it does. For example, in the case of integration and derivation both of these are possible. Integration is addition taken to an infinitely small limit, and geometrically it is the area under a curve.
In the case of convolution, its geometric interpretation is a point spread function in image processing (or more properly, the operation of spreading all points in an image using that function - it is easier to imagine this as blurring rather than sharpening) and in audio it does exactly the same thing. If you go beyond that and try to understand more using just intuition, after a point it no longer works.
~stratum~
-
- KVRian
- 1273 posts since 9 Jan, 2006
You make some interesting points.
However confusing various view points of convulsion may be I'd stand by the view that saying convolution is multiplication just isn't particularly helpful.
I was more interested in acidoses reply which actually seemed to be addressing practical implementations, rather than deeper understanding, as a means of muddying the water to avoid facing up to a rather minor miss use of terminology.
No biggie.
However confusing various view points of convulsion may be I'd stand by the view that saying convolution is multiplication just isn't particularly helpful.
I was more interested in acidoses reply which actually seemed to be addressing practical implementations, rather than deeper understanding, as a means of muddying the water to avoid facing up to a rather minor miss use of terminology.
No biggie.
-
- KVRAF
- 2256 posts since 29 May, 2012
Actually any answer to the original question would require picking one aspect of it or it cannot be answered at all.I was more interested in the motivation behind acidoses reply which actually seemed to be addressing practical implementations, rather than deeper understanding, as a means of muddying the water to avoid facing up to a rather minor miss use of terminology.
~stratum~
-
- KVRian
- 1273 posts since 9 Jan, 2006
Yes, that's right.neodymDNB wrote:filter coefficients are filter impulse response,is that right?
Maybe you already saw http://www.dspguide.com/pdfbook.htm, if not it's a good place to learn about convolution
-
- KVRAF
- 3089 posts since 4 May, 2012
For a FIR filter. If you take the impulse response of an IIR filter, you can reconstruct it as a FIR using that method.matt42 wrote:Yes, that's right.neodymDNB wrote:filter coefficients are filter impulse response,is that right?
Maybe you already saw http://www.dspguide.com/pdfbook.htm, if not it's a good place to learn about convolution