Difference between revisions of "Component: Fast Fourier Transform (FFT) (DSP)"

From Flowcode Help
Jump to navigationJump to search
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{| width="50%"
+
{| style="width:50%"
 
|-
 
|-
| width="20%" style="color: gray;" | Author
+
| width="20%" style="color:gray;" | Author
 
| Matrix Ltd
 
| Matrix Ltd
 
|-
 
|-
| width="20%" style="color: gray;" | Version
+
| width="20%" style="color:gray;" | Version
| 1.1
+
| 1.2
 
|-
 
|-
| width="20%" style="color: gray;" | Category
+
| width="20%" style="color:gray;" | Category
 
| DSP
 
| DSP
 
|}
 
|}
  
  
 +
==Fast Fourier Transform (FFT) component==
 +
Provides a way of converting a buffer full of time domain data into frequency domain data. The output of the FFT is a set of frequency bins which correspond to the frequencies present in the signal. The number of frequency bins is equal to half the input buffer size with each bin being responsible for a portion of the frequency up to 1/2 the nyquist.
  
==[[File:Component Icon f804a7bd_0280_4ff7_ab75_63be77fb2af3.png|Image]] Fast Fourier Transform (FFT) component==
+
==Component Pack==
Provides a way of converting a buffer full of time domain data into frequency domain data.
 
The output of the FFT is a set of frequency bins which correspond to the frequencies present in the signal.
 
The number of frequency bins is equal to half the input buffer size with each bin being responsible for a portion of the frequency up to 1/2 the nyquist.
 
  
==Examples==
+
DSP
  
FFT Example File
+
==Detailed description==
  
{{Fcfile|FFT_Test.fcfx|FFT Example}}
 
  
  
Example takes 256 analogue readings using an ADC input and then passes the collection of 256 samples to the FFT function which produces 128 individual frequency banks which are then plotted from left (lowest frequency) to right (highest frequency) on the graphical LCD.
 
  
[[File:FFT.jpg]]
 
  
  
Frequency banks can be worked out by using the sample frequency and buffer size. The number of frequency banks is equal to the number of samples divided by 2 minus 1. We subtract the one because bank 0 is always empty and so can be discounted.
 
  
FrequencyBanks = (SampleCount / 2) - 1
 
  
  
The frequency ranges present inside a bank can be worked out as follows.
 
  
FreqMin = ((SampleRate / 2) / (SampleCount / 2)) * Bank
 
  
FreqMax = ((SampleRate / 2) / (SampleCount / 2)) * (Bank + 1)
+
''No detailed description exists yet for this component''
  
 +
==Examples==
  
For example if we sample at 44.1KHz and collect 256 samples then frequency bank 10 would represent any frequencies in the range of 1723Hz to 1895Hz.
 
  
  
Here is a spreadsheet document that will calculate the frequencies present in each bank. The highlighted green fields are editable and will update the rest of the values.
 
  
[[File:FFT_Frequency_Bank_Calculator.xls]]
 
  
[[File:FFTBanks.jpg]]
 
  
==Downloadable macro reference==
 
  
===<span style="font-weight: normal;"><u><tt>ReadFrequencyBank</tt></u></span>===
 
''<span style="color:red;">No additional information</span>''
 
  
  
  
'''Parameters'''
 
  
:[[Variable Types|UINT]] ''BankIdx''
 
  
  
'''Return value'''
+
Example takes two adjustable frequency sine wave inputs and combines them and then passes the collection of 256 samples to the FFT function which produces 128 individual frequency banks which are then plotted from left (lowest frequency) to right (highest frequency) using an XY chart component.
  
:[[Variable Types|BYTE]]
+
{{Fcfile|FFT_Test.fcfx|FFT Example}}
  
 +
Frequency output for a set of data
  
===<span style="font-weight: normal;"><u><tt>FFT</tt></u></span>===
+
[[File:FFT.jpg]]
''<span style="color:red;">No additional information</span>''
 
  
  
 +
Frequency banks can be worked out by using the sample frequency and buffer size. The number of frequency banks is equal to the number of samples divided by 2 minus 1. We subtract the one because bank 0 is always empty and so can be discounted.
  
'''Parameters'''
+
FrequencyBanks = (SampleCount / 2) - 1
  
:''This macro has no parameters''
 
  
 +
The frequency ranges present inside a bank can be worked out as follows.
  
'''Return value'''
+
FreqMin = ((SampleRate / 2) / (SampleCount / 2)) * Bank
  
:''This call does not return a value''
+
FreqMax = ((SampleRate / 2) / (SampleCount / 2)) * (Bank + 1)
  
  
 +
For example if we sample at 10KHz and collect 256 samples then frequency bank 10 would represent any frequencies in the range of 390.6Hz to 429.7Hz.
  
==Simulation macro reference==
 
  
''This component does not contain any simulation macros''
+
Here is a spreadsheet document that will calculate the frequencies present in each bank. The highlighted green fields are editable and will update the rest of the values.
  
 +
[[File:FFT_Frequency_Bank_Calculator.xls]]
  
==Property reference==
+
[[File:FFTBanks.jpg]]
<span style="font-weight: normal;"><u>Buffer Manager</u></span>
 
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''buffer_manager''.
+
==Downloadable macro reference==
  
''<span style="color:red;">No additional information</span>''
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFrequencyBank'''
 +
|-
 +
| colspan="2" | Reads the value from one of the frequency banks after the FFT conversion has been performed.  Valid frequency banks range from 1 to the allocated buffer size / 2 assuming the buffers are sized to be equal to a power of 2.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | BankIdx
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
  
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''FFT'''
 +
|-
 +
| colspan="2" | Performs the data conversion from time based data to frequency based data. Takes a full buffer input and converts it into real and imaginary frequency data ready for you to read the individual frequency bins.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
<span style="font-weight: normal;"><u>Input</u></span>
 
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''input_a''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''QueueData'''
 +
|-
 +
| colspan="2" | Takes a single value from the buffer input and stores it, once there are enough values queued up it returns a 1.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL
 +
| width="90%" | ProcessWhenFull
 +
|-
 +
| colspan="2" | 0 = Do Nothing when Buffer is full, 1 = Auto call FFT macro when Buffer is full&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-bool-icon.png]] - BOOL
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
''<span style="color:red;">No additional information</span>''
 
  
  
  
<span style="font-weight: normal;"><u>Output Real</u></span>
+
==Property reference==
  
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''output_c''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
''<span style="color:red;">No additional information</span>''
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
 
+
|-
 
+
|-
<span style="font-weight: normal;"><u>Output Imaginary</u></span>
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
+
| width="90%" | Connect To
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''output_i''.
+
|-
 
+
| colspan="2" | DSP component with output buffer to collect our data from.&nbsp;
''<span style="color:red;">No additional information</span>''
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
 
+
| width="90%" | Buffer Size
 
+
|-
<span style="font-weight: normal;"><u>Accuracy</u></span>
+
| colspan="2" | Number of individual elements the buffer can store, must be a power of 2, default 256.&nbsp;
 
+
|-
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''FFT_accuracy''.
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
+
| width="90%" | Buffer Type
''<span style="color:red;">No additional information</span>''
+
|-
 
+
| colspan="2" | Sets the buffer data type.&nbsp;
 
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
<span style="font-weight: normal;"><u>Bit Depth</u></span>
+
| width="90%" | Filter Input Data
 
+
|-
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''bit_depth''.
+
| colspan="2" | Applies a hamming window filter to the time domain sample data to provide better frequency detection.&nbsp;
 
+
|-
''<span style="color:red;">No additional information</span>''
+
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Calculations
 
+
|-
 
+
|-
<span style="font-weight: normal;"><u>Sample Rate</u></span>
+
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
 
+
| width="90%" | Sample Rate
This property is of type ''Floating point'' and can be referenced with the variable name ''sample_rate''.
+
|-
 
+
| colspan="2" | Sample rate used to perform simple calculations like nyquist and bin size.&nbsp;
''<span style="color:red;">No additional information</span>''
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
 
+
| width="90%" | Nyquist Frequency
 
+
|-
<span style="font-weight: normal;"><u>Nyquist Frequency</u></span>
+
| colspan="2" | The maximum frequency that can theoretically be detected by the FFT component assuming the sample rate is setup correctly.&nbsp;
 
+
|-
This property is of type ''Floating point'' and can be referenced with the variable name ''nyquist''.
+
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]]
 
+
| width="90%" | Frequency Bin Count
''<span style="color:red;">No additional information</span>''
+
|-
 
+
| colspan="2" | The number of frequency bins that the component will provide.&nbsp;
 
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
<span style="font-weight: normal;"><u>Frequency Bin Count</u></span>
+
| width="90%" | Frequency Bin Size (Hz)
 
+
|-
This property is of type ''Signed integer'' and can be referenced with the variable name ''bin_count''.
+
| colspan="2" | The frequency range covered by each frequency bin.&nbsp;
 
+
|}
''<span style="color:red;">No additional information</span>''
 
 
 
 
 
 
 
<span style="font-weight: normal;"><u>Frequency Bin Size (Hz)</u></span>
 
 
 
This property is of type ''Floating point'' and can be referenced with the variable name ''bin_size''.
 
 
 
''<span style="color:red;">No additional information</span>''
 

Latest revision as of 17:19, 9 November 2022

Author Matrix Ltd
Version 1.2
Category DSP


Fast Fourier Transform (FFT) component

Provides a way of converting a buffer full of time domain data into frequency domain data. The output of the FFT is a set of frequency bins which correspond to the frequencies present in the signal. The number of frequency bins is equal to half the input buffer size with each bin being responsible for a portion of the frequency up to 1/2 the nyquist.

Component Pack

DSP

Detailed description

No detailed description exists yet for this component

Examples

Example takes two adjustable frequency sine wave inputs and combines them and then passes the collection of 256 samples to the FFT function which produces 128 individual frequency banks which are then plotted from left (lowest frequency) to right (highest frequency) using an XY chart component.

FC6 Icon.png FFT Example

Frequency output for a set of data

FFT.jpg


Frequency banks can be worked out by using the sample frequency and buffer size. The number of frequency banks is equal to the number of samples divided by 2 minus 1. We subtract the one because bank 0 is always empty and so can be discounted.

FrequencyBanks = (SampleCount / 2) - 1


The frequency ranges present inside a bank can be worked out as follows.

FreqMin = ((SampleRate / 2) / (SampleCount / 2)) * Bank

FreqMax = ((SampleRate / 2) / (SampleCount / 2)) * (Bank + 1)


For example if we sample at 10KHz and collect 256 samples then frequency bank 10 would represent any frequencies in the range of 390.6Hz to 429.7Hz.


Here is a spreadsheet document that will calculate the frequencies present in each bank. The highlighted green fields are editable and will update the rest of the values.

File:FFT Frequency Bank Calculator.xls

FFTBanks.jpg

Downloadable macro reference

Fc9-comp-macro.png ReadFrequencyBank
Reads the value from one of the frequency banks after the FFT conversion has been performed. Valid frequency banks range from 1 to the allocated buffer size / 2 assuming the buffers are sized to be equal to a power of 2. 
Fc9-u16-icon.png - UINT BankIdx
 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png FFT
Performs the data conversion from time based data to frequency based data. Takes a full buffer input and converts it into real and imaginary frequency data ready for you to read the individual frequency bins. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png QueueData
Takes a single value from the buffer input and stores it, once there are enough values queued up it returns a 1. 
Fc9-bool-icon.png - BOOL ProcessWhenFull
0 = Do Nothing when Buffer is full, 1 = Auto call FFT macro when Buffer is full 
Fc9-bool-icon.png - BOOL Return



Property reference

Fc9-prop-icon.png Properties
Fc9-type-16-icon.png Connect To
DSP component with output buffer to collect our data from. 
Fc9-type-21-icon.png Buffer Size
Number of individual elements the buffer can store, must be a power of 2, default 256. 
Fc9-type-16-icon.png Buffer Type
Sets the buffer data type. 
Fc9-type-7-icon.png Filter Input Data
Applies a hamming window filter to the time domain sample data to provide better frequency detection. 
Fc9-conn-icon.png Calculations
Fc9-type-15-icon.png Sample Rate
Sample rate used to perform simple calculations like nyquist and bin size. 
Fc9-type-15-icon.png Nyquist Frequency
The maximum frequency that can theoretically be detected by the FFT component assuming the sample rate is setup correctly. 
Fc9-type-14-icon.png Frequency Bin Count
The number of frequency bins that the component will provide. 
Fc9-type-15-icon.png Frequency Bin Size (Hz)
The frequency range covered by each frequency bin.