From: david t53 on 15 Jul 2010 08:26 Let's say I have the following filter: h = fdesign.lowpass('fp,fst,ap,ast', 0.45, 0.55, 1, 60); Hd = design(h, 'butter', 'FilterStructure', 'df1sos', 'MatchExactly', 'stopband'); set(Hd, 'Arithmetic', 'fixed', 'InputWordLength', 16, 'InputFracLength', 15, 'CoeffWordLength', 16, 'CoeffAutoScale', false, 'NumFracLength', 15, 'DenFracLength', 15, 'ScaleValueFracLength', 15, 'Signed', true, 'SectionInputWordLength', 16, 'SectionInputAutoScale', true, 'SectionOutputWordLength', 16, 'SectionOutputAutoScale', true, 'StateWordLength', 16, 'StateFracLength', 15, 'ProductMode', 'Specifyprecision', 'ProductWordLength', 32, 'NumProdFracLength', 29, 'DenProdFracLength', 29, 'AccumMode', 'KeepMSB', 'AccumWordLength', 40, 'CastBeforeSum', true, 'OutputWordLength', 16, 'OutputMode', 'Specifyprecision', 'OutputFracLength', 15, 'RoundMode', 'convergent', 'OverflowMode', 'wrap'); --- Is there a way to automatically generate a C function equivalent to y=filter(Hd, x)? If not, would the Filter Design HDL Coder be helpful (to generalte HDL code, and then manually transform this to C code?) note: I have the Signal Processing Toolbox, Filter Design Toolbox, HDL Coder and Fixed Point licenses. Regards, David
From: david t53 on 15 Jul 2010 09:15 ups, I just realized that I do not have the Filter Design HDL Coder license, but I do have the others: the Signal Processing Toolbox, Filter Design Toolbox and Fixed Point licenses. -- Is there a way to automatically generate a C function equivalent to y=filter(Hd, x)? for this filter: h = fdesign.lowpass('fp,fst,ap,ast', 0.45, 0.55, 1, 60); Hd = design(h, 'butter', 'FilterStructure', 'df1sos', 'MatchExactly', 'stopband'); set(Hd, 'Arithmetic', 'fixed', 'InputWordLength', 16, 'InputFracLength', 15, 'CoeffWordLength', 16... --- Regards, David
From: Wayne King on 15 Jul 2010 09:45 "david t53" <david_t53(a)sogetthis.com> wrote in message <i1n1l9$44c$1(a)fred.mathworks.com>... > ups, I just realized that I do not have the Filter Design HDL Coder license, > but I do have the others: the Signal Processing Toolbox, Filter Design Toolbox and Fixed Point licenses. > > -- > Is there a way to automatically generate a C function equivalent to y=filter(Hd, x)? > for this filter: > h = fdesign.lowpass('fp,fst,ap,ast', 0.45, 0.55, 1, 60); > Hd = design(h, 'butter', 'FilterStructure', 'df1sos', 'MatchExactly', 'stopband'); > set(Hd, 'Arithmetic', 'fixed', 'InputWordLength', 16, 'InputFracLength', 15, 'CoeffWordLength', 16... > > > --- > Regards, > David Hi David, The filter objects are currently not supported for C code generation. However, both butter() and a number of Fixed-Point Toolbox functions are supported for C code generation. You will need the Real-Time Workshop software to be able to generate embeddable C code using butter() and the Fixed-Point Toolbox software. Wayne
From: david t53 on 15 Jul 2010 11:15 Thanks for your answer. Good, I have the Real-Time Workshop license. Can you please provide me a quick example of generating C code for creating a butter filter (say, N=10, wn=0.3), fixed-point arithmetics using cascaded bi-quads, and filtering an input vector? Regards, David
From: Wayne King on 16 Jul 2010 08:47
"david t53" <david_t53(a)sogetthis.com> wrote in message <i1n8ma$ifc$1(a)fred.mathworks.com>... > Thanks for your answer. > > Good, I have the Real-Time Workshop license. > > Can you please provide me a quick example of generating C code for > creating a butter filter (say, N=10, wn=0.3), fixed-point arithmetics using cascaded bi-quads, and filtering an input vector? > > > Regards, > David Hi David, if you want a biquad structure, then you will need to have the Signal Processing Blockset and use System objects--both signalblks.DigitalFilter and signalblks.BiquadFilter (System objects) support biquad structures--The former in the case of IIR filters. In R2010a, Signal Processing Blockset has Simulink as a recommended product, but it is not required. By using butter(), you will not be able to implement a biquad filter structure. Basically you will implement your filter using filter() and that uses a direct form II structure transposed. Wayne |