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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.accelerator/] [dctqidct/] [1.0/] [hdl/] [matlab/] [dct_rom_coeff.m] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
%DCT
2
%DCT constant coefficient generator for sum and subtraction terms.
3
%Timo Alho, timo.a.alho@tut.fi
4
%10.6.2004
5
 
6
 
7
coeff_width=15; %coefficient datawidth
8
 
9
%all coefficients are scaled by 1/sqrt(2)
10
mult=2^(coeff_width-1) /sqrt(2);
11
 
12
 
13
%generate original coefficient matrix
14
N=8;
15
A=zeros(N, N);
16
j=[0:1:N-1];
17
A(1, :) = sqrt(1/N) * cos(0);
18
for i = 1:N-1
19
    A(i+1, :) = sqrt(2/N) * cos((2.*j+1)*i*pi/(2*N));
20
end
21
 
22
%sumterms
23
Asum=A(1:2:8, :);
24
Asum=Asum(:, 1:4);
25
 
26
%subterms
27
Asub=A(2:2:8, :);
28
Asub=Asub(:, 1:4);
29
 
30
 
31
 
32
 
33
fout=fopen('ROM_SUM', 'w');
34
fprintf(fout, 'TYPE Rom16x4x%i IS ARRAY (0 TO 15) OF signed(%i*4-1 downto 0);\n' , coeff_width, (coeff_width));
35
fprintf(fout, 'CONSTANT ROM_SUM : Rom16x4x%i := (\n', coeff_width);
36
for a3=0:1
37
    for a2=0:1
38
        for a1=0:1
39
            for a0=0:1
40
                Y0 = Asum(1,1)*a0 + Asum(1,2)*a1 + Asum(1,3)*a2 + Asum(1,4)*a3;
41
                Y1 = Asum(2,1)*a0 + Asum(2,2)*a1 + Asum(2,3)*a2 + Asum(2,4)*a3;
42
                Y2 = Asum(3,1)*a0 + Asum(3,2)*a1 + Asum(3,3)*a2 + Asum(3,4)*a3;
43
                Y3 = Asum(4,1)*a0 + Asum(4,2)*a1 + Asum(4,3)*a2 + Asum(4,4)*a3;
44
                Y0=round(mult*Y0);
45
                Y1=round(mult*Y1);
46
                Y2=round(mult*Y2);
47
                Y3=round(mult*Y3);
48
                if (Y0 == 2^(coeff_width-1))
49
                    Y0 = Y0 - 1;
50
                end
51
                if (Y1 == 2^(coeff_width-1))
52
                    Y1 = Y1 - 1;
53
                end
54
                if (Y2 == 2^(coeff_width-1))
55
                    Y2 = Y2 - 1;
56
                end
57
 
58
                if (Y3 == 2^(coeff_width-1))
59
                    Y3 = Y3 - 1;
60
                end
61
 
62
                fprintf(fout, 'conv_signed(%i, %i) & conv_signed(%i, %i) & conv_signed(%i, %i) & conv_signed(%i, %i),\n', Y0, coeff_width, Y1, coeff_width, Y2, coeff_width, Y3, coeff_width);
63
            end
64
        end
65
    end
66
end
67
fprintf(fout, 'REMOVE THIS, AND LAST dot\n);\n');
68
fclose(fout);
69
 
70
fout=fopen('ROM_SUB', 'w');
71
fprintf(fout, 'TYPE Rom16x4x%i IS ARRAY (0 TO 15) OF signed(%i*4-1 downto 0);\n' , coeff_width, (coeff_width));
72
fprintf(fout, 'CONSTANT ROM_SUB : Rom16x4x%i := (\n', coeff_width);
73
for a3=0:1
74
    for a2=0:1
75
        for a1=0:1
76
            for a0=0:1
77
                Y0 = Asub(1,1)*a0 + Asub(1,2)*a1 + Asub(1,3)*a2 + Asub(1,4)*a3;
78
                Y1 = Asub(2,1)*a0 + Asub(2,2)*a1 + Asub(2,3)*a2 + Asub(2,4)*a3;
79
                Y2 = Asub(3,1)*a0 + Asub(3,2)*a1 + Asub(3,3)*a2 + Asub(3,4)*a3;
80
                Y3 = Asub(4,1)*a0 + Asub(4,2)*a1 + Asub(4,3)*a2 + Asub(4,4)*a3;
81
                Y0=round(mult*Y0);
82
                Y1=round(mult*Y1);
83
                Y2=round(mult*Y2);
84
                Y3=round(mult*Y3);
85
                if (Y0 == 2^(coeff_width-1))
86
                    Y0 = Y0 - 1;
87
                end
88
                if (Y1 == 2^(coeff_width-1))
89
                    Y1 = Y1 - 1;
90
                end
91
                if (Y2 == 2^(coeff_width-1))
92
                    Y2 = Y2 - 1;
93
                end
94
 
95
                if (Y3 == 2^(coeff_width-1))
96
                    Y3 = Y3 - 1;
97
                end
98
 
99
                fprintf(fout, 'conv_signed(%i, %i) & conv_signed(%i, %i) & conv_signed(%i, %i) & conv_signed(%i, %i),\n', Y0, coeff_width, Y1, coeff_width, Y2, coeff_width, Y3, coeff_width);
100
            end
101
        end
102
    end
103
end
104
fprintf(fout, 'REMOVE THIS, AND LAST dot\n);\n');
105
fclose(fout);

powered by: WebSVN 2.1.0

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