### Do you have an example of a discrete Fourier transform (DFT) for a single frequency in EMT simulations?

In this example an IEC compliant DLL based dynamic model named "DFT analyser" is provided intended for EMT simulations. It retrieves the magnitude (i.e. peak value of sine wave) coefficient of a single Fourier term (i.e. at a specific integer harmonic order, multiple of the base frequency) contained within a measured input signal. The DFT model operates well whenever the specific frequency component matches well with the actual harmonic in the signal. For example, if trying to measure the magnitude of voltages in a 50 Hz network, the calculation will retrieve accurate results if the frequency in the system matches exactly 50Hz. If the system’s frequency differs (e.g. 49 Hz), then the DFT may retrieve less accurate results. In those cases, a more granular FFT calculation is recommended in order to identify the actual frequency component prior to computing the magnitude at a specific frequency.

The following customization options are available:

- one DLL named "IEC_DLL_DFT_50Hz_x64.dll" is intended for computing the magnitude of the 50Hz or one of the higher integer orders of an input signal.

- one DLL named "IEC_DLL_DFT_60Hz_x64.dll" is intended for computing the magnitude of the 60Hz or one of the higher integer orders of an input signal

Both DLLs work only on PowerFactory versions using x64 bit architecture. Both DLLs recompute the magnitude each 20ms, in a discrete manner i.e. a series of results updated each 20ms. An input signal buffer of 256 samples is used, hence the simulation time step requirements are strict: Ts = 1/(50*256) s for "IEC_DLL_DFT_50Hz_x64.dll" and Ts = 1/(60*256) s for "IEC_DLL_DFT_60Hz_x64.dll". The simulation time step must be smaller than Ts. DLL Model sampling times are fixed and cannot be changed, unless changing the source code and recompiling the DLL. The DLLs are operating with the GeneralInformation flag "-PFPrecise". That is, in PowerFactory 2021 SP3 and onwards, they will trigger an interrupt event at the exact sample time. In previous versions, a linear interpolation at the call time is applied (which is faster but may lead to larger inaccuracies).

In PowerFactory, the DLLs can be changed by changing the DLL path in the block definition object "DFT Analyser" page "Basic Options". Hence you can switch from a 50 to a 60 Hz based DFT analyser.

Refer to the example project "EMT_ExampleDFT" attached. Make sure you work with PowerFactory 2021, preferably 2021 SP3 or higher. Run the simulation. Go to the plot page "§ DFT Analyser (DLL model)". The results obtained by the analyser are shown. Each common model "DFT Analyser x", where x=1,2,3 is configured to capture a certain integer harmonic order (parameter "OutputOrder", preconfigured for harmonic order 1, i.e. fundamental frequency 50 Hz). Each common model "Measurement Selector x", where x=1,2,3 is configured to retrieve either phase A/B/C (via parameter PHASE_SELECTOR) current or voltage (via parameter FLAG_SELECTOR). "Measurement Selector 1" will feed an input signal to "DFT Analyser 1", and so on. The models operate independently: one will need to have in service a pair of these models e.g. "DFT Analyser 1" and "Measurement Selector 1" OR "DFT Analyser 2" and "Measurement Selector 2" OR "DFT Analyser 3" and "Measurement Selector 3" OR all of them (as in the example) in order to obtain the results for all three phase quantities. Each DFT Analyser model generates one output signal "dft_mag". The output corresponds to the discrete Fourier transform magnitude of the last 20ms (for 50Hz) and 16.67ms(for 60Hz) of that signal (hence the result will be delayed by one fundamental frequency period. It is not possible to generate in the same time results for multiple harmonic orders but only one. You will need to create multiple such DFT Analyser models if multiple orders are of interest.

Another plot is shown "§ FFT (post-processing results)" containing an FFT as precise calculation but as post processing. Results seem to be in line with the precise FFT calculation. Some mismatches might occur if the frequency order to be captured is not exactly equal to "OutputOrder*50Hz or OutputOrder*60Hz". The project contains a controlled voltage source that generates some harmonics on each phase, so the waveforms are distorted. You can also compare the magnitude values of each injected harmonic order of the voltage (as programmed in the Fourier Source element ElmFsrc) with the results given by the DFT.

The model is packed already for convenience in a template containing two terminals linked by a breaker, named "DFT Analyser". It can be deployed in a different project simply by copying the template in the destination project, under the projects' Library->Templates. It can be inserted in a grid using the General Templates symbol in the Drawing Toolbar.