Anda di halaman 1dari 3

Cuto Frequency of Arduino smooth()

davekw7x This document is released to public domain, but a simple attribution to davek7x would be appropriate if you decide to quote anything. December, 2010
Questions have been asked about the cuto frequency of the smoothing function published at http://www.arduino.cc/playground/Main/Smooth. Heres my approach: First of all, heres the algorithm demonstrated in the example sketch (I use the variable a instead of filterV al that appears in the sketch): You select a value of a such that 0 a < 1 and here is the function output for sample number k: y(k) = x(k)(1 a) + ay(k 1) That is, the output for a given input sample is a function of the value of that sample and the previous output value. Before getting into formal analysis, you can note the following: We see that for a = 0, we have y(k) = x(k), so it is simply the identity function. Not very interesting. Also, if we let a = 1, we see that y(k) = y(k 1), and the output doesnt change from whatever initial value you give it (i.e. y does not depend on x). So this is not very interesting either. Anyhow. . . You can run the test sketch (stimulating the lter with a square wave) and observe the following for values of a between 0 and 1: Small values of a dont have very much eect. There are a few output values between 0 and the maximum value for each transition. If we had real inputs that wiggled a lot, the amount of wiggling would (we hope) be reduced somewhat. Thats why it is called a smoothing function. As a gets closer to 1, there are more and more transition values between zero and the maximum value, so the wiggling would (probably) be reduced 1

more. The inescapable result is the the time it takes the output to reach a new value is increased as a increases. In other words, there is a delay that is a function of a. We see that lower cuto frequencies result in longer delays. Qualitatively, for people used to thinking in terms of frequency response of lters in the continuous time domain, these can be recognized as the characteristics of a low-pass lter. In particular, small values of a correspond to higher values of cut-o frequency, fco , and larger values of a correspond to lower values of fco . Now, heres the thing for analytical (quantitative) signal processing in sampleddata (discrete-time) systems: Mathematical treatment (with Fourier analysis) is valid only if the input signal doesnt have frequency components higher than one-half the sampling frequency. Since a square wave signal has an innite number of frequency components, it wont be used for a quantitative analysis. Instead, we will express the transfer function of the lter in terms of its response to a sinusoidal input signal. A very convenient tool for treating discrete-time systems is the Z-transform. I wont go into details here, but the Z-transform of the transfer function of this lter is given by Y (z) 1a = X(z) 1 az 1 I will treat the more general form of a single-pole low-pass lter in the Z domain: c Y (z) = X(z) 1 dz 1 Where c = 1 a and d = a. To get the frequency response, substitute z = ej and we have H1 () = c 1 dej

Now, is a frequency variable based on a sampling frequency of 1 sample per second. To get the transfer function for a given sampling frequency, fs , we divide by fs So we end up with the following transfer function of : H2 () = c 1 dej fs

where = 2f To get something real out of this, we want the absolute value of H2 (), and we might even want a function of f (f in Hz) instead of ( in radians/second). Again, skipping the details, applying a little complex math leads to something that we can actually write into a program: 2

|H(f )| =

c ([1 d cos(2f /fs )]2 + [d sin(2f /fs )]2

As a nal step, to calculate the cuto frequency, we want to nd a value of f for which |H(f )| = 1/ 2. Numerically, it is very straightforward to use a bisection method on the interval (0, 1) to nd a value of f for which |H(f )| 1/ (2) = 0 Oh, by the way, if the cuto frequency is high (close to fs /2), it may be that the response never goes down to 1/ 2, so that possibility must also be taken into account. Here are the results of cuto frequency calculations based on the above considerations: Sample frequency = 33.3333 a a a a a a a a a a a a a a a a a a a a = = = = = = = = = = = = = = = = = = = = 0.00: 0.05: 0.10: 0.15: 0.20: 0.25: 0.30: 0.35: 0.40: 0.45: 0.50: 0.55: 0.60: 0.65: 0.70: 0.75: 0.80: 0.85: 0.90: 0.95: lpfResponse(16.67) lpfResponse(16.67) lpfResponse(16.67) lpfResponse(16.67) fco = 11.74721 fco = 8.99822 fco = 7.35519 fco = 6.17082 fco = 5.24380 fco = 4.48175 fco = 3.83422 fco = 3.27062 fco = 2.77097 fco = 2.32157 fco = 1.91261 fco = 1.53684 fco = 1.18876 fco = 0.86409 fco = 0.55947 fco = 0.27218 = = = = 1.00000 0.90476 0.81818 0.73913

davekw7x

Anda mungkin juga menyukai