MathNet.Numerics is incompatible with WPF?

bhs67

Well-known member
Joined
Oct 11, 2021
Messages
52
Programming Experience
10+
I'm striving to create a sine wave and an FFT in WPF. The YouTube FFT in C# tutorial uses Forms => www.youtube.com/watch?v=DqQlNoQW00w.

Starting with:
public partial class MainWindow : Window

Add to References:
MathNet.Numerics (from NuGet)

Add:
using MathNet.Numerics;

Results in:
Error CS0104 'Window' is an ambiguous reference between 'MathNet.Numerics.Window' and 'System.Windows.Window'
 
It's not a matter of incompatibility. That's just how the using keyword works with regards to namespaces. It's just a regular old namespace resolution ambiguity because you decided to use:
C#:
using System.Windows;
using MathNet.Numerics;

using tells the compiler that when you use a type without any explicit namespace qualifiers, that it should go through the list of namespaces declared in using to try to figure out what you meant by that unqualified type. If there's more than one type with the same name in two or more namespaces, the compiler will tell you that it can't figure out which one you wanted.

If you want to keep both using statements:
You'll need to be more explicit when using type names. For example, change to:
C#:
public partial class MainWindow : System.Windows.Window
in your WPF main window class declaration.

Elsewhere where you need to use the MathNet Window you'll need to be more explicit about declaring:
C#:
var window = new MathNet.Numerics.Window();

If you want to prioritize one namespace over another:
Let's say you use the types from WPF more often, then just declare:
C#:
using System.Windows;

and leave this alone:
C#:
public partial class MainWindow : Window

and when you need to use the MathNet Window, you'll need to be explicit:
C#:
var window = new MathNet.Numerics.Window();
 
Last edited:
You can also declare an alias for using directive to shorten qualifiers, see here: using directive - C# Reference
In the above example you could have:
C#:
using MN = MathNet.Numerics;
and then do:
C#:
var window = new MN.Window();
 
I'm striving to create a sine wave and an FFT in WPF.
If you wanted to create an FFT, why are you using the pre-built FFT in MathNet?
 
No. C# is a general purpose language. Most general purpose languages don't have FFT implementations built-in. And no, the current versions of the .NET framework doesn't provide one either.
 
I suspect that what you are trying to say is that you want to build a spectrum analyzer, rather than build an FFT. You just want to use an FFT to get the component frequencies.
 
Nope. I need to create frequencies, convert them to the frequency domain, pad 0's between the points / and after the points, then convert back to the time domain. This is related to Nyquist Sampling.
 
Shouldn't your created frequencies already be in the frequency domain? Or are you creating a wave and then converting into the frequency domain?
 
I need to create sine waves in the time domain, convert them to the frequency domain, add additional numbers to the frequency domain numbers, convert them back to the time domain, view how the sine wave shape changed.
 
If you are creating the sine waves, then you already know the frequency of each of the waves because that would be the period of that particular wave.
 
I want to view the effects of adding 0's. I have a new idea, want to test it.

This - theproaudiofiles.com/oversampling/ - shows some images of oversampling. Oversampling is done to record music with fewer data bits stored, yet reconstructs the actual waveshape when the music is heard.
 
In general data compression theory and practice, more data doesn't compress information better because there is an absolute minimum of what information needs to be sent. More data may provide a better data model to aid in compression, but the information that is derived still needs to get sent somehow for lossless compression. For lossy data compression, then yes, more data helps the various compression algorithms figure what is essential information, and what can be tossed.

I thought that wavelets were better for sound compression, but then I'm not an audiophile. I don't hear the sound artifacts Bose speakers actually sound good to me -- to the horror of a lot of my audiophile friends.

Anyway, I see now that you are really not interested in building/implementing an FFT, but rather just need some implementation so that you can play with your data. You are on the right path of picking up something off the shelf.
 
Back
Top Bottom