This passage in Psalm is when David cried out to the Lord after he had sinned with Bathsheba.  A king, a man chosen by God who fell short.  When sin becomes a routine in your life, you are miserable.  Sins, failures and shortcoming will always be there unless you admit and confess them to the Lord.  Only then is there true joy.  The Lord knows your heart better than you do.  Live in honesty and truth.

Have mercy on me, O God,
    according to your unfailing love;
according to your great compassion
    blot out my transgressions.
 Wash away all my iniquity
    and cleanse me from my sin.
For I know my transgressions,

    and my sin is always before me.
 Against you, you only, have I sinned
    and done what is evil in your sight;
so you are right in your verdict
    and justified when you judge.
 Surely I was sinful at birth,
    sinful from the time my mother conceived me.
 Yet you desired faithfulness even in the womb;
    you taught me wisdom in that secret place.
Psalm 51:1-6