Analysis and design of a CMOS-based terahertz sensor and readout