@@ -15,11 +15,11 @@ var window = new FftSharp.Windows.Hanning();
1515window .ApplyInPlace (signal );
1616
1717// Calculate the FFT as an array of complex numbers
18- Complex [] fftRaw = FftSharp .Transform . FFT (signal );
18+ System . Numerics . Complex [] spectrum = FftSharp .FFT . Forward (signal );
1919
2020// or get the magnitude (units²) or power (dB) as real numbers
21- double [] fftMag = FftSharp .Transform . FFTmagnitude ( signal );
22- double [] fftPwr = FftSharp .Transform . FFTpower ( signal );
21+ double [] magnitude = FftSharp .FFT . Magnitude ( spectrum );
22+ double [] power = FftSharp .FFT . Power ( spectrum );
2323```
2424
2525Signal | Windowed Signal | FFT
@@ -32,12 +32,12 @@ Signal | Windowed Signal | FFT
3232// sample audio with tones at 2, 10, and 20 kHz plus white noise
3333double [] signal = FftSharp .SampleData .SampleAudio1 ();
3434int sampleRate = 48_ 000 ;
35+ double samplePeriod = sampleRate / 1000 . 0 ;
3536
3637// plot the sample audio
37- var plt = new ScottPlot . Plot ( 400 , 200 );
38- plt .AddSignal (signal , sampleRate / 1000 . 0 );
38+ ScottPlot . Plot plt = new ( );
39+ plt .AddSignal (signal , samplePeriod );
3940plt .YLabel (" Amplitude" );
40- plt .Margins (0 );
4141plt .SaveFig (" time-series.png" );
4242```
4343
@@ -59,15 +59,15 @@ double[] signal = FftSharp.SampleData.SampleAudio1();
5959int sampleRate = 48_ 000 ;
6060
6161// calculate the power spectral density using FFT
62- double [] psd = FftSharp .Transform .FFTpower (signal );
63- double [] freq = FftSharp .Transform .FFTfreq (sampleRate , psd .Length );
62+ System .Numerics .Complex [] spectrum = FftSharp .FFT .Forward (audio );
63+ double [] psd = FftSharp .FFT .Power (spectrum );
64+ double [] freq = FftSharp .FFT .FrequencyScale (psd .Length , sampleRate );
6465
6566// plot the sample audio
66- var plt = new ScottPlot .Plot (400 , 200 );
67+ ScottPlot . Plot plt = new ScottPlot .Plot ();
6768plt .AddScatterLines (freq , psd );
6869plt .YLabel (" Power (dB)" );
6970plt .XLabel (" Frequency (Hz)" );
70- plt .Margins (0 );
7171plt .SaveFig (" periodogram.png" );
7272```
7373
@@ -82,12 +82,12 @@ plt.SaveFig("periodogram.png");
8282If you are writing a performance application or just enjoy working with real and imaginary components of complex numbers, you can build your own complex array perform FFT operations on it in place:
8383
8484``` cs
85- Complex [] buffer =
85+ System . Numerics . Complex [] buffer =
8686{
87- new Complex ( 42 , 0 ),
88- new Complex ( 96 , 0 ),
89- new Complex ( 13 , 0 ),
90- new Complex ( 99 , 0 ),
87+ new ( real : 42 , imaginary : 12 ),
88+ new ( real : 96 , imaginary : 34 ),
89+ new ( real : 13 , imaginary : 56 ),
90+ new ( real : 99 , imaginary : 78 ),
9191};
9292
9393FftSharp .Transform .FFT (buffer );
0 commit comments