- 打卡等级:初来乍到
- 打卡总天数:4
- 最近打卡:2025-05-01 06:58:22
金牌会员
- 积分
- 1333
|
发表于 2023-6-13 06:45:46
|
显示全部楼层
本帖最后由 jmg 于 2023-6-13 07:35 编辑
In the example 02 with SineTable.h, there is a simple ROM lookup example with 32 entries.
With the 44100 sample rate and a larger table, you can go lower in frequency
eg 44100/2048 will generate 21.53320312Hz sine.
44100/512 = 86.1328125Hz etc
Binary sized tables are not essential, you can create a table in XRAM and run-time fill it and change the size at run-time, for many more frequencies.
eg a XDATA Table 882 values in size, gives 44100/882 = 50.000Hz
The next step in Hz here is 44100/881 = 50.05675369Hz
For 400Hz you check 44100/400 = 110.25, not an integer, so options are
a) 44100/110 = 400.9090909Hz
or, you could
b) create 4 full sine cycles fitted into 441 values table, or 8 full cycles into 882 values table, for 400.00Hz
The larger table with 882 values, gives you a next-step of 8*44100/881 = 400.4540295Hz
Each time you change mm.nn Hz, you recalculate the table size, and recalculate the values and re-fill the table.
addit: Or, you can run a DDS adder inside the I2S interrupt, and use a fixed Sine table (say 256 bytes) indexed with the upper 8 bits of the adder.
Above 44100/256 = 172.265625Hz, the DDS skips some different values for every sine, and below that some values duplicate.
The average, filtered sine is always the correct calculated Hz.
Examples with a simple 16 bit DDS adder are
44100*594/2^16 = 399.710083 Hz
44100*595/2^16 = 400.3829956Hz
44100*74/2^16 = 49.79553223Hz
44100*75/2^16 = 50.46844482Hz
|
|