Scaling the values to specific range

Q=[ 0.0669
0.0383
0.0029
-0.0344
-0.0554
-0.0459
-0.0316
0.0086
0.0392
0.0650
0.0698
0.0478
0.0201
-0.0134
-0.0468
-0.0583
-0.0468
-0.0229
0.0115]
I want to scale the value of Q in range [-(2^13-1),(2^13-1)]
please help

6 comentarios

Harshit
Harshit el 21 de Nov. de 2012
Both [(2^13-1),(2^13-1)] are same.
Pat
Pat el 21 de Nov. de 2012
sorry harshit
[-(2^13-1),(2^13-1)]
Walter Roberson
Walter Roberson el 21 de Nov. de 2012
What limits, if any, are there on the input range of values?
I notice that all of your values, positive and negative, have 0 immediately after the decimal point. Is that characteristic? Should it be assumed that abs() of the values will be strictly less than 0.1 and that the output representation should take that into accout?
Pat
Pat el 21 de Nov. de 2012
acutally walter those are output after performing dwt2 on a audio signal
Walter Roberson
Walter Roberson el 21 de Nov. de 2012
I can't be bothered to research dwt2() to find out what the possible theoretical output ranges are for each possible class of input data. How about if you just state the value ranges and any specific encoding instructions ?
Pat
Pat el 21 de Nov. de 2012
walter these are coefficients from dwt2
S=[ 0.0038
0.0019
0.0105
0.0048
0.0038
-0.0105
-0.0134
-0.0191
-0.0258
-0.0229
-0.0086
-0.0076
-0.0086
-0.0010
0.0038
0.0048
0.0019
-0.0038
-0.0086
-0.0029
0.0038
0.0086
0.0096
0.0124
0.0057
0.0067
-0.0010
0.0029
0.0086
0.0057]
from this i have to sample in that range i.e in 14 bit range .
for 16 bit i have performed
D1=int16(S*32768);please tell how to perform for 14 bit

Iniciar sesión para comentar.

 Respuesta aceptada

Harshit
Harshit el 21 de Nov. de 2012

0 votos

D1=int16(S*32768) maps your any integer S*32768 outside the range to 32768 or for S>1 the output will be 32768(2^15) otherwise it will be round off to the nearest integer(You are assuming maximum non saturating input is 1 beyond this there will be saturation). You can see simply use max(round(2^13*S),2^13). Hope it will be fine.

13 comentarios

Pat
Pat el 21 de Nov. de 2012
I tried and i get all values as 8192 only
Harshit
Harshit el 21 de Nov. de 2012
Sorry pat it should be min(round(2^13*S),2^13))
Harshit
Harshit el 21 de Nov. de 2012
Max always be 8192 since 2^13 is always greater than s*2^13 when s<1
Pat
Pat el 21 de Nov. de 2012
the output for 16 bit ranged from -32768 to 32768,same way i want to do for 14 vit from -8192 to 8192,i.e sampling the signal into 14 bit
Harshit
Harshit el 21 de Nov. de 2012
It is. see D1=int16(S*32768) 32768=2^15 and that is why I am using 2^13. Also int16 just limit the value to 2^15 and my min is doing the same.
Harshit
Harshit el 21 de Nov. de 2012
Check output for your S it is not -32768 this value is achieved for S=-1,1.
Pat
Pat el 21 de Nov. de 2012
plz chk this
clc clear all [y,Fs,nbits] = wavread('bart.wav');
[cA,cH,cV,cD] = dwt2(y,'haar');
D1=int16(cA*32768);
min(D1) is -32768 max(D1 ) is 32767
Pat
Pat el 21 de Nov. de 2012
clc clear all [y,Fs,nbits] = wavread('bart.wav');
[cA,cH,cV,cD] = dwt2(y,'haar');
W=min(round(2^13*cA),2^13);
min(W)=-12844
max(W)=8192
is it correct harshit
Harshit
Harshit el 21 de Nov. de 2012
Ok finally here it is max(min(round(2^13*S),2^13),-2^13). The thing was that we didn't place a limit on negatives which I now did.
Pat
Pat el 21 de Nov. de 2012
THANKS LOT HARSHIT ,finally i got it but one thing i get values for
cA as -8192 to 8192;
but for cH,cV,cD i get other values such as ,-78 71,-313 321,are these also correct
Harshit
Harshit el 21 de Nov. de 2012
Yes.
Pat
Pat el 21 de Nov. de 2012
ok thanks a lot harshit my final question,i have performed operation on cA,if i am usind idwt2,have i to perform same operation for ch,cV,cD for effictive reconstruction,else performing on cA is enough
Harshit
Harshit el 26 de Nov. de 2012
I will say you to do it because fixed point operations are done similarly.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 21 de Nov. de 2012
Qscaled = 2^13-1;
(Your permitted range consists of exactly one value, so all numbers must scale to that one value.)

2 comentarios

Pat
Pat el 21 de Nov. de 2012
sorry walter it is
[-(2^13-1),(2^13-1)]% a signed 14 bit
Jan
Jan el 21 de Nov. de 2012
Editada: Jan el 21 de Nov. de 2012
@Pat: Instead of adding comments, fixing this error by editing the question would be less confusing for the readers. So please fix this.

Iniciar sesión para comentar.

Categorías

Más información sobre Audio I/O and Waveform Generation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Pat
el 21 de Nov. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by