FUNCTION: Goertzel algorithm -- DFT of a specific frequency bin

This function implements the Goertzel algorithm (for integer N).

The Goertzel algorithm is a technique in digital signal processing (DSP) for efficient evaluation of the individual terms of the discrete Fourier transform ( DFT ).

In short, it measure the power of a specific frequency like one bin of a DFT , over a rolling window (N) of samples.

Here you see an input signal that changes frequency and amplitude (from 7 bars to 17). I am running the indicator 3 times to show it measuring both frequencies and one in between (13). You can see it very accurately measures the signals present and their power, but is noisy in the transition. Changing the block len will cause it to be more responsive but noisier.

Here is a picture of the same signal, but with white noise added.

If you have a cycle you think is present you could use this to test it, but the function is designed for integration in to more complicated scripts. I think power is best interrupted on a log scale.

Given a period (in bars or samples) and a block_len (N in Goertzel terminology) the function returns the Real (InPhase) and Quadrature (Imaginary) components of your signal as well as calculating the power and the instantaneous angle (in radians).

I hope this proves useful to the DSP folks here.
Gỡ bỏ khỏi Script Ưa thích Thêm vào Script Ưa thích

Bình luận

using as pattern diverson detector .. awesome.
Phản hồi
Very useful function. Very efficient over small sample sizes.

To answer the question in your function, yes, the loop should be from 0 to N-1 if you want the calculation to factor in the current bar. Otherwise, you're looking at the transform from the last bar.

I think it would be dope to make a spectral heatmap using this algorithm. I might play around with it in my spare time.

P.S. What's with the unused window function? lol
Phản hồi
yatrader2 DonovanWall
>I think it would be dope to make a spectral heatmap using this algorithm.
@DonovanWall, give me a few days, I am almost done with one.

>the loop should be from 0 to N-1 if you want the calculation to factor in the current bar.
Hmm, I'll double check this. Thanks.
Phản hồi
DonovanWall yatrader2
@yatrader2, Awesome. Looking forward to it!

And here's some pseudocode from wiki:


Notice they use 0 to N - 1.
Phản hồi
anoojpatel yatrader2
@yatrader2, Also, isn't it the case the the algorithm expects the iteration through 0 to N-1 should start at the start of the input array, rather than the end (since pinescript makes x looks at the N-1 input element of the input). So shouldn't the loop be from N-1 to 0, since we want to map the states of z1 and z2 to start at the beginning rather than what is currently happening where we work backwards from the current bar.
Phản hồi
great for pattern detection
Phản hồi
Interesting when applied to bitcoin hashrate QUANDL:BCHAIN/HRATE
Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Cách thức hoạt động Tính năng Biểu đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Các ý tưởng đã đăng Người theo dõi Đang theo dõi Tin nhắn riêng Trò chuyện Đăng xuất