Thread Subject: m-file level 2 s function

Subject: m-file level 2 s function

From: amr sayed

Date: 16 Nov, 2009 17:50:17

Message: 1 of 2

Dear all
i tried many time to implement m-file level 2 s function for wavelet function
[C,L] = wavedec(u,3,'db1');
cA3 = appcoef(C,L,'db1',3);

that accept one input (double) u and perform the wavelet function to output double
my m-file is operate with no errors but give me a trivial results.
i don't know why
please any one help me
the following is my m-file level 2 file

function amr(block)
% Level-2 M file S-Function for times two demo.

  setup(block);
  
%endfunction

function setup(block)
  
  %% Register number of input and output ports
  block.NumInputPorts = 1;
  block.NumOutputPorts = 1;

  %% Setup functional port properties to dynamically
  %% inherited.
  block.SetPreCompInpPortInfoToDynamic;
  block.SetPreCompOutPortInfoToDynamic;
 
  block.InputPort(1).Complexity = 'Real';
  block.InputPort(1).DataTypeId = 0;
  block.InputPort(1).SamplingMode = 'Sample';
  block.InputPort(1).Dimensions = 1;
  
  block.OutputPort(1).Complexity = 'Real';
  block.OutputPort(1).DataTypeId = 0;
  block.OutputPort(1).SamplingMode = 'Sample';
  block.OutputPort(1).Dimensions = 1;
  
  %% Set block sample time to inherited
  block.SampleTimes = [-1 0];
  
  %% Run accelerator on TLC
  block.SetAccelRunOnTLC(true);
  
  %% Register methods
  block.RegBlockMethod('Outputs', @Output);
  
%endfunction

function Output(block)

u=block.InputPort(1).Data;
  [C,L] = wavedec(u,3,'db1');

cA3 = appcoef(C,L,'db1',3);

  block.OutputPort(1).Data = cA3;
%endfunction

Subject: m-file level 2 s function

From: Phil Goddard

Date: 17 Nov, 2009 01:44:01

Message: 2 of 2

There are possibly/probably 2 issues that need resolving:

a) As implemented your block has direct feedthough but you have not told Simulink about it.
To do so you need to add the following line to the Setup method

block.InputPort(1).DirectFeedthrough = true;

b) Looking at the doc, the first input to the wavedec function should be a vector (of values over all time), but the s-function only passes in one number to it at a time.

Phil.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mfile level 2 s... amr sayed 16 Nov, 2009 12:54:03
rssFeed for this Thread

Contact us at files@mathworks.com