A period of rising hopes within President Fidel Castro's government for better relations with the United States has ended in bitter disappointment, according to Cuban officials and foreign diplomats.

The result has been a distinctly sharpened tone in official pronouncements on the United States. Diplomats say this is a consequence of Cuba having reassessed the possibilities for less acrimonious dealings with Washington.

The dimming of these hopes -- which, in Cuban eyes, had been building up for six months -- could lead to hardened Cuban positions in U.S.-led negotiations on Namibian independence and withdrawal of Cuban troops from Angola, a European diplomat predicted. But it is unlikely to foster radical changes in Cuban actions in Latin America, where the Cuban leader is successfully pursuing contacts with governments previously leery of his revolutionary ideology, Latin diplomats explained.

Cuban expectations were reversed mainly by the activation of Radio Marti, a U.S. broadcasting station directed at Cuba despite strong protests from Castro's government, and by recent South African actions in Angola that the Cuban leader said were a result of U.S. connivance with the white-supremacist government in Pretoria.

In addition, diplomatic sources said, Cuban government officials were informed of a hostile remark by President Reagan -- "Cuba si, Castro no" -- just as Radio Marti went on the air May 20. This was taken as the end of what Cuban Foreign Ministry officials had assessed as an effort on Reagan's part to avoid belligerent comments on Cuba since beginning his second term, the sources reported.

Many Cuban officials doubted up to the last moment that Radio Marti would go on the air, according to Cubans and others. This analysis apparently flowed from their belief that the Reagan administration was seeking to avoid conflict as much as possible, given the two countries' fundamental hostility, they said.

Moreover, the informants added, unexpected delays in getting Radio Marti started had raised hopes here that the administration was rethinking the project, using the delays to stall for time while seeking a political opening to abandon it. Some U.S. congressional aides also had speculated along these lines as the delays piled up.

The element of surprise contributed to Cuban rage when the government was informed by the U.S. interests section here at about 3:30 p.m. on Sunday, May 19, that broadcasts were to begin the next morning, the diplomats said.

Castro referred to this in his government's announcement May 20 of Cuban reprisals. The announcement, handed to U.S. diplomats here at 2:30 a.m., said the station went on the air "in a strangely secretive and surprise manner, without prior notice to the U.S. press or the government of Cuba."

Vice President Carlos Rafael Rodriguez told acquaintances the Cuban leadership also viewed Radio Marti with special concern because such a facility was outlined 4 1/2 years ago as part of what is called here "the Santa Fe document."

The document summarized the work of a group of conservative U.S. specialists on Latin America at a meeting in Santa Fe, N.M., shortly after Reagan's first election, laying out what they thought should be his administration's policy in the area. Although little talked about in Washington, the program is regarded in Cuba and, to some extent, in Nicaragua as an important guide to Reagan's policies toward Castro and the Sandinista revolution.

The mention of a broadcast facility among the Santa Fe ideas made Radio Marti seem all the more hostile to Cuban leaders, inserting it into what they regard as a semiofficial schedule for diplomatic aggression that also mentions military attack as an ultimate possibility, a well-informed diplomat explained.

But emphasis on the Santa Fe document as a source of Reagan administration policy had been tempered here in recent months by shifts that led officials to the hope for improved relations after all. Diplomatic and Cuban sources said these included the U.S.-Cuban immigration accord last December, the U.S. role in seeking agreement for Namibian independence, and Cuban officials' belief that Reagan was purposely softening his rhetoric directed at Cuba.

In addition, the sources said, some Cuban officials had speculated that Reagan's second term would be directed toward conciliation rather than the confrontation that they perceived as the hallmark of his first term. Although no one had illusions of shattering a quarter-century of enmity at once, they added, Cuban officials had expressed hope that the venom level in dealings could be reduced.

"Some very positive things were going on," recalled one middle-level Cuban official.

Deputy Foreign Minister Ricardo Alarcon recently mentioned to acquaintances, for example, that the atmosphere in his talks with U.S. diplomats on the immigration issue had been unusually free of acrimony. In addition, Castro told interviewers in January he would cooperate with U.S. mediation in southern Africa and said it had the potential to "exercise a positive influence in the international sphere."

The capture of a South African commando squad in Angola last week -- soon after Radio Marti went on the air -- apparently shook Castro's confidence in the U.S. efforts. The Communist Party newspaper Granma accused the United States and South Africa of working together in "an alliance of freebooters" and said South Africa's alleged violation of the 15-month-old Lusaka agreement puts into question Washington's role as mediator.

Despite Reagan administration protests to South Africa over the commando force, Castro said in a speech last week that South Africa and the United States are "allies" seeking to prevent Namibian independence. Without specifically refusing further cooperation with U.S. efforts in southern Africa, he linked the United States to the foiled raid and suggested the response may be to send more Cuban troops to Angola.