Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to use Fourier functionality?#1074

Unanswered
VikingExplorer asked this question inQ&A
Discussion options

Does anyone know how to use the Fourier functionality?

  1. I would like to create input data that is composed of several different sinusoids of different frequencies.
  2. Then call FFT to get the coefficients.
  3. Make sure all other frequencies have zero for coefficients.

I created an issue so that the documentation can be improved regarding Fourier:#1073

You must be logged in to vote

Replies: 1 comment

Comment options

Hello@VikingExplorer

I know you asked this question a long time ago so you are likely to have either figured out the answer yourself or have given up. Nonetheless, here is a code snippet showing one way to carry out your steps. It can be modified to use different units for frequency, generate the sinusoids in a different way, etc.

private static Complex[] GenerateDataAndCalculateFourierSpectrum(){    int signalLength = 1000;    double[] frequencies = new double[] { 100, 250, 475 };    Complex[][] signals = frequencies.Select(frequency => GenerateSignal(frequency, signalLength)).ToArray();    Matrix<Complex> signalMatrix = Matrix.Build.DenseOfRowArrays(signals);    Complex[] resultantSignal = signalMatrix.ColumnSums().ToArray();    Fourier.Forward(resultantSignal);    return resultantSignal;}private static Complex[] GenerateSignal(double omega, int signalLength){    double[] phases = Generate.LinearSpaced(signalLength, 0, 2 * Math.PI);    Complex[] signal = phases.Select(phase => Complex.FromPolarCoordinates(1, (float)(omega * phase))).ToArray();    return signal;}

Here is a plot of the magnitudes of the coefficients. As you can see, the peaks match the frequency numbers given.

image

Hope this helps!

-strMikhailPotapenko

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@VikingExplorer@strMikhailPotapenko

[8]ページ先頭

©2009-2025 Movatter.jp