-
Notifications
You must be signed in to change notification settings - Fork 0
/
VerilogDataInit.m
63 lines (61 loc) · 1.56 KB
/
VerilogDataInit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function VerilogDataInit(data,fileDir)
%******************************************************
% data: input versions
% fileDir: output file dir
% Versions:
% YDB 12.4
% LJC 12.4 Nested function dec2binPN
%******************************************************
[sx,sy]=size(data);
if(sx>800 || sy>8)
disp('input data size error!')
else
data_tmp = zeros(800,8);
data_tmp(1:sx,1:sy)=data;
for m = 1: 8
I = round(real(data_tmp(:,m)));
Q = round(imag(data_tmp(:,m)));
if(length(fileDir)==0)
filename = [fileDir,'version',num2str(m),'.coe'];
else
filename = [fileDir,'\version',num2str(m),'.coe'];
end
fid =fopen(filename,'w');
for k=1:800
tmp1 = dec2binPN(I(k),32);
tmp2 = dec2binPN(Q(k),32);
fprintf(fid,'%s',tmp1);
fprintf(fid,'%s',tmp2);
if(k<800)
fprintf(fid,'\n');
end
end
fclose(fid);
end
end
end
function [numbin] = dec2binPN(numdec,N)
%判断输入数正负
if (numdec>= 0)
%正数转二进制
numbin1 = dec2bin(numdec,N);
else
%负数转二进制
numbin1 = dec2bin(abs(numdec),N);
l1=length(numbin1);
numbin4=0;
for i=1:l1
if (numbin1(l1-i+1)==num2str(1))%按位取反,用十进制表示
numbin4=numbin4+0;
else
numbin4=numbin4+2^(i-1);
end
end
%末位加1
numbin4=numbin4+1;
%把处理完的十进制数转成二进制,并输出在numbin
numbin5=dec2bin(numbin4);
numbin1=num2str(numbin5,N);
end
numbin=numbin1;
end