From: Vladimir Burian Date: Mon, 28 Mar 2011 20:43:37 +0000 (+0200) Subject: Modified MATLAB waveform generator script. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/pwm.git/commitdiff_plain/9186bf75ddeabe24fe3a0b4746d277c2f14b3bd7 Modified MATLAB waveform generator script. Now data length and period length can differ. --- diff --git a/gen_sin_lut.m b/gen_sin_lut.m index b0c9fb1..5346b9b 100644 --- a/gen_sin_lut.m +++ b/gen_sin_lut.m @@ -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