Rectangular impulse built

public static double calcimpuls(double U,double T,double x) { if (x >= 0 && x <= T) return U; else return 0; } 

After that, the direct Fourier transform begins.

enter image description here

In the formula, I call the result of the constructed rectangular pulse into the formula of the direct Fourier transform (Given the complexity of integration, the Euler formula is applied). Thus, I get the spectral density

 public static Complex GetSpectralDensity(double U, double frequency, double T,double x) { NumericalIntegration integration = new NumericalIntegration(); double f = 1 / T; double w = 2 * Math.PI * f; return calcimpuls(U, T, x) * integration.Calculate(t => Math.Cos(w * t), 0, T) - Complex.ImaginaryOne * calcimpuls(U, T, x) * integration.Calculate(t=>Math.Sin(w*t),0,T); } 

From the theory, the spectral density of amplitudes is a module of the complex spectral density, therefore

enter image description here

Given that the graph below is very similar to the graph y = sin * x / x, but without negative coordinates, then I execute the following code (module so that there are no negative numbers)

 public static double GetSinModul(double U, double frequency, double T) { double x7 = GetSpectralDensity(U, frequency, T, 1);------ Неявное преобразование типа "System.Numerics.Complex" в "double" невозможно return U *T * Math.Abs(Math.Sin(x7) / x7); } 

The result should be such a schedule.

enter image description here

The problem is in converting System.Numerics.Complex and double.

I decided that it would be better to assign the result of the execution of the GetSpectralDensity method to the variable x7, for further calculation. But the problem in the conversion remained. The implicit conversion of the type "System.Numerics.Complex" to "double" is impossible

The formula with an imaginary unit and therefore the method will be Complex and not double. And the compiler will not allow it.

  • “The problem is in converting System.Numerics.Complex and double.” - what exactly is the problem? - VladD
  • 2
    Yeah, now it's clearer. Well, the problem is obvious: your GetSpectralDensity returns Complex . The compiler does not know how to get a double from it. Take X , drop Y ? Take Y , drop X ? Take R ? How do you want? The compiler does not convert for you. - VladD
  • If the spectral density of amplitudes is a module of complex density, then take the module from the result: GetSpectralDensity(U, frequency, T, 1).Magnitude - kmv

1 answer 1

The problem was solved in this way: 1) Created a list, unloaded the values ​​of the GetSpectralDensity method 2) With the help of ForEach, from each complex number I took the real part of the number and assigned it to the variable x2

  public static double GetSinModul(double U, double frequency, double T) { double x2=0; List<Complex> value = new List<Complex>(); value.Add(GetSpectralDensity(U, frequency, T, 1)); value.ForEach(x1=>x2=x1.Real);//Real return x2 * T * Math.Sin(GetSpectralDensity(U, frequency, T, 1).Magnitude) / GetSpectralDensity(U, frequency, T, 1).Magnitude; } 

Problem with implicit conversion resolved. Thank!