Skip to content

Commit a35e068

Browse files
author
Ivan Morozov
committed
26_09_2020
1 parent c7b9f16 commit a35e068

33 files changed

+12438
-7559
lines changed

README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# SIGNAL, 2018-2020, [email protected]
22
# FREQUENCY IDENTIFICATION, QUASIPERIODIC DECOMPOSITION AND CHAOS INDICATORS
33

4+
45
*Files*:
56
1) 'SRC_SIGNAL.WL' WM code (use Get[] function to load or see WM examples)
67
2) 'signal_examples.nb' WM examples
78
3) 'data' directory with WM examples' data
8-
4) 'signal.f90' FORTRAN code
9-
5) 'signal.h' C INTERFACE
9+
4) 'src' FORTRAN code
1010
6) 'examples' FORTRAN and C examples
11-
7) 'epics' EPICS
11+
7) 'epics' EPICS examples
1212

1313
*Dependencies*:
1414
Basic FORTRAN functions can be used without external libraries.
1515
FFT_EXTERNAL_ uses FFTW3.
1616
SVD related procedures use BLAS, LAPACK and ARPACK.
17-
GSL library will be used for special functions.
17+
Special functions use GSL library.

SRC_SIGNAL.WL

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,18 @@ S$PAD$ZEROS[ (* -- PAD ZEROS (LIST) *)
236236
RPAD_Integer, (* -- NUMBER OF RIGHT ZEROS (INTEGER) *)
237237
SIGNAL_List (* -- SIGNAL (LIST) *)
238238
] := Developer`ToPackedArray[Flatten[List[ConstantArray[N[0],LPAD],SIGNAL,ConstantArray[N[0],RPAD]]]] ;
239-
ClearAll[S$NEXT$NUMBER] ;
240-
S$NEXT$NUMBER::usage = "
241-
S$NEXT$NUMBER[NUMBER] -- return next power of two number greater then <NUMBER> (integer)
239+
ClearAll[S$ROUND$UP] ;
240+
S$ROUND$UP::usage = "
241+
S$ROUND$UP[NUMBER] -- return next power of two number greater then <NUMBER> (integer)
242242
" ;
243-
S$NEXT$NUMBER[NUMBER_Integer] := 2^Ceiling[Log[N[NUMBER]]/Log[N[2.0]]] ;
243+
S$ROUND$UP[NUMBER_Integer] := 2^Ceiling[Log[N[NUMBER]]/Log[N[2.0]]] ;
244244
ClearAll[S$PAD$LENGTH] ;
245245
S$PAD$LENGTH::usage = "
246246
S$PAD$LENGTH[NUMBER] -- return numbers to pad (sum) to the next power of two
247247
" ;
248248
S$PAD$LENGTH[NUMBER_Integer] := Block[
249249
{TOTAL},
250-
TOTAL = Subtract[S$NEXT$NUMBER[NUMBER],NUMBER] ;
250+
TOTAL = Subtract[S$ROUND$UP[NUMBER],NUMBER] ;
251251
List[Floor[Divide[TOTAL,Plus[1,1]]],Ceiling[Divide[TOTAL,Plus[1,1]]]]
252252
] ;
253253
S$PAD$ZEROS[SIGNAL_List] := Block[

epics/Makefile

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ PROGRAM = decomposition
88
INCDIR += $(EPICS_BASE)/include/os/Linux
99
INCDIR += $(EPICS_BASE)/include
1010
INCDIR += $(EPICS_BASE)/include/compiler/gcc
11-
INCDIR += .
11+
INCDIR += ../src
1212

1313
LIBDIR += $(EPICS_BASE)/lib/$(EPICS_HOST_ARCH)
14-
LIBDIR += .
14+
LIBDIR += ../src
1515

1616
LIB += ca Com
1717
LIB += m
@@ -36,11 +36,8 @@ all: $(PROGRAM)
3636
.PHONY: clean realclean
3737
clean:
3838
rm -rf build_*
39-
rm -f libsignal.a
40-
41-
realclean: clean
42-
rm -f $(foreach file,$(PROGRAM),$(BINDIR)/$(file))
43-
rm -f libsignal.a
39+
rm -f decomposition
40+
rm -f *.mod *.smod
4441

4542
build_%:
4643
mkdir $@
@@ -58,13 +55,11 @@ build_$(EPICS_HOST_ARCH)/$(PROGRAM): $(OBJ)
5855
$(CC) -o $@ $^ $(LDFLAG)
5956
# $(CXX) -o $@ $^ $(LDFLAG)
6057

61-
build_$(EPICS_HOST_ARCH)/%.o: %.c libsignal.a signal.h
58+
build_$(EPICS_HOST_ARCH)/%.o: %.c ../src/libsignal.a ../src/signal.h
6259
$(CC) -c $(CPPFLAG) $(CFLAG) $< -o $@
6360
# $(CC) -c $(CPPFLAG) $(CFLAG) $< -o $@
6461

65-
libsignal.a: ../signal.f90
66-
$(FC) -c -cpp -fPIC -frecursive -Wno-unused-function -std=f2018 -Wall -pedantic -O3 -ffast-math -march=native ../signal.f90
67-
ar rcs libsignal.a signal.o
68-
rm -f signal.o signal.mod
62+
../src/libsignal.a: ../src/*.f90
63+
make -C ../src
6964

7065
-include build_$(EPICS_HOST_ARCH)/*.d

epics/README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

epics/decomposition

-1.17 MB
Binary file not shown.

epics/decomposition.c

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,60 @@ int main(){
3838
SEVCHK(ca_pend_io(pend), "error: ca_pend_io") ;
3939

4040
// format
41+
int flag = 0 ;
4142
double signal[2*length] ;
4243
convert_real_(&length, read, signal) ;
4344

4445
// set window
4546
int order = 2 ;
4647
double window[length] ;
47-
window_(&length, &order, window) ;
48+
window_cos_(&length, &order, window) ;
4849
double total = 0.0 ;
4950
for(int i = 0; i < length; i++){
5051
total = total + window[i] ;
5152
}
5253

53-
int flag ;
54+
double sequence[2*length] ;
55+
56+
// pre-process
57+
remove_window_mean_(&length, &total, window, signal, sequence) ;
58+
*signal = *sequence ;
59+
60+
// apply window
61+
apply_window_(&length, window, signal, sequence) ;
62+
*signal = *sequence ;
63+
5464
int peak ;
55-
double frequency ;
65+
int method = 2 ;
66+
double frequency ;
5667

57-
// frequency (bin)
58-
flag = 0 ;
68+
// frequency_ (bin)
5969
peak = 0 ;
60-
frequency = frequency_(&flag, &peak, &length, &total, window, signal) ;
70+
frequency = frequency_(&flag, &peak, &method, &length, signal) ;
6171
printf("frequency_\n") ;
6272
printf("%.15f\n", frequency) ;
6373
printf("\n") ;
6474

65-
// frequency (peak)
66-
flag = 0 ;
67-
peak = 1 ;
68-
frequency = frequency_(&flag, &peak, &length, &total, window, signal) ;
75+
// frequency_ (peak)
6976
printf("frequency_\n") ;
70-
printf("%.15f\n", frequency) ;
77+
for (int i = 1; i <= 3 ; i++)
78+
{
79+
peak = i ;
80+
frequency = frequency_(&flag, &peak, &method, &length, signal) ;
81+
printf("%.15f\n", frequency) ;
82+
}
7183
printf("\n") ;
7284

73-
// decomposition (subtract)
74-
int loop = 3 ;
85+
// restore signal
86+
convert_real_(&length, read, signal) ;
87+
88+
int mode ;
89+
int loop = 3 ;
7590
double fre_amp[loop], cos_amp[loop], sin_amp[loop] ;
76-
peak = 0 ;
77-
decomposition_(&flag, &peak, &length, &total, window, signal, &loop, fre_amp, cos_amp, sin_amp) ;
91+
92+
// decomposition_ (subtract)
93+
mode = 0 ;
94+
decomposition_(&flag, &method, &mode, &length, &length, &total, window, signal, &loop, fre_amp, cos_amp, sin_amp) ;
7895
printf("decomposition_\n") ;
7996
for(int i = 0; i < loop; i++){
8097
printf("%.15f %.15f %.15f\n", fre_amp[i], cos_amp[i], sin_amp[i]) ;
@@ -84,31 +101,46 @@ int main(){
84101
}
85102
printf("\n") ;
86103

87-
// frequency list (subtract)
88-
peak = 0 ;
89-
frequency_list_(&flag, &peak, &length, &total, window, signal, &loop, fre_amp) ;
104+
// frequency_list_ (subtract)
105+
frequency_list_(&flag, &method, &mode, &length, &length, &total, window, signal, &loop, fre_amp) ;
106+
printf("frequency_list_\n") ;
107+
for(int i = 0; i < loop; i++){
108+
printf("%.15f\n", fre_amp[i]) ;
109+
}
110+
printf("\n") ;
111+
112+
// decomposition_ (peak)
113+
mode = 1 ;
114+
decomposition_(&flag, &method, &mode, &length, &length, &total, window, signal, &loop, fre_amp, cos_amp, sin_amp) ;
115+
printf("decomposition_\n") ;
116+
for(int i = 0; i < loop; i++){
117+
printf("%.15f %.15f %.15f\n", fre_amp[i], cos_amp[i], sin_amp[i]) ;
118+
fre_amp[i] = 0.0 ;
119+
cos_amp[i] = 0.0 ;
120+
sin_amp[i] = 0.0 ;
121+
}
122+
printf("\n") ;
123+
124+
// frequency_list_ (peak)
125+
frequency_list_(&flag, &method, &mode, &length, &length, &total, window, signal, &loop, fre_amp) ;
90126
printf("frequency_list_\n") ;
91127
for(int i = 0; i < loop; i++){
92128
printf("%.15f\n", fre_amp[i]) ;
93129
}
94130
printf("\n") ;
95131

96-
// amplitude list (subtract)
132+
// amplitude_list_
97133
amplitude_list_(&flag, &length, &total, window, signal, &loop, fre_amp, cos_amp, sin_amp) ;
98134
printf("amplitude_list_\n") ;
99135
for(int i = 0; i < loop; i++){
100136
printf("%.15f %.15f %.15f\n", fre_amp[i], cos_amp[i], sin_amp[i]) ;
137+
cos_amp[i] = 0.0 ;
138+
sin_amp[i] = 0.0 ;
101139
}
102140
printf("\n") ;
103141

104-
// fit_
142+
// fit_ (least squares)
105143
printf("fit_ \n") ;
106-
for (int i = 1; i <= loop ; i++)
107-
{
108-
peak = i ;
109-
frequency = frequency_(&flag, &peak, &length, &total, window, signal) ;
110-
fre_amp[i-1] = frequency ;
111-
}
112144
double mean ;
113145
double error ;
114146
fit_(&length, data, &loop, fre_amp, &mean, cos_amp, sin_amp, &error) ;

epics/signal.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/Makefile

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ cc = gcc-10
1111
fcf = -cpp -std=f2018 -fPIC -frecursive -Wall -pedantic -O3 -ffast-math -march=native
1212
ccf = -std=c99 -Wall -pedantic -O3 -ffast-math -march=native
1313

14+
src = ../src
15+
mod = ../src/mod
16+
1417
all: example01
1518
all: example02
1619
all: example03
@@ -20,40 +23,34 @@ all: example06
2023
all: example07
2124
all: example08
2225

23-
example01: libsignal.a signal.mod example01.f90
24-
$(fc) -o example01 $(fcf) -L. -I. example01.f90 $(lib)
25-
26-
example02: libsignal.a signal.mod example02.f90
27-
$(fc) -o example02 -fopenmp $(fcf) -L. -I. example02.f90 $(lib)
26+
example01: example01.f90 ../src/libsignal.a
27+
$(fc) -o example01 $(fcf) -L$(src) -I$(src) -I$(mod) example01.f90 $(lib)
2828

29-
example03: libsignal.a signal.mod example03.f90
30-
$(fc) -o example03 $(fcf) -L. -I. example03.f90 $(lib)
29+
example02: example02.f90 ../src/libsignal.a
30+
$(fc) -o example02 -fopenmp $(fcf) -L$(src) -I$(src) -I$(mod) example02.f90 $(lib)
3131

32-
example04: libsignal.a signal.mod example04.f90
33-
$(fc) -o example04 $(fcf) -L. -I. example04.f90 $(lib)
32+
example03: example03.f90 ../src/libsignal.a
33+
$(fc) -o example03 $(fcf) -L$(src) -I$(src) -I$(mod) example03.f90 $(lib)
3434

35-
example05: libsignal.a signal.mod example05.f90
36-
$(fc) -o example05 $(fcf) -L. -I. example05.f90 $(lib)
35+
example04: example04.f90 ../src/libsignal.a
36+
$(fc) -o example04 $(fcf) -L$(src) -I$(src) -I$(mod) example04.f90 $(lib)
3737

38-
example06: libsignal.a signal.mod signal.h example06.c
39-
$(cc) -o example06 $(ccf) -L. -I. example06.c $(lib)
38+
example05: example05.f90 ../src/libsignal.a
39+
$(fc) -o example05 $(fcf) -L$(src) -I$(src) -I$(mod) example05.f90 $(lib)
4040

41-
example07: libsignal.a signal.mod example07.f90
42-
$(fc) -o example07 -fopenmp $(fcf) -L. -I. example07.f90 $(lib)
41+
example06: example06.c ../src/libsignal.a ../src/signal.h
42+
$(cc) -o example06 $(ccf) -L$(src) -I$(src) -I$(mod) example06.c $(lib)
4343

44-
example08: libsignal.a signal.mod example08.f90
45-
$(fc) -o example08 $(fcf) -L. -I. example08.f90 $(lib)
44+
example07: example07.f90 ../src/libsignal.a
45+
$(fc) -o example07 -fopenmp $(fcf) -L$(src) -I$(src) -I$(mod) example07.f90 $(lib)
4646

47-
libsignal.a: signal.o
48-
ar rcs libsignal.a signal.o
47+
example08: example08.f90 ../src/libsignal.a
48+
$(fc) -o example08 $(fcf) -L$(src) -I$(src) -I$(mod) example08.f90 $(lib)
4949

50-
signal.o: ../signal.f90
51-
$(fc) -c $(fcf) -Wno-unused-function ../signal.f90
50+
../src/libsignal.a: ../src/*.f90
51+
make -C ../src
5252

5353
clean:
54-
rm -f libsignal.a
55-
rm -f signal.o
56-
rm -f signal.mod
5754
rm -f example01
5855
rm -f example02
5956
rm -f example03
@@ -62,3 +59,4 @@ clean:
6259
rm -f example06
6360
rm -f example07
6461
rm -f example08
62+
rm -f *.mod *.smod

examples/README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)