def medianDetrend(flux, binWidth):
	halfNumPoints = binWidth // 2
	medians = []
	for i in range(len(flux)):
		if i < halfNumPoints:
			medians.append(np.median(flux[:i+halfNumPoints+1]))
		elif i > len(flux) - halfNumPoints - 1:
			medians.append(np.median(flux[i-halfNumPoints:]))
		else:
			medians.append(np.median(flux[i-halfNumPoints : i+halfNumPoints+1]))
	return flux - medians