Solution 1:

According to Merriam Webster, duh is an interjection which has two meanings:

  1. used to express actual or feigned ignorance or stupidity
  2. used derisively to indicate that something just stated is all too obvious or self-evident

Apparently this first appeared in 1966 (per Merriam Webster). If you look at Google NGrams, "duh" has appeared even in the 1800s but a quick look at the results shows that in the early cases "duh" was used mostly as a syllable in a foreign language or as a form of "the". You can see that there is an increase over time, regardless, after 1960.

enter image description here

The etymology of the interjection is, as you suggested, onomatopoeic in origin. One site, Think-Ink, devotes an entire page to the discussion of the word. One thing they mention is an etymology, from the American Heritage Dictionary:

Imitative of the utterance attributed to slow-witted people.

Solution 2:

The OED's says it's origin is imitative and gives a first quotation from a 1943 Merrie Melodies cartoon (as documented in J. E. Lighter's Historical Dictionary of American Slang (1994)):

Duh... Well, he can't outsmart me, 'cause I'm a moron.

Checking further, the cartoon is Jack-Wabbit and the Beanstalk starring Bugs Bunny, and the quote is from the giant. Here's some more dialogue from IMDb:

Bugs Bunny: [Nervously] Eh, what's up doc?
Giant: Duh, caught ya choppin' up my victory garden, huh?, Well don't try nuttin' funny cuz I got ya covered! [Pulls out a gun]
Bugs Bunny: [to the Giant] Hey come here Gulliver!, I want to tell you something, come here! [Giant leans over towards him]
Giant: [Bugs takes off his glove and slaps him with it] Duh, duh now why did you wanna go and do that for huh?
Bugs Bunny: You want to fight fair don't you? That means that I challenge you to a duel! Giant: Duh, duel? uh, oh yeah!, okay!

You can watch the cartoon on YouTube.