Help with Fourier

 
I tried to use 'Library of FFT Fast Fourier Transform Functions' ('Library of FFT Fast Fourier Transform Functions'), but I can't figure out how to use these functions, for some reason they all have the same descriptions. Help, please! How, for example, having Close values of 8 last bars to get their spectrum, then leave first 4 frequencies (like low pass filter) and get signal back?
 
I doubt it's even possible to get 4 frequencies out of 8 bars, not that it's all that's left.
 
Conversion (FFT) of 8 discrete signal values will give 8 frequencies, leaving 4 lower frequencies, we get the LF filter of the current course fluctuations.
 
They sent me a Fourier approximation, if you're interested, it might come in handy.

#property library
//--------------------------------------------------------------------------------
double b = 0.7;
double c1,c2,c3,c4,b2,b3;
double e1,e2,e3,e4,e5,e6,n,w1,w2,t3f; 
int ft3;
b2=b*b; b3=b2*b; c1=-b3; c2=(3*(b2+b3)); c3=-3*(2*b2+b+b3); c4=(1+3*b+b3+3*b2);
//==============================================
double af_T3( int i,int pt3, double ct3) {
//---------------------------
if (ft3==0) {n=pt3; if (n<1) n=1; n=1+0.5*(n-1); w1=2/(n+1); w2=1-w1; ft3=1;}
//------------------------
e1=w1*ct3+w2*e1; 
e2=w1*e1+w2*e2; 
e3=w1*e2+w2*e3; 
e4=w1*e3+w2*e4; 
e5=w1*e4+w2*e5; 
e6=w1*e5+w2*e6;
t3f=c1*e6+c2*e5+c3*e4+c4*e3;
return(t3f); }


#property  copyright "ANG3110@latchess.com"
//----------------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//-------------------------------
#import "af_T3.ex4"
int   af_T3( int i,int pt3, double ct3);
//-------------------------------
extern int hrf = 2;
extern int hrT3 = 6;
extern int days = 1;
//-----------------------------------------
double ak[],bk[],fx[],w,ak0,ss,sc,sk,dfx[];
double pi=3.1415926535897932384626433832795;
int T,sm,k;
double t3[],ct3,dc[];
int pt3;
//==========================================
int init() {
    IndicatorBuffers(5);
    SetIndexStyle(0,DRAW_LINE); 
    SetIndexBuffer(0,fx);
    SetIndexBuffer(1,t3);
    SetIndexBuffer(2,ak);
    SetIndexBuffer(3,bk);
    SetIndexBuffer(4,dc);
//--------------------------
pt3=hrT3*60/Period();
T=days*1440/Period(); 
w=2*pi/T;     
k=T/(hrf*60/Period());
return(0); }
//***************************************************
int start() {
//-----------------
int n,i,cbi;
//------------------
cbi=Bars-IndicatorCounted()-2;
for(i=cbi; i>=0; i--) {
//---------------------
ct3=Close[i];
t3[i]=af_T3(i,pt3,ct3);
dc[i]=Close[i]-t3[i];
}
//-------------------------- 
ak0=0.0;
for (n=0; n<=k; n++) { sc=0.0; ss=0.0;  
for (i=0; i<=T-1; i++) {
if (n==0) ak0+=dc[i]; 
if (n!=0) {sc=sc+dc[i]*MathCos(n*i*w); ss=ss+dc[i]*MathSin(n*i*w);} }
ak[n]=sc*2/T; bk[n]=ss*2/T; }
ak0=ak0/T; 
//--------------------------
for (i=0; i<=T-1; i++) { sk=0.0;
for (n=1; n<=k; n++) {
sk=sk+ak[n]*MathCos(n*i*w)+bk[n]*MathSin(n*i*w);}
fx[i]=ak0+sk+t3[i];  
} 
//---------------------------
 return(0); }
//****************************************************

Maybe you can also tell me why, if instead of the library, the first code is inserted directly into an indicator, it shows the weather in Africa.




 
lsv писал (а):
Conversion (FFT) of 8 discrete signal values will give 8 frequencies, leaving 4 lower frequencies, we obtain an LF filter of the current course oscillation.

A minimum of 2 bars is required to determine 1 period. The frequencies 4, 2 and 1 are thus determined.
 
It feels as if I'm the only one from the radio department. 1 bar is one frequency, a constant value, f(x)=k0. 2 bars is 2 frequencies, f(x)=k0+k1*Sin(a1*x+b1), etc.
 
Bookkeeper, the weather in Africa is formed because of the variable ft3, it is not defined, so you get different values.
 
lsv писал (а):
Bookkeeper, the weather in Africa is formed because of the variable ft3, it is not defined, so you get different values.

Thanks... let's see if we can figure it out...
 

Here's an example (indicator) on which I studied Fourier...
Look in the code there - it's not hard.
By default the spectrum of a periodic function is output...
You can send any indicator you want. What to do with the spectrum afterwards is your imagination.
I now want to collect patterns from the obtained spectrograms and "shove" it all into a neural network for recognition.

Uploaded the file

Files:
 
lsv:
It feels as if I'm the only one from the radio department. 1 bar is one frequency, a constant value, f(x)=k0. 2 bars is 2 frequencies, f(x)=k0+k1*Sin(a1*x+b1), etc.
As far as I remember, 8 bars in FFT produces 8 frequencies,
but half of them are symmetric to the other half (shifted by pi it seems)
So that really leaves 4.

It can't be any other way around.
One frequency (sinusoid) contains 3 parameters - G(t) = A*Sin(w*t+p)
The frequencies (w) are fixed, that leaves 2 parameters - amplitude (A) and phase (p).

In any transformation from K independent variables (bar values)
one can obtain at most K independent parameters.
I.e. from 8 bars a maximum of 4 frequencies can be obtained (2 parameters per bar)
 
klot, your file is not available for some reason. I initially wanted to use Fourier to extract the trend, i.e. as a FFT filter, but I remembered that Fourier assumes that the analyzed section repeats. I.e. if there are bars with prices 10,11, 13, 12, then Fourier assumes that they will be followed by bars 10,11, 13, 12, 10,11, 13, 12. And this spoils the whole idea.
Reason: