Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello.
Ive looked everywhere, but cant find this.
I would like to take a discrete fourier transform of some of my data in the script load in qlikview.
This will almost certainly involve a couple of loops within a resident table, but manually coded looping
within the load script is a bit of a mystery to me - also setting variables and so on.
Does anyone know if this has been done before, and if so where I might find some example code?
Its actually quite a simple calculation, but it does involve a couple of nested loops, and
I dont think qlikview syntax is made for it?
Sure it must be possible.
Any help much appreciated !
Thanks
Hi,
maybe one solution might be:
LET table='DAY';
LET field='FORDKWH';
LET N= NoOfRows('$(table)');
FOR k= 0 to N-1
[DFT Table]:
LOAD $(k) AS k,
Sum($(field)*cos(2*Pi()*$(k)*(RecNo()-1)/$(N)))/$(N) as REAL,
Sum(-$(field)*sin(2*Pi()*$(k)*(RecNo()-1)/$(N)))/$(N) as IMAG
Resident $(table);
NEXT;
hope this helps
regards
Marco
OK found the answer myself. this may be useful to someone. I hope so.
Its extremely slow for large amount of records because of the two loops.
Speeding it up is the next challenge!
DAY is a table containing rows of sampled signal data in column FORDKWH
[DFT Table] contains 3 columns/fields
k - frequency number
REAL - real co-efficients - amplitudes of Cosine harmonics
IMAG - imaginary co-efficients - amplitudes of Sine harmonics.
Will post more if I manage to speed this up -
Let table='DAY';
let field='FORDKWH';
Let N= NoOfRows('$(table)'); // N=number of data points
Let K=$(N); // K = frequency number.
// frequency loop - corresponds to rows of table
for k= 0 to $(K)-1
let totalreal=0;
let totalimag=0;
// inner loop for SUM
for n = 0 to $(N)-1
Let kwh = Peek('$(field)',$(n),'$(table)');
let angle=2*Pi()*$(k)*$(n)/$(N);
let totalreal = $(totalreal) + $(kwh)*cos($(angle));
let totalimag = $(totalimag) - $(kwh)*sin($(angle));
next
totalreal=$(totalreal)/$(N);
totalimag=$(totalimag)/$(N);
[DFT Table]:
LOAD
$(k) AS k,
$(totalreal) AS REAL,
$(totalimag) AS IMAG
AutoGenerate 1;
Next;
Hi,
maybe one solution might be:
LET table='DAY';
LET field='FORDKWH';
LET N= NoOfRows('$(table)');
FOR k= 0 to N-1
[DFT Table]:
LOAD $(k) AS k,
Sum($(field)*cos(2*Pi()*$(k)*(RecNo()-1)/$(N)))/$(N) as REAL,
Sum(-$(field)*sin(2*Pi()*$(k)*(RecNo()-1)/$(N)))/$(N) as IMAG
Resident $(table);
NEXT;
hope this helps
regards
Marco
Wow, this so much reminds me of my studies, never thought I'd see Fourier and Qlik in the same post!
wow! that ran fast. THanks very much!