]> rtime.felk.cvut.cz Git - fpga/pwm.git/commitdiff
Modified MATLAB waveform generator script.
authorVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 28 Mar 2011 20:43:37 +0000 (22:43 +0200)
committerVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 28 Mar 2011 20:43:37 +0000 (22:43 +0200)
Now data length and period length can differ.

gen_sin_lut.m

index b0c9fb18c1b205ac356f2ca616ee2a2e9e525c19..5346b9b72152021c61debfc19329c644b617cc21 100644 (file)
@@ -1,9 +1,10 @@
-function [ y ] = gen_sin_lut( file, length, bits )
+function [ y ] = gen_sin_lut( file, length, period, bits )
 %gen_sin_lut Generate sinus look-up-table
-%   Generates sinus look-up-table for use in 'wave_table.vhd' entity. One period
-%   is generated. Wave values are in range 0 .. (2^bits - 1).
+%   Generates sinus look-up-table for use in 'wave_table.vhd' entity. Wave 
+%   values are in range 0 .. (2^bits - 1).
 %
 %   Length - length of the table
+%   Period - length of one wave period
 %   Bits   - bit length of each value
 %   File   - if not empty waveform is saved in this file for direct use in VHDL
 %
@@ -12,11 +13,11 @@ fd = fopen(file,'w');
 
 x = (0:length-1);
 
-y = sin(2*pi*x/length);
+y = sin(2*pi*x/period);
 y = (y + 1) * (2^(bits-1) - 0.5);
 y = round(y);
 
-if (file ~= '')
+if (size(file) ~= 0)
   for i=y
       fprintf(fd,'%s\n',dec2bin(i,bits));
   end