calculate frequency for histgram