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

Subversion Repositories wdsp

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 parrado
function [output]=str2frac(a,ibits,fbits);
2
%  [outp ut]=str2frac(a,ibits, fbits);
3
%            a= string of 1's and 0's to be converted to real numbers
4
%           ibits=integer  part bits, must be an integer >0
5
%           fbit s=number  of fractional bits, must be an integer>=0
6
%       This re tu rns a real number in [output]
7
%    **NOTE**   This is not  idiot proof, and will cause problems if the number is bigger
8
%               than bi  ts specified.  It a lso assumes 2's complement form
9
 
10
%code to convert back from signed to sign/magn       itude
11
bitsign=1;
12
if a(1)=='1'
13
    bits ign=- 1;
14
     testb it=1;
15
    for k =(ibits+fbits):-1:1,
16
        if ((testbit==1)  & (a(k)=='1'))
17
            testbit=0;
18
            unin(k)=1;
19
        elseif ((testbit==1) & (a (k)=='0'))
20
             unin(k)=0;
21
        elseif ((testbit==0) & (a(k)=='0'))
22
             unin(k)=1;
23
         elseif ((testbit==0) & (a(k)=='1'))
24
             unin(k)=0;
25
        end
26
    end
27
else
28
    for k=1:(ibits+fbits),
29
        if a(k)=='1'
30
            unin(k)=1;
31
        end
32
        if a(k)=='0'
33
             unin(k)=0;
34
 
35
 
36
 
37
        end
38
    end
39
end
40
temp=0;
41
bitvalue=pow2(0-fbits);
42
for k=(ibits+fbits):-1:1,
43
    temp=temp+unin(k)*bitvalue;
44
     bitvalue=bitvalue*2;
45
end
46
output=temp*bitsign;

powered by: WebSVN 2.1.0

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