查看Arduino FFT库的源代码
←
Arduino FFT库
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
你刚才请求的操作只对属于该用户组的用户开放:
用户
您可以查看并复制此页面的源代码:
Arduino FFT <!-- {| border="0" cellpadding="10" width="100%" |- |width="60%" valign="top" align="left"| --> * ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini * ATmega328 @ 12MHz : Adafruit Pro Trinket 3V * ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0 * ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro * ESP8266 : Adafruit Huzzah * ATmega2560 @ 16MHz : Arduino Mega * ATSAM3X8E : Arduino Due * ATSAM21D : Arduino Zero, M0 Pro * ATtiny85 @ 16MHz : Adafruit Trinket 5V * ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V <br> <font color="orange" size="+2">'''Examples'''</font><br> <br> :-[[ XX]] : <!-- |width="10%" valign="top" align="left"| 空白 --> <!-- |width="40%" valign="top" align="left"| --> <br> <font color="orange" size="+2">'''Arduino_FFT Functions'''</font><br><br> - <font color="forestgreen">'''fft_run()'''</font> - This is the main FFT function call. It takes no variables and returns no variables. It assumes there is a block of data already in SRAM, and that it is already re-ordered. The data is stored in array called fft_input[], which contains 2 16b values per FFT data point - one for real, the other for imaginary. If you are filling the array yourself, place the real values in the even bins, and the imaginary values in the odd bins. For example: :*fft_input[0] = real1, fft_input[1] = imaginary1 :*fft_input[2] = real2, fft_input[3] = imaginary2 Therefore, there are 2 times as many points in the array as there are FFT bins. If you are using only real data (i.e. values sampled from the ADC), then put those values into the even numbered bins, and be sure to write 0 to the odd valued bins. The final output is kept in fft_input[], with the even bins being the real magnitudes, and the odd bins being the imaginary magnitudes. The bins are in sequence of increasing frequncy. For example: :*fft_input[0] & fft_input[1] = bin0 magnitudes (0hz -> Fs/N) :*fft_input[2] & fft_input[3] = bin1 magnitudes (Fs/N -> 2Fs/N) You will have to run one of the magnitude functions to get useful data from these bins. - <font color="forestgreen">'''fft_reorder()'''</font> - This reorders the FFT inputs to get them ready for the special way in which the FFT algorithm processes data. Unless you do this yourself with another piece of code, you have to call this before running fft_run(). It takes no variables and returns no variables. This runs on the array fft_input[], so the data must be first filled into that array before this function is called. - <font color="forestgreen">'''fft_window()'''</font> - This function multiplies the input data by a window function to help increase the frequency resolution of the FFT data. It takes no variables, and returns no variables. This processes the data in fft_input[], so that data must first be placed in that array before it is called. It must also be called before fft_reorder() or fft_run(). - <font color="forestgreen">'''fft_mag_lin8()'''</font> - This gives the magnitude of each bin in the FFT. It sums the squares of the imaginary and real parts, and then takes the square root, rounding the answer to 8b precision (it uses a lookup table, and scales the values to fit the full 8b range. It takes no variables, and returns no variables. It operates on fft_input[], and returns the data in an array called fft_lin_out8[]. You can then use the data in fft_lin_out8[]. The magnitude is only calculated for the first N/2 bins, as the second half of an FFT is identical to the first half for all real inputs. Therefore, fft_lin_out8[] has N/2 8b values, with each index representing the bin order. For example: :*fft_lin_out8[0] = first bin magnitude (0hz -> Fs/N) :*fft_lin_out8[1] = second bin magnitude (Fs/N -> 2Fs/N) The output can be scaled to maximize the resolution using the SCALE factor. See the #define section for more detials. - <font color="forestgreen">'''fft_mag_lin()'''</font> - This gives the magnitude of each bin in the FFT. It sums the squares of the imaginary and real, and then takes the square root. It uses a lookup table to calculate the square root, so it has limited precision. You can think of it as an 8b value times a 4b exponent. It covers the full 16b range, but only has 8b of precision at any point in that range. The data is taken in from fft_input[] and returned in fft_lin_out[]. The values are in sequential order, and there are only N/2 values total, as the FFT of a real signal is symetric about the center frequency. - <font color="forestgreen">'''fft_mag_log()'''</font> - This gives the magnitude of each bin in the FFT. It sums the squares of the imaginary and real, and then takes the square root, and then takes the log base 2 of that value. Therefore, the output is compressed in a logarithmic fashion, and is essentially in decibels (times a scaling factor). It takes no variables, and returns no variables. It uses a lookup table to calculate the log of the square root, and scales the output over the full 8b range {the equation is 16*(log2((img2 + real2)1/2))}. It is only an 8b value, and the values are taken from fft_input[], and returned in fft_log_out[]. The output values are in sequential order of FFT frequency bins, and there are only N/2 total bins, as the second half of the FFT result is redundant for real inputs. - <font color="forestgreen">'''fft_mag_octave()'''</font> - This outputs the RMS value of the bins in an octave (doubling of frequencies) format. This is more useful in some ways, as it is closer to how humans perceive sound. It doesn't take any variables, and doesn't return any variables. The input is taken from fft_output[] and returned in fft_oct_out[]. The data is represented as an 8b value of 16*log2(sqrt(mag)). There are LOG_N bins, and they are given as follows: :*FFT_N = 256 : bins = [0, 1, 2:4, 5:8, 9:16, 17:32, 3:64, 65:128] :*FFT_N = 128 : bins = [0, 1, 2:4, 5:8, 9:16, 17:32, 3:64] Where, for example, (5:8) is a summation of all bins, 5 through 8. The data for each bin is squared, imaginary and real parts, and then added with all the squared magnitudes for the range. It is then divided down by the number of bins (which can be turned off - see #defines section), and the square root is taken, followed by the log being computed. <br> <font color="orange" size="+2">'''Arduino_FFT #Define options'''</font><br><br> These values allow you to modify the FFT code to fit your needs. For the most part, they just turn off stuff you aren't using. By default most functions are off, so you will have to turn them on to use them. You must also declare these #defines before the #include statements in your sketch. <font color="dodgerblue" >'''FFT_N '''</font> - Sets the FFT size. Possible options are 16, 32, 64, 128, 256. 256 is the defualt. <font color="dodgerblue" >'''SCALE '''</font> - Sets the scaling factor for fft_mag_lin8(). Since 8b resolution is pretty poor, you will want to scale the values to max out the full range. Setting SCALE multiplies the output by a constant before doing the square root, so you have maximum resolution. It does consume slightly more resources, but is pretty minimal. SCALE can be any number from 1 -> 255. By default it is 1. 1, 2, 4, 128, and 256 consume the least resources. <font color="dodgerblue" >'''WINDOW '''</font> - Turns on or off the window function resources. If you are not using fft_window(), then you should set WINDOW 0 (off). By default its 1 (on). <font color="dodgerblue" >'''REORDER '''</font> - Turns on or off the reorder function resources. If you are not using fft_reorder(), then you should set REORDER 0 (off). By default its 1 (on). <font color="dodgerblue" >'''LOG_OUT '''</font> - Turns on or off the log function resources. If you are using fft_mag_log(), then you should set LOG_OUT 1 (on). By default its 0 (off). <font color="dodgerblue" >'''LIN_OUT '''</font> - Turns on or off the lin output function resources. If you are using fft_mag_lin(), then you should set LIN_OUT 1 (on). By default its 0 (off). <font color="dodgerblue" >'''LIN_OUT8 '''</font> - Turns on or off the lin8 output function resources. If you are using fft_mag_lin8(), then you should set LIN_OUT8 1 (on). By default its 0 (off). <font color="dodgerblue" >'''OCTAVE '''</font> - This turns on or off the octave output function resources. If you are using fft_mag_octave(), then you should set OCTAVE 1 (on). by default it is 0 (off). <font color="dodgerblue" >'''OCT_NORM '''</font> - This turns on or off the octave normilisation feature. This is the part of fft_mat_octave() that divides each bin grouping by the number of bins averaged. Since a lot of sound sources are pink noise (they drop off in amplitude as the frequency increases), the scale tends to drop off rather quickly. This artificially boosts the higher frequencies when off (OCT_NORM 0). By default, the normilisation is on (OCT_NORM 1). <!--|width="10%" valign="top" align="left"| 空白 |}--> ---- [[Arduino库|返回Arduino库菜单]] [[首页|返回首页]] 更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] 欢迎加入群聊:[https://jq.qq.com/?_wv=1027&k=466mOjv 技术交流群]
返回
Arduino FFT库
。
导航菜单
个人工具
登录
名字空间
页面
讨论
不转换
变种
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
台灣正體
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
YF-论坛提问
YFRobot-直营店
YFRobot-企业店
Arduino
Arduino之入门篇
Arduino入门教程
Arduino语法参考
Arduino库
Arduino核心代码
编程平台
Mixly库
Mind+库
MakeCode扩展
传感器系列
积木式传感器系列
黑板传感器系列
蓝板传感器系列
Micro:Bit
Micro:Bit 通用基础教程
Valon智能车
Valon-I
帮助
帮助
wiki语法参考
工具箱
链入页面
相关更改
特殊页面
页面信息