#!/bin/tcsh

### Script for Part 1 of AFNI Time Series Analysis videos
### - Creates synthetic data for linear regression
### - plots results into files s1a.*.png

# create a file with the dependent variable ('data')
# to be fitted by various models

set scale = 1.7
1deval -num 100 -dt 0.01 \
       -expr "abs(sin(${scale}*t)+gran(0,0.1))" > s1a.temp.data.1D

# fit data with a polyomial of order 1 (straight line)

3dTfitter -RHS s1a.temp.data.1D  \
          -polort 1              \
          -prefix NULL           \
          -fitts s1a.temp.fitts.1.1D

# fit data with a polynomial of order 2 (quadratic = parabola)

3dTfitter -RHS s1a.temp.data.1D  \
          -polort 2              \
          -prefix NULL           \
          -fitts s1a.temp.fitts.2.1D

# plot data only

1dplot -one -dt 0.01 -xaxis 0:1:10:5   \
       -dashed 0:2:3 -png s1a.data     \
       -ynames Data -                  \
       s1a.temp.data.1D

# plot data + line fit

1dplot -one -dt 0.01 -xaxis 0:1:10:5   \
       -dashed 0:2:3 -png s1a.fit1     \
       -ynames Data Linear -           \
       s1a.temp.data.1D s1a.temp.fitts.1.1D

# plot data + line fit + quadratic fit

1dplot -one -dt 0.01 -xaxis 0:1:10:5   \
       -dashed 0:2:3 -png s1a.fit2     \
       -ynames Data Linear Quadratic - \
       s1a.temp.data.1D s1a.temp.fitts.1.1D s1a.temp.fitts.2.1D

# toss out the trash

\rm -f s1a.temp.*.1D
