From: Avinash Parnandi on 28 Jan 2010 23:10 "Matthew " <mdford86(a)gmail.com> wrote in message <hbsfpg$c3g$1(a)fred.mathworks.com>... > I want to create a lowpass butterworth filter for some data that I have and from what I've read online I can't figure out how to actually implement the filter. I have time and acceleration data (so two vectors, say, Time and Accel) collected at 500kHz and I'd like to do a lowpass filter with a cutoff frequency of 20kHz with no phase shift. Not sure about the order yet, but will assume 5th order right now. > > Everything I found suggests that I should use [b, a] = butter(5,500000,'low'). But I'm not sure what to do with [b, a], whether I should apply it to the time and acceleration vectors, what the output would be, and how I could plot this signal on top of my original vectors. > > Any help would be greatly appreciated. This is how you can do it. This code will do the filtering, but I think it will bring in phase shift.- %%%%%%%%% code %%%%%%%% data; % this is your data f = 500000; % sampling freq = 500k fnorm =20000/(250000); % normalized cut off freq, here 20000 is the cutoff freq [b1,a1] = butter(5,fnorm,'low');% here 5 is the order of the filter; The asymptotic roll-off of an nth order is 20n dB/decade low_pass_data = filtfilt(b1,a1,data); freqz(b1,a1,128,f),title('filter characteristics') % plots the characteristics of the filter figure subplot(2,1,1), plot(data),title('actual') subplot(2,1,2), plot(low_pass_data), title('filtered') %%%%%%%%%%%%%%%%%%%%%%%%%%%% Cheers, Avinash Parnandi Interaction Lab (USC Robotics Research Lab) http://robotics.usc.edu/~parnandi/
From: Mark Shore on 28 Jan 2010 23:23 "Wayne King" <wmkingty(a)gmail.com> wrote in message .... > However, you should realize that filter() does NOT implement zero-phase filtering as you indicated you wanted in your original post. If you're okay with this, fine. If you need to use filtfilt(), then you will need to have the filter coefficients because filtfilt() does not currently accept filter objects as inputs. > .... But see filtfilthd(), which does. http://www.mathworks.com/matlabcentral/fileexchange/17061-filtfilthd Mark
|
Pages: 1 Prev: Write Binary Image from Matrix Next: How to write a for loop for multiple variables |