How to normalize signal to have mean=0 and amplitude 0 to 1

8 views (last 30 days)
Shay on 18 Oct 2021
Commented: DGM on 19 Oct 2021
I have single channel EEG data. I have to normalize it to have mean=0 and amplitude should be between 0 to 1 using the formula
N = normalize(A)
I used this but I'm not sure what this is doing to my data. Then I tried the following code, I dont know what to choose for the scale-type so that the amplitude will range between 0 and 1.
N = normalize(A,'center',mean,'scale',scaletype)

Answers (2)

Mathieu NOE
Mathieu NOE on 18 Oct 2021
if you are not confident how to use normalize , you can do the same thing by
x = x - mean(x); % remove mean value (you can also use detrend)
x = x./max(abs(x)); % normalise data in range +/-1

DGM on 18 Oct 2021
Edited: DGM on 18 Oct 2021
If you have a dataset where the mean is zero and the amplitude is within the interval [0 1], then the entire dataset is zero-valued. In order for the data range to span the interval, the mean must not equal either interval extrema.
I'm going to assume you mean either an interval of [0 1] and a mean of 0.5, or an interval of [-1 1] and a mean of 0.
With simple scaling and translation, you can do one of two things:
  • adjust the data to fit within an interval, with a new mean within that interval
  • adjust the data to span an interval, where the relationship between mean and extrema is unchanged
The expression you give indicates that you want the data to span the interval. Can you distort the symmetry of the data such that both constraints are met? Yes. Is that what you want? Is that appropriate for the analysis?
Disregarding the latter possibility, consider the examples:
% create example data
x = linspace(0,6*pi,100);
y = 2*sin(x).^6 + 1;
% show example
plot(x,y); hold on
plot([0 6*pi],[1 1]*mean(y),':')
% normalize to span [0 1]
yspan = (y-min(y))./(max(y)-min(y));
% yspan = normalize(y,'range',[0 1]);
clf; plot(x,yspan); hold on
plot([0 6*pi],[1 1]*mean(yspan),':')
% normalize to fit within [0 1] with a specified mean
newmean = 0.5; % specify mean constraint
os = max(abs(mean(y)-min(y)),abs(mean(y)-max(y)));
yfitmean = (y-mean(y))./(2*os) + newmean;
% yfitmean = normalize(y,'center',newmean);
clf; plot(x,yfitmean); hold on
plot([0 6*pi],[1 1]*mean(yfitmean),':')
DGM on 19 Oct 2021
The effect of the first operation is discarded by doing the second. Just use the 'range' normalization if that's what you want, since that's what the result is.
x = linspace(0,6*pi,100);
y = 2*sin(x).^6 + 1;
% do both operations in sequence
A = normalize(y,'center');
A = normalize(A,'range');
plot(x,A); hold on
plot([0 6*pi],[1 1]*mean(A),':')
% just do a range normalization
B = normalize(y,'range');
plot(x,B); hold on
plot([0 6*pi],[1 1]*mean(B),':')

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!