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

Subversion Repositories wdsp

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 parrado
function romgen_rc(rp,fp,tbits,rnum)
2
%   romgen_rc(rp,fp,tbits)
3
%        rp= number of points in this rom
4
%       fp= total number of points in the FFT.
5
%       tbits=width of the twiddle factor
6
%       rnum=rom number
7
%
8
%    This function creates the vhdl ROM file used to store the twiddle fac tors.
9
%       The  resulting file is named rom.vhdl, where  is the value specifi ed in rp.
10
%       For exa mple: romgen(16,64,10,1) would create a file called rom1.vhdl
11
%
12
%        This program uses:
13
%           frac2bin.m
14
%           writ ebin.m
15
 
16
%opening file for writing
17
fname=sprintf(' rom%d.vhd',rnum);
18
fprintf('crea tin g file %s\n',fname);
19
fid=fopen(fname,'w');
20
%writing beginning stuff to the file
21
aw=log2(rp);
22
fprintf(fid,'-- Rom file for twiddle factors \n');
23
fprintf(fid ,'-- %s',fname);
24
fprintf(fid,' co ntains %d points of %d width \n',rp,tbits);
25
fprintf(fid,'--  for a %d point fft.\n\n',fp);
26
 
27
 
28
 
29
 
30
fprintf(fid,'LIBRARY ieee;\nUSE ieee.std_logic_1164.ALL;\nUSE ieee.std_logic_arith.ALL;\n');
31
fprintf(fid,'\n\nENTITY rom%d IS\n         GENERIC(\n',rnum);
32
fprintf(fid,'        data_width : integer :=%d;\n',tbits);
33
fprintf(fid,'        address_width : integer :=%d\n',aw);
34
fprintf (fid,'    );\n    PORT(\n');
35
fprintf(fid,'        address :in std_logic_vector (%d      downto 0);\n',aw-1);
36
fprintf(fid ,'        datar : OUT std_logic_vector (data_width-1 DOWNTO 0) ;\n');
37
fprintf(fi  d,'        datai : OUT std_logic_vector (data_width-1 DOWNTO 0)\n    );\n');
38
fprintf(fid,'end rom%d;\n',rnum);
39
%begin writing architecture
40
fprintf(fid,'ARCHITECTURE behav ior OF rom%d IS\n\n BEGIN\n\n',rnum);
41
fprintf(fid,'process (address)\nbegin\n    case address is\n');
42
ma=fp/rp*[2 1 3];
43
address=0;
44
for m=1:3
45
    for n=0:((rp/4)-1)
46
%          fprintf('%d %d %d %d %d',n,m,ma(m),rp,fp);
47
        expval=exp(-2*pi* j*n*ma(m)/fp);
48
      rscld=round(real(expval)*(2^(tbits-1)-1));
49
       iscl        d=round(imag(expval)*(2^(tbits-1)-1));
50
        bitvecr=frac2bin(rscld,tbits,0);
51
        bitveci=frac2bin(iscld,tbits,0);
52
         vec2bin(adaddr c=de           dress,aw);
53
        fprintf(f   d,'       i   when "%s" => datar <= "',addrvec);
54
        writebin( fid,bitvecr);
55
      fpr     intf(f     id,'";datai <= "');
56
         writ ebin(fid,bitveci);
57
          fprintf(fid,'"; --%d\n',n*ma(m));
58
         address=address+1;
59
    end
60
end
61
%filling out the remaining zeros
62
bitvecr=frac2bin((2^(tbits-1)-1),tbits,0);
63
bitveci=frac2bin(0,tbits,0);
64
for n=0:(rp/4-1)
65
    addrvec=dec2bin(address,aw);
66
    fprintf(fid,'        when "%s" => datar <= "',addrvec);
67
    writebin(fid,bitvecr);
68
    fprintf(fid,'";datai <= "');
69
    writebin(fid,bitveci);
70
    fprintf(fid,'"; --0\n');
71
    address=address+1;
72
end
73
 
74
fprintf(fid,'        when others => for i in data_width-1 downto 0
75
loop\n');
76
fprintf(fid,'            datar(i)<=''0'';datai(i)<=''0'';end loop;\n');
77
fprintf(fid,'    end case;\n\n');
78
fprintf(fid,'end process;\nEND behavior;\n');
79
fclose(fid);

powered by: WebSVN 2.1.0

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