DSPRelated.com
Forums

Interchanging of filtering and decimation operations

Started by vasindagi April 26, 2008
rickman <gnuarm@gmail.com> wrote in
news:c4a4ca29-9b14-48a3-8161-b59bbdb5f9e9@f63g2000hsf.googlegroups.com: 

> On Apr 26, 7:12 am, "vasindagi" <vish...@gmail.com> wrote: >> Hi, >> >> It is known that downsampling introduces aliasing if the signal to be >> downsampled has high frequency components. Hence it is passed through >> a low pass filter before it is downsampled. I want to know whether >> the filtering and the downsampling operations can be interchanged as >> they are essentially the same, or is it always necessary to filter >> the signal first and then downsample it. >> Thanks in advance. > > It is funny how everyone seems to think you have to filter *before* > you down sample. One of the cool things about decimation is that you > simply toss out samples. If you are tossing out data from a filter, > why do you need to calculate the results being tossed??? So you can > combine the filter and down sampling by designing your filter to only > calculate the samples you will be outputting. > > Pretty simple, no? > > Rick
You don't "have" to do anything, unless you want your results to make sense. If your signal has frequency components above the Nyquist for the downsamples rate, you will alias if you don't filter first. -- Scott Reverse name to reply
John, Can you try to demodulate the signal at frequency  = (1.0103 +
4.3436)/2  = 2.67695 MHz then apply the "skipping decimation"?
"DigitalSignal" <digitalsignal999@yahoo.com> wrote in message 
news:cda9250a-f6ec-4953-94c9-66dff1f25255@f24g2000prh.googlegroups.com...
> John, Can you try to demodulate the signal at frequency = > (1.0103 + > 4.3436)/2 = 2.67695 MHz then apply the "skipping > decimation"?
?? I don't understand. Can you elaborate?
rickman wrote:
> On Apr 26, 7:12 am, "vasindagi" <vish...@gmail.com> wrote: >> Hi, >> >> It is known that downsampling introduces aliasing if the signal to be >> downsampled has high frequency components. Hence it is passed through a low >> pass filter before it is downsampled. I want to know whether the filtering >> and the downsampling operations can be interchanged as they are essentially >> the same, or is it always necessary to filter the signal first and then >> downsample it. >> Thanks in advance. > > It is funny how everyone seems to think you have to filter *before* > you down sample. One of the cool things about decimation is that you > simply toss out samples. If you are tossing out data from a filter, > why do you need to calculate the results being tossed??? So you can > combine the filter and down sampling by designing your filter to only > calculate the samples you will be outputting. > > Pretty simple, no?
Not simple enough for some until they digest it a while. :-) When cleverly done (and with the right kind of filter) filtering and decimation can be combined into one operation. It needs to be clear that one can't decimate first and filter later. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
rickman wrote:

   ...

> I think I didn't read the OP very well. The question was, can the > filter and decimation steps be interchanged. My answer was, "Yes you > can combine them". No one is saying you don't have to use a filter > and no one is saying that the filter can be *after* the decimation. > But the two can be combined to the advantage of saving processing > steps. If we decimate by 4, your filter is going to produce the > results; Y0, Y1, Y2, Y3, Y4, Y5, Y6,... and you will be decimating to > retain Y0, Y4, Y8,... why bother to calculate the samples that you are > tossing; Y1, Y2, Y3, Y5, Y6, Y7,...?
No reason to /if you won't need them later/.
> I am thinking of a FIR filter implementation of course where a > decimation by 4 will save you 3/4 of the calculations in the filter. > But even in an IIR filter, you can save work if you are calculating > the results on the fly. If you are combining 4 steps of a IIR into > one operation, you can save processor work in loading and storing the > intermediate results and loading up the registers for computation.
That works. With an IIR it doesn't work because Y[n-1] enters the calculation of y[n]. ... Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Apr 27, 1:32 pm, Jerry Avins <j...@ieee.org> wrote:
> rickman wrote: > > ... > > > I think I didn't read the OP very well. The question was, can the > > filter and decimation steps be interchanged. My answer was, "Yes you > > can combine them". No one is saying you don't have to use a filter > > and no one is saying that the filter can be *after* the decimation. > > But the two can be combined to the advantage of saving processing > > steps. If we decimate by 4, your filter is going to produce the > > results; Y0, Y1, Y2, Y3, Y4, Y5, Y6,... and you will be decimating to > > retain Y0, Y4, Y8,... why bother to calculate the samples that you are > > tossing; Y1, Y2, Y3, Y5, Y6, Y7,...? > > No reason to /if you won't need them later/. > > > I am thinking of a FIR filter implementation of course where a > > decimation by 4 will save you 3/4 of the calculations in the filter. > > But even in an IIR filter, you can save work if you are calculating > > the results on the fly. If you are combining 4 steps of a IIR into > > one operation, you can save processor work in loading and storing the > > intermediate results and loading up the registers for computation. > > That works. With an IIR it doesn't work because Y[n-1] enters the > calculation of y[n].
Jerry, You are usually sharper than that. I didn't say you wouldn't calculate each step of an IIR. I said that by combining multiple calculations, you can reduce the overhead. It is less work to calculate four iterations of an IIR in a loop (and only save the last of the four) than it is to return to the same code four times to perform four iterations. There is a lot more to a filter than just the multiplies and adds. The hard part is actually retrieving and saving the data.
rickman wrote:
> On Apr 27, 1:32 pm, Jerry Avins <j...@ieee.org> wrote: >> rickman wrote: >> >> ... >> >>> I think I didn't read the OP very well. The question was, can the >>> filter and decimation steps be interchanged. My answer was, "Yes you >>> can combine them". No one is saying you don't have to use a filter >>> and no one is saying that the filter can be *after* the decimation. >>> But the two can be combined to the advantage of saving processing >>> steps. If we decimate by 4, your filter is going to produce the >>> results; Y0, Y1, Y2, Y3, Y4, Y5, Y6,... and you will be decimating to >>> retain Y0, Y4, Y8,... why bother to calculate the samples that you are >>> tossing; Y1, Y2, Y3, Y5, Y6, Y7,...? >> No reason to /if you won't need them later/. >> >>> I am thinking of a FIR filter implementation of course where a >>> decimation by 4 will save you 3/4 of the calculations in the filter. >>> But even in an IIR filter, you can save work if you are calculating >>> the results on the fly. If you are combining 4 steps of a IIR into >>> one operation, you can save processor work in loading and storing the >>> intermediate results and loading up the registers for computation. >> That works. With an IIR it doesn't work because Y[n-1] enters the >> calculation of y[n]. > > Jerry, > > You are usually sharper than that. I didn't say you wouldn't > calculate each step of an IIR. I said that by combining multiple > calculations, you can reduce the overhead. It is less work to > calculate four iterations of an IIR in a loop (and only save the last > of the four) than it is to return to the same code four times to > perform four iterations. There is a lot more to a filter than just > the multiplies and adds. The hard part is actually retrieving and > saving the data.
Have you done that? I didn't think it would be possible to use Y[n-3], Y[n-2], and Y[n-1] in calculating Y[n] without calculating each of them first. Is there a shortcut? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
"rickman" <gnuarm@gmail.com> wrote in message 
news:84b07c44-59ac-4603-be62-5808f570e796@y21g2000hsf.googlegroups.com...
> > I think I didn't read the OP very well. The question was, > can the > filter and decimation steps be interchanged. My answer was, > "Yes you > can combine them". No one is saying you don't have to use a > filter > and no one is saying that the filter can be *after* the > decimation. > But the two can be combined to the advantage of saving > processing > steps. If we decimate by 4, your filter is going to produce > the > results; Y0, Y1, Y2, Y3, Y4, Y5, Y6,... and you will be > decimating to > retain Y0, Y4, Y8,... why bother to calculate the samples > that you are > tossing; Y1, Y2, Y3, Y5, Y6, Y7,...?
That is a good point and one that I don't think about often enough. The filtering is still being performed on the pre-decimated signal, but only needs to be done at the decimated rate. Thanks for making this clear. In many of the applications with which I'm familiar, the FIRs are too long for evaluation by direct convolution and FFT-based fast convolution techniques are used to do the filtering. In this case, I think there is less opportunity to combine the two operations (filtering and decimation) since the IFFT generates all the filtered (predecimated) samples in one step.
On Apr 27, 12:23 pm, Jerry Avins <j...@ieee.org> wrote:
> It needs to be clear that > one can't decimate first and filter later. >
Hi Jerry, I think there may be times where you can decimate first and filter. If the significant components of the signal don't alias to be on top of one another, a person may downsample and then filter. It's essentially subsampling (or undersampling) a signal. It's important to insure where the significant components of the signal are before downsampling, which is a practical problem. In regards to John's problem, the aliased components all happen to fall around 1MHz (neglecting the width of the components) and maybe the order of the filter needed to filter out the unwanted signals will be much greater than if the filtering is done first (or even better, with a polyphase implementation as suggested). -Mark
On Apr 27, 10:01&#4294967295;am, "John E. Hadstate" <jh113...@hotmail.com> wrote:
> "DigitalSignal" <digitalsignal...@yahoo.com> wrote in message > > news:cda9250a-f6ec-4953-94c9-66dff1f25255@f24g2000prh.googlegroups.com... > > > John, Can you try to demodulate the signal at frequency &#4294967295;= > > (1.0103 + > > 4.3436)/2 &#4294967295;= 2.67695 MHz then apply the "skipping > > decimation"? > > ?? > > I don't understand. &#4294967295;Can you elaborate?
John, I should have asked what you intend to do with the frequency components at one at 1.0103 MHz, (the signal of interest), one at 2.3230 MHz. and one at 4.3436 MHz. Do you want to analyze their intensity using FFT?