Convert Matlab SOS filters to C#
This file takes a filter in sos sections and converts it into a C# class. It "unwinds" the sos stages explicitly without looping for speed...it runs faster under managed C# than it does under Matlab.
For example, to design a sos filter:
H = design(fdesign.highpass('fst,fp,ast,ap',250, 300, 20, 3, 1000),'cheby1','MatchExactly', 'passband');
Then to convert the sos sections into C# code:
sos2csharp(H,'filter.cs')
This creates the C# class filter.cs file in the current working directory. Add it to your C# solution. To call it within C#, for instance,
double[] x {1.0, 2.0, 4.0, 2.0}; // input data
double[] y = new double[4]; // output data
Filter myFilter = new Filter();
myFilter(x, y); // the filtered data is now in array y
double[] x1 {4.0, 2.0, 7.0, 1.0}; // new input data
myFilter(x1, y); // the initial conditions are saved, so this is
// same as if you gave it the concatenation of [x x1]
Zitieren als
James Squire (2024). Convert Matlab SOS filters to C# (https://www.mathworks.com/matlabcentral/fileexchange/23530-convert-matlab-sos-filters-to-c), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.2.0.0 | Clarified example calling code |
||
1.1.0.0 | Added example of calling it from within a C# program |
||
1.0.0.0 |