improved qft matrix generation