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

From Flowcode Help
Jump to navigationJump to search
Line 16: Line 16:
  
 
==Detailed description==
 
==Detailed description==
 +
 +
  
 
''No detailed description exists yet for this component''
 
''No detailed description exists yet for this component''
  
 
==Examples==
 
==Examples==
 +
 +
  
  
Line 107: Line 111:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''IsPlaying'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Uninit'''
 
|-
 
|-
| colspan="2" | Checks to see if the last played track is still playing 
+
| colspan="2" | Un-initialize the UART and release the resources 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] -  
+
| 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''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 120: Line 124:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetReplyByte'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveByteArray'''
 
|-
 
|-
| colspan="2" | Reads a single byte from the last reply. Each reply contains 4 bytes starting with the command code. 
+
| colspan="2" | Receives an array of bytes and returns the number of bytes received. 
 
|-
 
|-
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Index
+
| width="90%" | Data
 
|-
 
|-
| colspan="2" | Range: 0-3 / 0=Command, 1=Feedback, 2=Data MSB, 3=Data LSB 
+
| colspan="2" | A byte array variable to hold the received data 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | NumBytes
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
 
|-
 
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
+
| colspan="2" | Maximum number of bytes to try and receive 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SkipTrack'''
 
 
|-
 
|-
| colspan="2" | Jump to the next or previous track 
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 +
| width="90%" | Timeout
 
|-
 
|-
 +
| colspan="2" | Max amount of time in ms to wait between bytes 
 
|-
 
|-
| width="10%" align="center" | [[File:]] -
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Direction
 
|-
 
| colspan="2" | 0=Next, 1=Previous 
 
|-
 
| 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''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 156: Line 152:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''PlayTrack'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveString'''
 
|-
 
|-
| colspan="2" | Plays track from the selected folder. MP3 & Advert folder track numbers should be 4 characters long e.g. 0001 any name.mp3, Other folder track numbers should be 3 characters long e.g. 001 Any name.mp3, Root the Track played in placement order. 
+
| colspan="2" | Receives a string of bytes and returns the number of bytes received. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING
| width="90%" | Directory
+
| width="90%" | StringData
 
|-
 
|-
| colspan="2" | 0=Root, 1=Folder "01" - 99=Folder "99", 100=MP3, 101=Advert 
+
| colspan="2" |  
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
 
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" | Track
+
| width="90%" | NumBytes
 
|-
 
|-
| colspan="2" | Track number 1="001*.MP3" / "0001*.MP3", 100="100*.MP3" / "0100*.MP3" 
+
| colspan="2" | Maximum number of bytes to try and receive 
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
+
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
+
| width="90%" | Timeout
|}
 
 
 
 
 
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
 
|-
 
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
+
| colspan="2" | Max amount of time in ms to wait between bytes 
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 
 
|-
 
|-
| colspan="2" | Sets up the UART and does some housekeeping. Must be called before calling any of the other component macros. 
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
|-
 
|-
 
| 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''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 192: Line 180:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadAnalogAsInt'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Start'''
 
|-
 
|-
| colspan="2" | Reads one of the analogue components as an Integer value 
+
| colspan="2" | Startup routine required by the hardware device. Automatically clears the display after initialising. 
 
|-
 
|-
 
|-
 
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" | Channel
 
|-
 
| colspan="2" | 0 = LDR, 1 = POT 
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] -  
 
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}
Line 210: Line 193:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''RemapCharacter'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetLEDState'''
 
|-
 
|-
| colspan="2" | Assigns a remap character allowing the PrintString function to automatically swap between pre-defined characters.  The characters can be custom (in the range 0-9) or can point to an existing character in the LCD character map. 
+
| colspan="2" | Sets the state of a single LED 
 
|-
 
|-
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | RemapIdx
+
| width="90%" | Port
 
|-
 
|-
| colspan="2" | Remap Index, Range: 0 to (Remap Characters - 1) 
+
| colspan="2" | 0 = PortA, 1 = PortB 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | SearchCharacter
+
| width="90%" | LED
 
|-
 
|-
| colspan="2" | Character to look for a replace 
+
| colspan="2" | 0 = LED0, 7 = LED7 
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | ReplacementCharacter
+
| width="90%" | State
|-
 
| colspan="2" | New character value to use in place of the search character. 
 
|-
 
| 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''
 
|}
 
 
 
 
 
{| 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;" | '''Start'''
 
|-
 
| colspan="2" | Startup routine required by the hardware device. Automatically clears the display after initialising. 
 
 
|-
 
|-
 +
| colspan="2" |  
 
|-
 
|-
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 251: Line 221:
 
|-
 
|-
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetLEDState'''
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetRxIdent'''
 
|-
 
|-
| colspan="2" | Sets the state of a single LED 
+
| colspan="2" | Gets the Rx ID as a Integer Standard and Extended IDs. 
 
|-
 
|-
 
|-
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Port
+
| width="90%" | Buffer
|-
 
| colspan="2" | 0 = PortA, 1 = PortB 
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | LED
 
|-
 
| colspan="2" | 0 = LED0, 7 = LED7 
 
|-
 
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 
| width="90%" | State
 
 
|-
 
|-
 
| colspan="2" |  
 
| colspan="2" |  
 
|-
 
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 
|}
 
|}

Revision as of 10:35, 17 November 2021

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.

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. 
[[File:]] - ProcessWhenFull
0 = Do Nothing when Buffer is full, 1 = Auto call FFT macro when Buffer is full 
[[File:]] - Return


Fc9-comp-macro.png Uninit
Un-initialize the UART and release the resources 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png ReceiveByteArray
Receives an array of bytes and returns the number of bytes received. 
Fc9-u8-icon.png - BYTE Data
A byte array variable to hold the received data 
Fc9-u16-icon.png - UINT NumBytes
Maximum number of bytes to try and receive 
Fc9-u16-icon.png - UINT Timeout
Max amount of time in ms to wait between bytes 
Fc9-u16-icon.png - UINT Return


Fc9-comp-macro.png ReceiveString
Receives a string of bytes and returns the number of bytes received. 
Fc9-string-icon.png - STRING StringData
 
Fc9-u16-icon.png - UINT NumBytes
Maximum number of bytes to try and receive 
Fc9-u16-icon.png - UINT Timeout
Max amount of time in ms to wait between bytes 
Fc9-u8-icon.png - BYTE Return


Fc9-comp-macro.png Start
Startup routine required by the hardware device. Automatically clears the display after initialising. 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png SetLEDState
Sets the state of a single LED 
Fc9-u8-icon.png - BYTE Port
0 = PortA, 1 = PortB 
Fc9-u8-icon.png - BYTE LED
0 = LED0, 7 = LED7 
Fc9-u8-icon.png - BYTE State
 
Fc9-void-icon.png - VOID Return


Fc9-comp-macro.png GetRxIdent
Gets the Rx ID as a Integer Standard and Extended IDs. 
Fc9-u8-icon.png - BYTE Buffer
 
Fc9-u32-icon.png - ULONG Return


Fc9-comp-macro.png Initialise
Must be called before any other CAN component macros to enable and initialise the CAN peripheral.  
Fc9-void-icon.png - VOID Return



Property reference

Fc9-prop-icon.png Properties
Fc9-type-17-icon.png Connect To
 
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-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. 
Fc9-conn-icon.png Connections
Fc9-conn-icon.png Simulations