#!/usr/bin/python
#
# Script for plotting sin(f*pi*x) on x in [0,1] together with 
# sample points with frequency fT.
# Use option -a to automatically compute "correct" fT=2*f+1.
#
# author: Tobias Neckel
# date:   27.01.13
#
# INPUT: f	frequency for the function plot
# 	 fT 	frequency for the sampling (option -a ignores this)
#
import optparse
import sys
from pylab import *

#p = optparse.OptionParser()
#p.add_option("-a", "--auto", action="store_true", dest="auto", help="computes fT automatically correct using f")
#(options, args) = p.parse_args()

#f  = int(sys.argv[1])
#if options.auto:
#  fT=2*f+1; 
#else:
#  fT = int(sys.argv[2])

f=8
#fT = 2*f+1
fT = 10

x=linspace(0,1,f*100)

#plot shannon sample points
xT=linspace(0,1,fT); 
plot(xT,zeros(xT.shape),'ok');
plot(xT,sin(f*pi*xT),'dk');
vlines(xT, [0], sin(f*pi*xT), color='k', linestyles='solid')

#plot function
func = sin(f*pi*x)
plot(x,func); 

#setup general plotting properties
title("plot of function sin("+str(f)+"*pi*x) and sample points for fT=" + str(fT))
xlabel("x")
ylabel("y=sin("+str(f)+"*pi*x)")
grid(True)
axis([-.05,1.05, min(func)-.05*abs(min(func)),max(func)+.05*max(func)])
show()


