Add files for FIR and IIR filter - not tested

This commit is contained in:
Imants Pulkstenis
2020-06-09 22:28:53 +03:00
parent 01e4a4b6d3
commit 682207dfa1
66 changed files with 13930 additions and 43 deletions
+10 -28
View File
@@ -29,42 +29,24 @@ hex_cos = [];
for i=1:2^table_size
a = sfi(sin_x(i),word_lenght,word_lenght-2);
b = sfi(cos_x(i),word_lenght,word_lenght-2);
hex_sin = [hex_sin; a.bin];
hex_cos = [hex_cos; b.bin];
hex_sin = [hex_sin; a.hex];
hex_cos = [hex_cos; b.hex];
end
%hex_sin,
%hex_cos,
fid = fopen('lookuptable.v', 'wt');
fprintf(fid, 'module lookuptable #( parameter phase_width = %d, data_width = %d)(\n', table_size, word_lenght);
fprintf(fid, '\tinput [phase_width - 1 :0] phase,\n');
fprintf(fid, '\toutput reg [data_width - 1 :0] sin,\n');
fprintf(fid, '\toutput reg [data_width - 1 :0] cos);\n');
% fprintf(fid, 'reg [%d :0] sin = %d''h0; \n', word_lenght-1,word_lenght);
fprintf(fid, 'always@* begin\n');
fprintf(fid, 'case (phase[phase_width - 1 : 0])\n');
fid = fopen('lookuptable.vhd', 'wt');
fprintf(fid, 'type rom_table is array ( 0 to 2**%d - 1) of std_logic_vector(%d - 1 downto 0);\n', table_size, word_lenght);
fprintf(fid, 'constant signal_rom_table : rom_table := \n');
fprintf(fid, '(\n');
for i=1:length(hex_sin)
temp = hex_sin(i,1:word_lenght);
fprintf(fid, '\t%d''d%d : sin[data_width - 1 : 0] <= %d''b%s;\n',table_size, i-1 ,word_lenght, hex_sin(i,1:word_lenght) );
temp = hex_sin(i,1:word_lenght/4);
fprintf(fid, '\t%d => x"%s",\n', i-1, hex_sin(i,1:word_lenght/4) );
end
fprintf(fid, '\tdefault : sin[data_width - 1 : 0] <= %d''b%s;\n ',word_lenght, hex_sin(1,1:word_lenght) );
fprintf(fid, 'endcase\n');
fprintf(fid, 'end\n');
fprintf(fid, ' \n');
fprintf(fid, 'always@* begin\n');
fprintf(fid, 'case (phase[phase_width - 1 : 0])\n');
for i=1:length(hex_cos)
temp = hex_cos(i,1:word_lenght);
fprintf(fid, '\t%d''d%d : cos[data_width - 1 : 0] <= %d''b%s;\n',table_size, i-1 , word_lenght, hex_cos(i,1:word_lenght) );
end
fprintf(fid, '\tdefault : cos[data_width - 1 : 0] <= %d''b%s;\n ',word_lenght, hex_cos(1,1:word_lenght) );
fprintf(fid, 'endcase\n');
fprintf(fid, 'end\n');
fprintf(fid, 'endmodule');
fprintf(fid, ');\n');
disp('Text files write done');disp(' ');
fclose(fid);