all:Out.noise.svg Out.timing.svg

Out.noise.svg: out.noise.data Makefile
	echo '\
	set term svg size 800,600 background "white" font "Arial,18";\
	set out "$@";\
	set title "Noise filtering using DFT";\
	set xlabel "time";\
	set ylabel "signal";\
	plot \
	 "$<" index 0 with lines title "original signal"\
	,"$<" index 1 with lines title "signal with random noise"\
	,"$<" index 2 with lines title "amplitude filtered signal"\
	,"$<" index 3 with lines title "frequency filtered signal"\
	,"$<" index 4 with lines lc "black" title "least squares filtered signal"\
	'|gnuplot

Out.timing.svg: out.timing.data Makefile
	echo '\
	set term svg size 640,480 background "white" font "Arial,18";\
	set out "$@";\
	set title "FFT time as function of data set size";\
	set key left;\
	set xlabel "data set size N";\
	set ylabel "seconds to perform FFT";\
	set format x "%2.0s*10^{%S}";\
	set xtics 100000;\
	a=1;\
	f(x)=a*x*log(x);\
	fit f(x) "$<"  via a;\
	plot\
	 "$<" with points title "data" \
	,f(x) with lines title "N*log(N)";\
	'|gnuplot

#N = $(shell echo '4*2^12; 4*2^13; 4*2^14; 4*2^15'|bc -l)
N = $(shell echo '2^16; 2^17; 2^18; 2^19'|bc -l)
out.timing.data:main.exe #Makefile
	>$@
	for n in $(N); do time -f "$$n %U" -ao $@ mono ./$< $$n; done

out.noise.data:main.exe
	mono ./$< > $@

main.exe: main.cs fft.cs matlib.dll
	mcs -out:$@ $(addprefix -r:,$(filter %.dll,$^))  $(filter %.cs,$^)

matlib.dll: \
	../matrix/matrix.cs\
	../matrix/vector.cs\
	../QR/givensqr.cs\
	../complex/complex.cs\
	../complex/cmath.cs
	mcs -target:library -out:$@ $^

clean:
	$(RM) *.o [Oo]ut* *.log log* *.exe *.dll *.svg

TEST=$(shell echo '2^11; 2^12; 2^13'|bc -l)
