President Carter, reversing his fortunes of only four months ago, has swept into a broad-based lead over Sen. Edward M. Kennedy in the New Hampshire presidential primary race, according to a survey of Democratic and independent voters conducted for The Boston Globe.

In the same period, Kennedy's support has plummeted in the state he has said he must win to keep his presidential campaign alive.

Among the 231 voters whose answers in the poll showed they were likely to cast ballots in the Feb. 26 Democratic primary, Carter commanded an 18-point lead, taking 54 percent of the projected vote, compared to Kennedy's 36 percent and California Gov. Edmund G. (Jerry) Brown Jr.'s 5 percent.

The gap is even wider if the entire sample of 606 voters is considered. Among all voters interviewed, the president, who trailed Kennedy 20-68 percent last September, led 56-31 percent in the new poll. The poll showed Carter ahead in all categories of voters including liberals, young people and Catholics, traditionally strong backers of the senator.

The president appears vulnerable on issues including inflation, energy and Iran. But Kennedy, who has scheduled a major address tomorrow in Washington, faces major difficulties in exploiting these weaknesses because his unfavorability rating has increased dramatically.

The poll was taken lasy week by Research Analysis Corp. of Boston, an independent firm previously affiliated with The Globe. Telephone interviews were conducted from last Tuesday, the day after Carter won the Iowa Democratic caucuses, through last Thursday night. Only 90 of the final sample of 606 Democrats and independents were contacted Thursday, after Carter's televised State of the Union address last Wednesday night.

The favorability rating can be critical as a measure of a politician's popularity and ability to gain support. Poll participants were asked to say whether they had a very favorable, somewhat favorable somewhat unfavorable or very unfavorable opinion of each of the three Democratic canadates. Research Analysis then combined answers on the favorable and unfavorable sides to calculate favorability and unfavorability ratings.

Since September, when Research Analysis conducted its previous New Hampshire poll, Carter's favorability rating has jumped from 40 percent to 75 percent and, perhaps more important, his unfavorablity rating has dropped from 54 percent to 20 percent. It was during this period that Iranian militants took 50 Americans hostage and the Soviet Union invaded Afghanistan.

During the same period, Kennedy's favorability rating has dropped from 79 percent to 54 percent, and his unfavorability rating has nearly tripled from 16 percent to 43 percent. The senator has received much adverse publicity regarding his involvement in a fatal car accident at Chappaquiddick in 1969, but the poll results indicate relatively few voters see this as a legitimate issue in making their judgements on the candidates.