One of the pinnacles of form in classical Western music, the fugue is often used in the teaching of music analysis and composition. Fugues alternate between instances of a subject and other patterns and modulatory sections, called episodes. Musicological analyses are generally built on these patterns and sections. We have developed several algorithms to perform an automated analysis of a fugue, starting from a score in which all the voices are separated. By focusing on the diatonic similarities between pitch intervals, we detect subjects and countersubjects, as well as partial harmonic sequences inside the episodes. We also implemented tools to detect subject scale degrees, cadences, and pedals, as well as a method for segmenting the fugue into exposition and episodic parts. Our algorithms were tested on a corpus of 36 fugues by J. S. Bach and Dmitri Shostakovich. We provide formalized ground-truth data on this corpus as well as a dynamic visualization of the ground truth and of our computed results. The complete system showed acceptable or good results for about one half of the fugues tested, enabling us to depict their design.