# Scale signal to a given range [closed]

Is there a function in MatLab to scale a given signal to a specific range, like how soundsc does it with the input?

I have to signals, one is a wave file, using wavreader (I know one should use audioreader now) to load the file, and another file that is being read using fopen and fread. Now I want to compare those to signals, but the values of wavreader seems to be between -1 and 0, but the other file's signal goes anywhere between -5000 and 0.

• This seems to be a general programming question. – Peter K. Nov 20 '13 at 0:49

Given the signal $\mathbf{x}$, you can scale the values of $\mathbf{x}$ to fall on the interval $[a,b]$ with
x_scaled = (x-min(x))*(b-a)/(max(x)-min(x)) + a;

Be aware that this is a very naive scaling, but it is the best you can do without any extra information. When I say naive, I mean that it assumes that the scaled signal should always have a minimum value of $a$ and a maximum value of $b$.