simulink user defined matlab function outputs zero irrespective of input

조회 수: 4 (최근 30일)
I am using simulink user defined block to realise a difference equation. The function is defined as shown below.
function y = fcn(u)
a = [1 -2 1]; % left hand side of difference equation
b = [0 1 2]; % right hand side of difference equation
y=filter(b,a,u);
When I use this block independenly with some array as input, I am able to get the expected values. But when I use this block in another design, the output is always zero though the input is changing. Any suggestions on how to debug this ?
  댓글 수: 4
Ameer Hamza
Ameer Hamza 2020년 9월 23일
and what is the value of y if you execute code line by line during breakpoint?
Nithin Ravani Nanjundaswamy
Nithin Ravani Nanjundaswamy 2020년 9월 23일
Hi, my supervisor suggessted that the filter function is designed to accept data as (timed) arrays. But Simulink works differently, here the function is called at every simulation step and feed with the current input data. So he suggested to use discrete filter block with the calculated filter coefficients. would you please advice me on how to calculate filter co-efficients from the difference eqaution which is mentioned in the question.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jalaj Gambhir
Jalaj Gambhir 2020년 10월 1일
Hi,
Please have a look at the model examples given here.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by