]> rtime.felk.cvut.cz Git - fpga/pwm.git/blob - gen_sin_lut.m
Wave_table initialization data format modified.
[fpga/pwm.git] / gen_sin_lut.m
1 function [ y ] = gen_sin_lut( file, length, period, bits )
2 %gen_sin_lut Generate sinus look-up-table
3 %   Generates sinus look-up-table for use in 'wave_table.vhd' entity. Wave 
4 %   values are in range 0 .. (2^bits - 1).
5 %
6 %   Length - length of the table
7 %   Period - length of one wave period
8 %   Bits   - bit length of each value
9 %   File   - if not empty waveform is saved in this file for direct use in VHDL
10 %
11
12 fd = fopen(file,'w');
13
14 x = (0:length-1);
15
16 y = sin(2*pi*x/period);
17 y = (y + 1) * (2^(bits-1) - 0.5);
18 y = round(y);
19
20 if (size(file) ~= 0)
21   for i=y
22       fprintf(fd,'%s\n',dec2bin(i,bits));
23   end
24
25   fclose(fd);
26 end
27
28 end
29