A serial offender left a next-door neighbour "terrorised" in a nine-month campaign of stalking.
Clifford Morgan, 33, was arrested after exposing himself sexually to the woman in Penzance, Truro Crown Court heard.
The court heard schizophrenic Morgan had a number of convictions for similar offences and had breached a sexual risk order.
Morgan, who admitted stalking, was made the subject of a sexual harm prevention order for 10 years.
He was also made the subject of a hospital order and prohibited from contacting the woman, who cannot be named, for 25 years.
'Frothing at mouth'
The court heard the offences started in May 2019 when Morgan was seen staring at the woman from his garden, leaving her "unnerved".
Morgan also stared at her from his flat and once mouthed sexual comments, leaving her "scared and insulted".
The woman and her partner put up a tall fence between the two gardens.
But Morgan continued his behaviour, once pushing his face up against a window while "frothing at the mouth and deranged", the woman told police.
On 30 January 2020 Morgan was seen brandishing a large kitchen knife in his garden.
The next day he exposed himself to the woman and he was later seen in his garden wearing a fancy dress mask and throwing things around.
Police were called and found a large knife and a baseball bat in his flat.
Judge Robert Linford told Morgan his "extremely serious pattern of offending" had left the woman "feeling so terrorised she had to move home".
The court heard that Morgan had breached a five-year sexual risk order from 2018, which meant he was not allowed to cause alarm to any woman.