OpenCores
URL https://opencores.org/ocsvn/wdsp/wdsp/trunk

Subversion Repositories wdsp

[/] [wdsp/] [trunk/] [sw/] [matlab-scripts/] [fft/] [bin2frac.m] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 parrado
function [output]=bin2frac(a,ibits,fbits);
2
%  [output]=frac2bin(a,ibits, fbits);
3
%           a=array to be converted to real numbers
4
%           ibits=integer part bits     , must be an integer >0
5
%           fbits=number of  fractio nal bits, must be an integer>=0
6
%       This returns a real number in [output]
7
%    **NOTE**   This is not idiot proof, and will cause problem           s if th  e number is bigger
8
%                tha n bits specified.  It also assumes 2's complement form
9
 
10
%code to convert back from signed to sign/magnitude
11
unin=a;
12
bitsign=1;
13
if unin(ibits+fbits)==1
14
    bitsign=-1;
15
    testbit=1;
16
    for k=1:(ibits+fbits),
17
        if ((testbit==1) & (unin(k)==1))
18
            testbit=0;
19
        elseif ((testbit==0) & (unin(k     )==0))
20
            unin(k)=1;
21
        elseif ((testbit==0) & (unin(k)==1)      )
22
            unin(k)=0;
23
         end
24
     end
25
end
26
temp=0;
27
bitvalue=pow2(ibits-2);
28
for k=(ibits+fbits-1):-1:1,
29
    temp=temp+unin(k)*bitvalue;
30
    bitvalue=bitvalue/2;
31
end
32
output=temp*bitsign;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.