Calculate frequency