1
$\begingroup$

Currently doing some signal analysis in python for a major project in my physics degree which is due really soon. I need some help!

Say I have two signals, f(t) and g(t) which are recorded over the same amount of time.

f(t) and g(t) both feature different amounts of noise.

f(t) and g(t) are recorded at different sampling rates so I have two different quantities of measurements.

For analysis I imagine I will need:

a) Interpolation (or resampling?) both signals to get the same sampling rate.

b) Smoothing/filtering to reduce noise.

a then b or b then a?

I would like to ideally have two signals with equal sampling frequencies. I would also like all values of f(t) and g(t) to occupy the same points on the t (x) axis. In addition to this I would like to smooth the data as much as possible with a minimal loss of information.

$\endgroup$
  • $\begingroup$ I would suggest just trying both options for a few scenarios and see what happens. $\endgroup$ – David K Mar 12 '14 at 13:23
  • $\begingroup$ How long are the samples of f() and g() ? Uniform, right ? $\endgroup$ – denis Apr 28 '14 at 14:39
1
$\begingroup$

Could you describe what you want to find in your data -- peaks, trends, model ? and what kind of noise there is -- $\infty$ possibilities ? A plot would be good. Without some more info, I can only say, with others, "try it and see".

As you may know, a good way to smooth and resample (interpolate) in Python is with scipy.ndimage.map_coordinates, along the lines

import numpy as np
from scipy.ndimage import map_coordinates

def smooth_resample( y, newlen ):
    """ resample y to newlen, with B-spline smoothing """
    n = len(y)
    newgrid = np.linspace( 0, n - 1, newlen )
        # e.g. n = 3, newlen = 5 -> [0 .5 1 1.5 2]
    return map_coordinates( y, newgrid, mode="nearest", prefilter=False )

map_coordinates also works for 2d images, 3d voxels ... hence the name "ndimage".
For more, stackoverflow has quite a few Q+A s that use it.

(Cubic-spline interpolation uses the nearest 4 points to each x in newgrid, whereas dsp smoothing filters are usually much longer. For smoothing that preserves peaks,
see Savitzky-Golay filters, e.g. Numerical Recipes p. 771 ff.)

$\endgroup$
0
$\begingroup$

If the 2 Fs are multiple each other the simple thing than you have to do is Interpolate the signal with the lowest Fs. Remember that interpolation is the process of upsampling and filtering a signal to increase its effective sampling rate. So you have to up-samplig data of a factor L (put L zero btw each samples) and then low pass filter (with freq cut = pi/L).

If the 2 Fs are not multiple each other you 2 Interpolate each data with different interpolation factor in order to obtain the same sampling freq. In any case: it is not recommend decimante. I will lost data.

$\endgroup$
0
$\begingroup$

If you want to upsample to the higher of the two frequencies, then order shouldn't matter so much - as David K said, try both (does python have anything like Matlab's interp1? It's a useful approach for resampling to a common time basis when sampling frequencies aren't multiples/divisors of the target frequency). If you want to downsample, you need to low-pass filter first to avoid aliasing. In that case, low-pass filter to a cutoff frequency less than or equal to half the target sampling frequency. Is that the kind of answer you're looking for, or were you hoping for more details?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.