Image copyright Getty Images Image caption Williams said he respected Gaye's music "beyond words"

Pharrell Williams has denied copying Marvin Gaye's Got to Give It Up for the hit single Blurred Lines.

But the producer and singer agreed he was "channelling... that late-70s feeling" when he co-wrote the song.

Williams, Robin Thicke and rapper TI are being sued by Gaye's family over similarities between Gaye's 1977 song the 2013 hit Blurred Lines.

In court, Williams said Gaye's work was not on his mind when he wrote the song, but he later recognised a likeness.

"Sometimes when you look back on your past work, you see echoes of people."

"But that doesn't mean that's what you were doing," Williams testified in court in Los Angeles.

Williams, Thicke and rapper TI - real name Clifford Harris Jr - all deny copying Got to Give It Up for the song, a number one hit in 2013.

Expressing his admiration for Gaye, Williams said: "The last thing you want to do as a creator is take something of someone else's when you love him."

"I respect his music beyond words," he added.

Image copyright Getty Images Image caption Pharrell Williams, Robin Thicke and TI perform Blurred Lines in January 2014

During his testimony on Wednesday, the Happy star was played extracts of both his and Gaye's compositions, stripped down to their basic song structure.

Listening to the juxtaposed bass lines, Williams responded, "It sounds like you're playing the same thing", but argued that some of the note progressions had been shifted in pitch so they sounded more alike.

His comments appeared to prompt Thicke, who was attending the trial, to leave the courtroom.

Both Williams and Thicke have testified that Williams was the principle creator of Blurred Lines, which generated more than $16m (£10.8) in profits and made more than $5m (£3m) for both stars.

Speaking in court, Williams said it took him three days of "surfing around" at Burbank's Glenwood Place Studios, in June 2012, before he hit upon the composition for the 2013 song.

"In this case I started with drums," he said in court, adding that he was influenced by two other recordings he was making at that time - for Miley Cyrus and Earl Sweatshirt.

"I was doing a bunch of country-sounding music with Miley," he said. "It was like blending this country sound with this up-tempo groove."

"Once you have a groove, then you're pretty much allowing the groove to tell you what's next," he said, describing his writing process.

He said he completed the instrumentals in about an hour. Thicke joined him that evening, and they immediately started recording the vocals, Williams told the court.

Last week, Thicke testified that he had contributed little to the writing of the song.

In a pre-trial depostiondeposition he admitted he was "high on Vicodin and alcohol when I showed up at the studio" and "wanted to be more involved than I actually was".

Marvin Gaye's children - Frankie and Nona - are seeking money from sales and touring, as well as damages. During opening arguments, a lawyer for the Gayes estimated damages at $40m (£26m).

The trial continues.