Code covered by the BSD License  

Highlights from
Convert Matlab SOS filters to C#

5.0

5.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 2.31 KB File ID: #23530
image thumbnail

Convert Matlab SOS filters to C#

by James Squire

 

02 Apr 2009 (Updated 07 Dec 2010)

Converts Matlab SOS filters into a fast C# class

| Watch this File

File Information
Description

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]

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
19 Nov 2011 Morris  
Please login to add a comment or rating.
Updates
03 Apr 2009

Added example of calling it from within a C# program

07 Dec 2010

Clarified example calling code

Tag Activity for this File
Tag Applied By Date/Time
c James Squire 03 Apr 2009 11:08:06
filter James Squire 03 Apr 2009 11:08:07

Contact us at files@mathworks.com