PYTHON = python3

all: Noise.svg Scaling.svg

Noise.svg: out.noise Makefile
	echo '\
	set term svg size 640,480 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

Scaling.svg: out.scaling 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 "time to perform FFT";\
	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

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

ns = 1024 2048 4096 8192 16384 32768
out.scaling:main-scaling.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__
