Analytical Model for wideband THz sources and detectors based on Optical Rectification and Electro-Optic Sampling