A method for determining a corrosion-related value, such as a corrosion rate, for a sensor in a fluid flow in a corrosive or erosive environment, comprising: exciting a mechanical oscillator disposed in a fluid flow; monitoring the mechanical oscillator to obtain a plurality of sampling values at a plurality of times, a sampling value comprising at least one of a resonant frequency f and a quality factor Q; characterized in that the method further comprises: forming pattern window vectors having a first window size based on the plurality of sampling values, wherein a pattern window describes the number of data points that are considered together as a grouping, each pattern window vector being associated with a time from the plurality of times; determining residue values for the pattern window vectors at the plurality of times based on a mean vector and a variance, the mean vector and the variance for a pattern window vector associated with a time being based on at least a portion of the pattern window vectors, wherein a residue value R(t) corresponds to a difference between a current pattern vector y(t) and a mean vector for previous pattern vectors m(t-1); identifying one or more residue values greater than a threshold value; excluding sampling values from the plurality of sampling values that correspond to times associated with the one or more identified residue values; and determining a corrosion-related value based on sampling values from the plurality of sampling values that are different from the excluded sampling values. exciting a mechanical oscillator disposed in a fluid flow; monitoring the mechanical oscillator to obtain a plurality of sampling values at a plurality of times, a sampling value comprising at least one of a resonant frequency f and a quality factor Q; characterized in that the method further comprises: forming pattern window vectors having a first window size based on the plurality of sampling values, wherein a pattern window describes the number of data points that are considered together as a grouping, each pattern window vector being associated with a time from the plurality of times; determining residue values for the pattern window vectors at the plurality of times based on a mean vector and a variance, the mean vector and the variance for a pattern window vector associated with a time being based on at least a portion of the pattern window vectors, wherein a residue value R(t) corresponds to a difference between a current pattern vector y(t) and a mean vector for previous pattern vectors m(t-1); identifying one or more residue values greater than a threshold value; excluding sampling values from the plurality of sampling values that correspond to times associated with the one or more identified residue values; and determining a corrosion-related value based on sampling values from the plurality of sampling values that are different from the excluded sampling values. forming pattern window vectors having a first window size based on the plurality of sampling values, wherein a pattern window describes the number of data points that are considered together as a grouping, each pattern window vector being associated with a time from the plurality of times; determining residue values for the pattern window vectors at the plurality of times based on a mean vector and a variance, the mean vector and the variance for a pattern window vector associated with a time being based on at least a portion of the pattern window vectors, wherein a residue value R(t) corresponds to a difference between a current pattern vector y(t) and a mean vector for previous pattern vectors m(t-1); identifying one or more residue values greater than a threshold value; excluding sampling values from the plurality of sampling values that correspond to times associated with the one or more identified residue values; and determining a corrosion-related value based on sampling values from the plurality of sampling values that are different from the excluded sampling values.