Calculating frequency in different situations