# Blackman Filter - The Smoother The Better

จำนวนเข้าชม 1124
1124
Introduction

Who doesn't like smooth things? I'd like a smooth market price for christmas! But i can't get it, instead its so noisy...so you apply a filter to smooth it, such filters are called low-pass filters, they smooth and its great but they have lag, so nobody really use them, but they are pretty to look at.

Its on a childish note that i will introduce this indicator, so what it is all about? I propose a new FIR filter using a blackman function as filter kernel for financial time-series smoothing, do you prefer the childish tone ? Fear not its surprisingly easy!

The Blackman Function

The blackman function look like a bell shaped curve, look:

The blackman function will produce such curve. This function is called a cosine sum function because she is based on the sum of cosine functions, here only 2.

0.42 - 0.5 * cos(2 * pi * k) + 0.08 * cos(4 * pi * k)

Originally you use this function for windowing , what does it means? In signal processing you have a function called sync function, if you use this function as filter kernel you would get the ideal frequency domain response filter, sometime called brickwall filter, it would be extremely smooth.

Above the optimal low pass filter frequency response.

However the sync function has no ending values and goes on forever, therefore we can't use it for convolution, expect if we apply windowing. Filters using windowing are called windowed-sinc filters, i will describe the procedure below :

1 - Create a sync function = sin(pi*n)/(pi*n)

2 - Truncate it = I only keep the first length points of the sync function.

This create a abrupt end, the frequency of a filter using step 1 as kernel would contain ripples in the pass band and stop band, this is bad! The frequency response would look like this :

3 - I multiply my values of step 2 by a window function, it can the blackman window, i no longer have an abrupt end, its smooth!

The frequency response of the filter using this kernel would no longer have ripples! This is the power of windowing functions.

Here we are not using such thing, but we could in the future. Here instead we use the blackman function as filter kernel, because this function is bell shaped this mean that the filter will certainly be smooth (symmetrical weighting is a rule of thumb for kernels when we want really smooth filters).

The Filter

This filter is quite smooth, unlike the gaussian filter this filter give less weights to recent and past values, this is because the blackman function has fatter tails than the gaussian one. I could make a comparison of both, however they are quite alike, if you often use a gaussian filter its up to you to decide which one you prefer.

The filter can do a better job than the moving average when it comes to preserve the frequency components that constitute the cycles/trend.

We can see that the filter has a greater performance when it comes to keep the shape of the market price, thus it has a slightly better fit.

Conclusion

Ok so in this post you learned a bit about the sync function and windowing, those are basic subjects in signal processing, they allow us to approximate the filter with the ideal frequency response, i also showed you that those windowing function could be used as kernel and that they where pretty smooth on their own, there are many others, but the one i prefer is the blackman windowing function.

I know what you are thinking, "we want trailing stops, alerts, colors, arrows!", and i understand you pal, but sometimes its cool to take a break from all this stuff. However i can tell that i'am working on a side project that aim to estimate rolling maximum/minimum as fast as possible, any experiments will be published here, and i can ensure you that those indicators will make your day quite brighter, we will see that soon.

I hope you learned something from this post! I'am a bit tired (look i'am disappearing !)

You can check my indicator papers here : https://figshare.com/authors/Alex_Pierrefeu/7339466
I have seen the blackman window equation on a few sites, but how did you come up with the for loop?
ตอบกลับ
Peeinthebutt
@Peeinthebutt, The loop is used for the convolution, in the code w is the formula for the blackman window :)
ตอบกลับ
you are a genius thank you for work
ตอบกลับ
whoostyle
@whoostyle, Thank you a lot for your support :) I hope to still have it when i'll publish more indicators in the future.
ตอบกลับ
Great! With everything you publish I learn something new!! Keep it up!
JD.
ตอบกลับ
Duyck
@Duyck, I'am glad to hear that, i will maybe talk more about windowing in the future when i will actually use it for making filters, the post would certainly be more descriptive on how it works :)
ตอบกลับ
Effective ,Simple and Pure Vision ,lets get the picture

Thanks Mate

Great Job as Usual...
ตอบกลับ
ZAQDA
@ZAQDA, You are welcome and thanks for the support :)
ตอบกลับ
yea i bet you know alot about the black man function anime boy
ตอบกลับ
gelnd
@gelnd, And what am i supposed to understand here ?
ตอบกลับ