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