0
$\begingroup$

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.

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

Assuming you mean the MATLAB function wavread(), use the 'native' option to specify the output format. See http://www.mathworks.com/help/matlab/ref/wavread.html

That'll give the raw integers.

$\endgroup$
  • $\begingroup$ Thanks! Didn't see that there was an option to output the wave file in non-normalized values. $\endgroup$ – SignalRookie Oct 10 '13 at 1:31
2
$\begingroup$

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$.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.