triforcely / Octave.NET

📈 More than cross-platform Octave process wrapper 🔬
MIT License
32 stars 7 forks source link

How do I use variables? #18

Open dds852456tw opened 6 months ago

dds852456tw commented 6 months ago

My requirement is to input a double array and then do FFT using Octave, but I don’t know how to give the input to Octave. by the way FFT output format is complex , can i use AsVector(); ??

public static void FFT_Octave(double[] signal) { double fre, amp;

using (var octave = new OctaveContext())
{
    var input = octave.Execute(signal.ToOctave()); // [??????]

    var vectorResult = octave
        .Execute("fft(input)")
        .AsVector();
}

}

dds852456tw commented 6 months ago

Hi I found the solution below, but the result is string not array or another type, I referred to the test examples and did not find any suitable ones for process the complex.

octave

>> fft([1 2 3 4 5])
ans =

   15.0000 +       0i   -2.5000 +  3.4410i   -2.5000 +  0.8123i   -2.5000 -  0.8123i   -2.5000 -  3.4410i

c#

FFT_Octave([0, 1, 2, 3, 4, 5]);

public static void FFT_Octave(double[] signal)
{
    double fre, amp;

    using (var octave = new OctaveContext())
    {
        string input = signal.ToOctave(); // [??????]

        string cmd = "fft(" + input + ")";

        var vectorResult = octave.Execute(cmd);
    }
}