# [SciPy-User] variable smoothing kernel

Sun Mar 27 08:41:45 CDT 2011

I guess by FIR-filters you don't mean Far InfraRed ;-). I guess if I
describe my specific case in more detail than that might help:
My Signal is an optical spectrum which has nm on the x axis and
intensity on the y. I am trying to simulate the effects of the optical
properties of a real spectrograph on synthetic spectra. Basically we
describe this as the resolution (R) = lambda/(fwhm(lambda). That's why I
have a variable kernel size. So for the moment I interpolate the evenly
linear spaced spectrum on log space spectrum (I use splrep and splev
with k=1, rather than interp1d. I hope that's a good idea) and then
calculate the kernel size and use ndimage.gaussian_filter1d.

Ah while we are on the topic: I sometimes have synthetic spectra which
are irregularly sampled. This means what I am doing is resampling it on
a linear grid using smallest wavelength delta (which can be quite
small). This obviously expands the spectra to many times its original
size. Then I would resample it on a log spacing where the largest delta
is equal to the smallest delta on the linear scale. This makes it even
larger. There is probably a much smarter way.

I should also mention that my knowledge about signal processing is limited.

Your help is very much appreciated,
Wolfgang

On 27/03/11 11:24 PM, Sturla Molden wrote:
> Den 27.03.2011 03:54, skrev Wolfgang Kerzendorf:
>> I have learned that multiplying functions in fourier space is the same
>> as convoluting them.
>
> Yes.
>
> The best strategy is to do this chunk-wise, however, instead of
> FFT'ing the whole signal. This leads tot he so-called
> "overlap-and-add" method, used by e.g. scipy.signal.fftfilt. fftfilt
> tries to guess the optimum chunk-size to use for filtering.
>
> For short FIR-filters it will be faster to filter in the time-domain.
>
> For moving average filters one can use a very fast recursive filter.
> Bartlet filter can be implemented by appying MA twice, Gaussian can be
> approximated by applying MA four times. (A better IIR-approximation
> for the Gaussian is available, howver, see below.)
>
>
>> I believe that is how the ndimage kernels work so
>> incredibly fast.
>
> No. They truncate the Gaussian, which is why compute time depends on
> filter size. Cf. the comment on short FIR-filters above.
>
> For the Gaussian it is possible to use a recursive IIR filter instead,
> for which compute time does not depend on filter size.
>
>
>
>> I wanted to see if there's a similar shortcut for a variable kernel.
>
> Not in general, because the filter will be non-linear.
>
>
> Sturla
>
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110328/2bcd90ab/attachment.html