# A Makefile which goes through the design process
# for a 4th-order modulator with an OSR of 64.
# To design another modulator the designer must re-code 
# the sim.c program (using the results from realize)
# and change scaling values (determined from the unscaled
# xmax simulations.

OSR= 64
k= 2
w0= 0
# if you use a different w0, you should change the f= argument
# in the simulations which determine xmax. Also, increasing the
# number of time points to 100000 is probably wise.

ALL = ntf ntf.mag ntf.passband ntf.p ntf.r x.zero.mod \
      simx x.zero.sim sim sim.p sim.r simMax xmax \
      simsx x.zero.sims sims sims.p sims.r simsMax xmax.scaled \
      scaledCoefficients 

all: ${ALL}

release install:

clean: 
	rm -f ${ALL}

ntf:
	synthesizeNTF n=4 R=${OSR} -opt > ntf
	echo >> ntf
	realize ntf >> ntf

ntf.mag: ntf
	mag ntf > ntf.mag

ntf.passband: ntf
	mag -dB ntf 0 0.015625 > ntf.passband

ntf.p: ntf
	snrCheck ntf R=${OSR} w0=$w0 k=$k -f

x.zero.mod: ntf 
	constant 10 0 | modulator -x ntf > $@

sim.c: ntf
	@echo "You need to copy the alpha, beta, and gamma values"
	@echo "produced by the realize program to the sim.c file."

simx: sim.c 
	cc -o simx sim.c -DCOMPARATORINPUT

x.zero.sim: simx
	constant 10 0 | simx > $@

sim: sim.c
	cc -o sim sim.c

sim.p: sim
	snrCheck sim R=${OSR} w0=$w0 k=$k -f

simMax: sim.c
	cc -o simMax sim.c -DMAXIMA

xmax: simMax
	for u in .1 .15 .2 .25 .3 .35 .4 .45 .5 .55 \
	 .6 .65 .7 .75 .8 .85 .9 .95 1 ; do \
	   echo $$u `sine N=10000 f=0 A=$$u | simMax` >> $@; \
	   done
	@echo "You need to transfer the maximum x values that you want"
	@echo "to use for scaling to sim.c"

scaledCoefficients: sim.c
	cc -o pscv sim.c -DPRINTSCALEDVALUES -DSCALED
	echo >> ntf
	echo "Scaled coefficients:" >> ntf
	pscv >> ntf
	rm pscv

simsx: sim.c
	cc -o simsx sim.c -DCOMPARATORINPUT -DSCALED

x.zero.sims: simsx
	constant 10 0 | simsx > $@

sims: sim.c
	cc -o sims sim.c -DSCALED

sims.p: sims
	snrCheck sims R=${OSR} w0=$w0 k=$k -f

simsMax: sim.c
	cc -o simsMax sim.c -DMAXIMA -DSCALED

xmax.scaled: simsMax
	rm -f $@
	for u in .1 .15 .2 .25 .3 .35 .4 .45 .5 .55 \
	 .6 .65 .7 .75 .8 .85 .9 .95 1 ; do \
	   echo $$u `sine N=10000 f=0 A=$$u | simsMax` >> $@; \
	   done
