A method that automatically estimates the metrical structure of a piece of music is presented. The approach is based on the generation of a beat similarity matrix, which provides information about the similarity between any two beats of a piece of music. The repetitive structure of most music is exploited by processing the beat similarity matrix in order to identify similar patterns of beats in different parts of a piece. This principle proves to be equally effective for the detection of both duple and triple meters as well as complex meters. The use of beat positions and dynamic programming techniques allows tracking similar musical patterns formed by beats with moderate tempo deviations. The robustness of the presented approach is reflected by the results presented, where 361 songs are used in order to compare the presented approach against the use of the autocorrelation function in existing state of the art meter detection methods.