Ed Sheeran picked up his guitar and sang a snippet of his song Thinking Out Loud as he testified in his copyright infringement trial on Thursday.

The heirs of Ed Townsend, who wrote Let's Get It On with Marvin Gaye, are suing the British singer for allegedly copying parts of the 1973 song while writing his 2014 ballad Thinking Out Loud.

Sheeran returned to the witness stand in Manhattan Federal Court on Thursday and demonstrated the four-chord sequence at the heart of his song on his acoustic guitar.

He performed part of what he insisted was the first version of Thinking Out Loud, revealing that the key lyric he and Amy Wadge originally wrote was "I'm singing out now" instead of "thinking out loud". He also sang the song's opening line, "When your legs don't work like they used to before."

During his testimony, which lasted almost an hour, the 32-year-old explained that he and Wadge wrote the song during a two-day writing session at his home in England. He recalled how stepped out of the shower and heard Wadge strumming the chords and thinking, "We need to do something with that."

He revealed the process of writing the song didn't take very long and they completed it within a day, with the lyrics being inspired by the longtime love between his grandparents.

The singer is expected to return to the stand for cross-examination when the trial resumes on Monday.