The patient sits on a hospital gurney. The doctor asks how she feels, takes her blood pressure and gives her a capsule to swallow. She is then led to a brain scanner that resembles a giant washing machine, and she lies in front of it before it sucks her in. Doctors study a series of vivid images of her head and brain, looking for activity before she is allowed to leave the scanner. The patient is asked who she would like to have with her at this moment. She replies: "My husband."

When asked how she feels, she replies: "Light. It's pleasant. There's an airiness and openness to the senses. A slight heightening of sensory perception, which I liked. The visual feeling is vivid. The colours are lush, which I enjoy. I might be a bit more alert to sounds. I feel physically relaxed and that is a pleasure."

The patient is the writer, Lionel Shriver, and she has just taken the drug MDMA as part of an experiment that will be shown on Channel 4 at the end of this month. She is one of six volunteers who also include the actor Keith Allen and a former MP who will be shown taking the drug and undergoing a series of tests, some of which will be done in the scanner in order to see the change in brain activity caused by MDMA.

The experiment has been designed by Val Curran, professor of psychology at University College London, and David Nutt, professor of neuropsychopharmacology at Imperial College London. It will feature 26 volunteers, only a small number of whom will appear on television.

The broadcasting of controversial research will seem to many like a publicity stunt, an easy way to court controversy and increase viewing figures. But there is a real concern among many scientists that the government's classification of the drug as Class A overstates the danger it poses to society and inhibits important research that could help people suffering from depression and post-traumatic stress disorder (PTSD).

A spokesman for the Home Office disagrees: "Televising the use of illegal drugs risks trivialising a serious issue. Our licensing regime allows legitimate research to take place in a secure environment so that harmful drugs can't get into the hands of criminals. There is no evidence to suggest that the current listing of MDMA as a Schedule 1 substance is a barrier to attracting funding for legitimate purposes."

Nutt insists that without funding from Channel 4 the study wouldn't have been possible: "We have failed to get money for research from conventional sources, which is why the Channel 4 intervention is fantastic. Nearly half a million people are believed to take ecstasy or MDMA every year in the UK, but there has been very little research into what it does in the brain. These experiments will give us a much clearer picture of the fundamental effects of MDMA on the resting brain than anyone has been able to get before."

Yet to some, the prominence of the experiments on primetime television might be seen as an endorsement of drug-taking. Professor of psychology Andy Parrott of Swansea University, who has researched MDMA for 15 years, says: "Once people start writing that MDMA is being used for therapy, kids will look at that and think it's a safe drug."

MDMA, or methylenedioxy- methylamphetamine, was first patented in 1912 by German scientists looking for a substance to control bleeding. The US military experimented with it in the 1950s and this may have led to instances of it being used recreationally in the US in the 1970s. In 1976, an American chemist, Alexander Shulgin, who became known as the godfather of ecstasy, took MDMA himself as part of a personal investigation of psychoactive substances. Shulgin was an industrial chemist who had personal experience of psychedelics and worked closely with America's Drug Enforcement Agency. He described the feelings MDMA induced as "an easily controlled altered state of consciousness with emotional and sensual overtones". In his journal he wrote: "I feel absolutely clean inside, and there is nothing but pure euphoria. The cleanliness, clarity, and marvellous feeling of solid inner strength continued… through the next day. I am overcome by the profundity of the experience."

Shulgin promoted MDMA among psychologists, who began to use it as an aid to psychotherapy. But its use in therapy was about to become overshadowed by its popularity as a recreational drug. MDMA became popular in nightclubs in Dallas in the early 80s and then spread through the rest of the world. By 1987, rebranded by clubland as ecstasy and often mixed with small amounts of other drugs such as ketamine, heroin and acid, and fillers and binding agents such as corn starch and cellulose, it had become a major part of British youth culture.

Drugs like MDMA (but not MDMA explicitly) were made illegal in 1977 in the UK and in the US in 1985, but this did little to prevent its immense popularity as a recreational drug.

The case of Donna Kilgore was the first widely publicised success of MDMA in treating a psychiatric condition. In 1993, she was raped by a stranger who burst into her home in Alaska. Her cries alerted the police who caught the rapist. After the attack, Kilgore tried to get on with her life, which was made easier by the fact that she could not remember much of her experience. After four years, she began having flashbacks, panic attacks, fits of anger, migraines and faints. She consulted a series of psychiatrists who prescribed a series of drugs. Some of the drugs dulled the pain, others exacerbated it. Finally, in 2002, a new psychiatrist linked her condition to her rape for the first time, diagnosed her with PTSD, and sent her to Dr Michael Mithoefer in South Carolina. Mithoefer was one of many therapists who were convinced that MDMA could play a major role in curing patients of a range of psychiatric disorders, including PTSD. He was licensed to carry out experiments with MDMA and Kilgore was his first patient.

The result was dramatic. "What MDMA did was clear the fog so I could see. Down there was guilt, anger, shame, fear. And it wasn't so bad. I thought, 'I can do this,'" she said in an interview. "'This fear is not going to kill me.' I remembered the rape from start to finish – those memories I had repressed so deeply." Clearly, this is just one patient's experience: many more, larger studies would be needed before MDMA is adopted as a treatment.

The dangers of MDMA, or at least ecstasy, had already been highlighted in the UK by the death of Leah Betts who died at the age of 18 in 1995 after taking an ecstasy tablet which contributed to her death. The tragedy of Leah Betts and other similar deaths has tended to be the driver of government policy rather than the experience of Donna Kilgore. The government has rejected expert advice on two occasions to change the classification of the drug from Class A, which also includes heroin and cocaine, to Class B, which includes cannabis.

The division between some scientists and government was demonstrated in 2009 when David Nutt was chairman of the government's Advisory Council on the Misuse of Drugs. He pointed out that horse riding was more dangerous than taking ecstasy, pointing to statistics that showed that horse riding had an adverse event once in every 350 outings while social ecstasy use led to an adverse event once in every 10,000 experiences. The then home secretary, Jacqui Smith reacted angrily to Nutt's remarks and insisted he apologise to the families of people who had died after taking ecstasy. Later the same year, Nutt was dismissed after he issued a paper that classified drugs according to the harm they caused, placing alcohol and tobaccos as more harmful than drugs such as ecstasy and cannabis.

In Nutt's study, volunteers' pre-drug experience, unlike that of clubbing ecstasy users, is deliberately sterile. For the documentary they undergo two days of tests, one with MDMA and one with a placebo (clearly what might make good television doesn't make the most rigorous of trials). Both days are identical. They arrive at Hammersmith hospital where they change into medical scrubs and begin a series of tests. First their breath and urine are analysed to ensure they have not been taking alcohol or drugs. Some of the volunteers failed and were told they could not participate in the experiment.

The volunteers have more medical tests and fill out questionnaires before a nurse arrives with a brown envelope containing a capsule. The patients and researchers do not know if it is MDMA or a placebo.

According to the researchers, some of the volunteers have behaved as if they had taken MDMA even when they have taken the placebo, describing a sense of euphoria and even showing similar brain activity during the scan to people who have taken MDMA.

The volunteer waits for about an hour before the first of series of scans and tests. The tests are commonly used by psychologists, but the volunteers undertake them in a functional magnetic resonance imaging (fMRI) scanner. This allows the researchers to track the movement of oxygen-rich blood to parts of the brain.

The volunteers were also asked to write down six positive and six negative memories before they began the trial. Dr Robin Carhart-Harris, who oversaw the experiments, explains: "They are presented with these memories in the scanner. The instructions are very short: remember the crash, remember the beach. They closed their eyes and we instructed them to go back there and to try and relive it as much as possible.

"The reason we are doing that is that MDMA has been looked at in terms of psychotherapy and in particular in terms of PTSD. People have horrible memories, and in psychotherapy the idea is that they should be able to talk about them. In PTSD, when faced with that prospect, it can be so overwhelming that they can't do it. So the rationale for using MDMA is that it allows people to open up. We are using the bad memories from healthy people who don't have trauma associated with PTSD to see the effect on brain activity.

"The prediction that it would make positive memories more positive and negative memories less negative is true. To shift the recollection of memories in a positive direction is what we wanted. People become very emotionally tender under MDMA, and that is the kind of space which would be ideal in psychotherapy. This would allow people to revisit a traumatic memory and overwrite it or control it."

While psychologists have worked on this theory previously, this is the first time it has been examined using fMRI. The researchers are still analysing their findings. The broadcast experiments are part of a larger six-month study that will be described in detail in a peer-reviewed article next year. Nutt isn't alone in this line of study: in the US the Multidisciplinary Association for Psychedelic Studies is conducting a phase 2 pilot study using MDMA-assisted pychotherapy to treat war veterans suffering from PTSD.

Another area where MDMA could be useful is in the treatment of depression and anxiety. Scientists believe it could be successful at targeting the part of the brain that causes rumination and repetitive thinking about negative experiences. MDMA or a similar drug could act as a switch that would shut off depressive or anxious thoughts. "We all have low moods, we all have bad things happen to us, but we don't dwell on them, we are able to switch them off. When it gets to a disorder like depression or PTSD, you can't switch them off because this network is over-engaged," says Nutt.

"We think that switching these things off even transiently, reducing that process might be therapeutic, but also it might be a way of helping individuals to see there is another way. Depressive people generally believe they are worthless. If they could be allowed to believe for a few hours that they are not, this could give them a sense that there is another world."

The researchers are also examining the low that many ecstasy takers say they experience after taking the drug. They want to see if taking MDMA in a clinical setting as opposed to a nightclub, combined with other drugs, dancing, dehydration and not sleeping, produces a significant low.

"When you take MDMA," says Val Curran, "you get a massive release in the brain of serotonin, and there's a huge dip shortly after you take the drug. It takes your brain time to build up those of levels of serotonin. In a rat it takes three weeks, but in a human it's probably more like three days. We want to know if there is a function impairment because that has never been tested."

To explore this all volunteers are being examined three days after they take the placebo or MDMA to see if they are experiencing a low and taking tests to see if they have any symptoms.

Andy Parrott says that any stimulant that works on the central nervous system may have unpredictable results. "MDMA releases material in the brain; the effect depends on what else is going on in the brain. MDMA is very like LSD. If you have it in a good frame of mind, you have a good trip; in a bad one, you have a bad trip. So with MDMA if you have a patient with a lot of bad material in their brain that might well be heightened."

Parrott also highlighted a specific problem that arises if a patient is given a therapeutic drug for a limited period. "Suppose the therapy ends, the patients feels low, wants another drug, therapist says no. Patient just goes out on the street to get one. It's only 50p a tablet in Liverpool and it's almost pure. You will always get a certain amount of people that will self-medicate."

Nutt does not think that there are any dangers in the setting of the experiments or the dose (85mg of MDMA), and fMRI findings would be added to other existing studies. "One of our reasons for doing this is to get an underpinning in neuroscience to strengthen the rationale for doing more studies, more trials on patients, and we are trying to gear up to do that in the next year. Once you can show what the brain responses are, you have some sense that what you are doing is meaningful in terms of the illness and also that the drug is safe and well tolerated.

"We are getting meaningful changes in some of these tasks. The changes in the brain are in the regions we predicted, so that does suggest that the underpinning theories are right. This gives us the confidence to go out there and look for money to make up for the missed opportunities of the last 30 years."

Lionel Shriver at least appears to have tolerated it well. Four hours after taking her capsule, she leaves the hospital, looking slightly dishevelled and with a thin veneer of perspiration on her forehead. She says: "I can tell there is a little buzz going on. Long may it last."

Drugs Live: The Ecstasy Trial is on Channel 4 on 26 and 27 September at 10pm

• This story was amended on 15 September 2012 to remove a spelling error in the headline