Before you even try to write a letter of complaint, see if you can have a word with the person who's causing the noise. If it's a neighbour or somebody you know well, talking face to face might solve the problem without further difficulties. If the problem is coming from a stranger or if you've already talked without results, then it's time to sit down and write a letter.
Decide to whom you'll address the letter. If this is the first time you'll complain, you might want to send the letter to the person causing the noise. Don't threaten legal action or be rude. Instead, use this first letter as a way to inform the person that the noise is not acceptable. You can suggest possible solutions. For example, ask the person to keep his dog indoors after 10 p.m. so he doesn't bark.
Write to the building manager if you've already talked to the person causing the noise and obtained no results. If you live in a rental house, write a letter to your landlord. If you live in a building, you could collect signatures from other people who are also experiencing the same problem. Include those signatures at the end of the letter or as a separate sheet inside the same envelope.
Make the letter very specific. Explain the type of noise you're hearing, how often it happens and at what times. Go into details about why the noise is disrupting your life: you can't sleep, you can't concentrate if you work from home, your baby wakes up constantly and so on. Try to be reasonable. "I don't like the music" is not a good reason to complain. However, "The music is so loud I can still hear it when I close the windows" is a reasonable problem.
Explain what steps you've taken to solve the problem. Maybe you talked to the neighbour or checked the noise ordinances in effect in the city. Also explain what you expect. For example, say you want the noise to stop completely, or you expect silence before 8 a.m. End with a short note saying what you'll do if you don't see any results. Say something like, "If the noise doesn't stop, I'll have to contact the appropriate authorities." This makes it clear that you're serious about the problem.