Bach's Chromatic Fantasy and Fugue is an amazing work. Here is a fragment from the last measures of the Fantasy. We find 3 elements in this section:
These are the diminished seventh chords used by Bach:
Before analyzing this passage we will discuss some important aspects of the diminished seventh chord.
The diminished seventh chord has its origin in the seventh degree of the harmonic minor scale and has a dominant function. In other words, we can replace a dominant chord by a diminished seventh chord. For example, the dominant chord of the A minor is E and the diminished seventh is G#. Both share three notes and if we combine the notes of both chords we obtain the dominant minor ninth chord:
Another interesting fact about this chord is that it is a symmetric chord, all the intervals are minor thirds or augmented seconds (both intervals have 3 semitones). When inverted, these chords sound as a diminished seventh in root position:
This also means that a chord can be written in four different ways. Aurally similar, although theoretically belonging to different keys.
Using this cycle of fifths progression:
We will change each chord to its equivalent diminished seventh chord (a major third above):
By arranging the notes so that each note moves chromatically (the F# moves to F) and some enharmonic changes we get the same chords used by Bach:
So the progression used by Bach - as well as that of Chopin - is based in the cycle of fifths progression. In the case of Bach, all twelve keys are visited.
Another interesting aspect in this passage is the way Bach resolves the diminished seventh chords preceding the two minor chords (D minor and G minor):
F# diminished is the VII degree of the G minor key yet it resolves into a D minor chord. Similarly G# diminished resolves into G minor. Chopin uses the diminished chord in the same way in his Prelude #4:
The only difference is that Chopin adds the minor seventh (G) to the A minor chord.
Although these two examples provided by Bach and Chopin, this use of the diminished seventh chord is not discussed in traditional harmony books. Here the diminished seventh chord resolves one half step down to the next chord (A# to A minor). In jazz harmony this resolution is called passing diminished seventh chords because it is sometimes used to move between two minor seventh chords: