PYTHON = python3

all: Noise.svg Timing.svg

Noise.svg: out.noise Makefile
	echo '\
	set term svg size 640,480 noenhanced 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 noise"\
	,"$<" index 2 with lines title "filtered signal"\
	'|gnuplot

Timing.svg: out.timing Makefile
	echo '\
	set term svg size 640,480 noenhanced 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 "time to perform FFT";\
	n=1000;\
	f(x)=x*log(x)/n;\
	fit f(x) "$<"  via n;\
	plot "$<" with points title "data"\
		, f(x) with lines title sprintf("N*log(N)/%g",n);\
	'|gnuplot

out.noise: main-noise.py fft.py
	${PYTHON} $< > $@

#ns = 1024 2048 4096 8192 16384 32768
ns = $(shell echo '2^12; 2^13; 2^14; 2^15'|bc -l)
out.timing:main-timing.py fft.py
	cat /dev/null > $@
	for n in $(ns); do time -f "$$n %U" -ao $@ ${PYTHON} $< $$n; done

clean:
	rm -rf *.log log* out.* *.png *.svg *.pyc __pycache__
