Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to filter out data ? 2

Status
Not open for further replies.

customcustom

Mechanical
May 15, 2007
6
I have two columns of data (50,000 points) in an excel file (.CSV) that needs to be filtered down from 20hz to 5hz. How would I go about doing this?
ie I need the data to filtered down to 12500 data points evenly.
 
Replies continue below

Recommended for you

If I load the original .csv file in matlab, is it possible to extract data points - then export into csv format?.
 
Yes, you could load it into Matlab and take every 4th point. But you need to be careful. If the 20Hz sample frequency signal contains frequencies greater than 2.5 Hz then you need to filter them out or your 5Hz sample rate signal will be aliased.

M

--
Dr Michael F Platten
 
Luckily they have thought of that and the excellent decimate function in matlab will antialias your data and then downsample it.

DECIMATE Resample data at a lower rate after lowpass filtering.
Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times the
original sample rate. The resulting resampled vector Y is R times
shorter, i.e., LENGTH(Y) = CEIL(LENGTH(X)/R). By default, DECIMATE
filters the data with an 8th order Chebyshev Type I lowpass filter with
cutoff frequency .8*(Fs/2)/R, before resampling.

alternatively you could take a 4-8 point moving average of the data in excel and pick every 4th point. Not too sure what the frequency response of a moving average is, but I don't need to.


Cheers

Greg Locock

SIG:please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Ooooo. Nice function. Shame we don't stretch to the signal processing toolbox.

M

--
Dr Michael F Platten
 
Greg that seems to be working. I have two columns of data. Does that mean that I need to apply the filter to each column separately?.
Also, decimate is not accepting 4.5 for R. Is there any way around this (this is to get 20hz down to 8hz)?
 
"I have two columns of data. Does that mean that I need to apply the filter to each column separately?."

Yes, vector is matlab speak for a one dimensional array

"Also, decimate is not accepting 4.5 for R. Is there any way around this (this is to get 20hz down to 8hz)?"

That is an odd and unnecessary restriction, they might have done it for speed.

Two ways, (1) roll your own, by filtering and then downsampling or (2) upsample using interp1 to a sampling rate that can be decimated to 8 hz, eg 40 hz. I'd use linear interpolation.

The latter might seem a bit bizarre but since it uses canned routines may be faster than rolling your own.





Cheers

Greg Locock

SIG:please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Instead of rolling your own try resample. Basically what you are trying to do has already been done a million times before and perusal of matlab's help files will get you the right answer.

RESAMPLE Change the sampling rate of a signal.
Y = RESAMPLE(X,P,Q) resamples the sequence in vector X at P/Q times
the original sample rate using a polyphase implementation. Y is P/Q
times the length of X (or the ceiling of this if P/Q is not an integer).
P and Q must be positive integers.

RESAMPLE applies an anti-aliasing (lowpass) FIR filter to X during the
resampling process, and compensates for the filter's delay. The filter
is designed using FIRLS. RESAMPLE provides an easy-to-use alternative
to UPFIRDN, relieving the user of the need to supply a filter or
compensate for the signal delay introduced by filtering.

In its filtering process, RESAMPLE assumes the samples at times before
and after the given samples in X are equal to zero. Thus large
deviations from zero at the end points of the sequence X can cause
inaccuracies in Y at its end points.

Cheers

Greg Locock

SIG:please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor