How can I write a Mask parameter to the workspace in Simulink?

조회 수: 20 (최근 30일)
Rafael Cordero
Rafael Cordero 2020년 6월 21일
댓글: Rafael Cordero 2020년 6월 23일
Hello world!
I have a masked subsystem with two parameters fc_lo and fc_hi. They define the corner frequencies of a Bandpass FIR filter inside the subsystem (specified in the dialog box of the Bandpass FIR filter block). However, once run, I get an error saying how these variables are not defined in the Matlab workspace.
Is there a way to write these Mask parameters to the matlab workspace so that the bandpass filter block will recognize them?
(I already looked at previous questions such as https://uk.mathworks.com/matlabcentral/answers/179344-how-can-i-mask-a-bandpass-filter-block-from-the-dsp-system-toolbox-r2014b?s_tid=answers_rc1-1_p1_MLT - but when I implemented their solutions the model ran incredibly slow).
Thanks
Rafael
  댓글 수: 2
Ashish Azad
Ashish Azad 2020년 6월 22일
Hi Rafael,
You have to initialize the value of parameter used by the blocks inside subsystem using fc_lo and fc_hi.
Could you please share your screenshot of subsystem block diagram, so I can assist you further.
Rafael Cordero
Rafael Cordero 2020년 6월 22일
편집: Rafael Cordero 2020년 6월 22일
Hello Ashish,
This is the masked subsystem:
The mask is the following:
Inside, the subsystem is the following. It is essentially a "filtfilt" operation (i.e. zero-phase filtering by reversing the input signal and filtering again). Bandpass filter 1 and 2 are identical and their parameters are also shown.
So how exactly do I go about "initializing the value of parameter used by the blocks inside subsystem using fc_lo and fc_hi"?
Thanks

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 6월 22일
The masked parameters seem to mismatch internal variables. The easiest way is to change the #1 and #2 parameter name in the mask dialog from "ecg_fc_lo" to "fc_lo", from "ecg_fc_hi" to "fc_hi". But then, you also need to add the masked parameter for "fs".
Look in document to learn about mask.
  댓글 수: 11
Fangjun Jiang
Fangjun Jiang 2020년 6월 23일
Sorry for the extra route. You could utilize your original mask. In the original model you posted, in the mask of the subsystem, in the initilization tab, add the two lines below
assignin('base','fc_lo',fc_lo);
assignin('base','fc_hi',fc_hi);
You should have fc_lo and fc_hi defined in the base workspace initially to avoid error when starting simulation right after openning the model. The value doesn't matter. When Simulation runs, the value got updated.
Rafael Cordero
Rafael Cordero 2020년 6월 23일
I think I understand what is happening.
I did what Fangjun suggested and it works. I just have to be careful HOW I do it.
I was testing the model sent above (FIRfiltfilt3) by deleting the workspace variables fc_lo and fc_hi then re-running the simulink model. This did not work because the mask parameters are sent to the workspace via 'assignin('base','fc_lo',WhatEverValueFromMask)' ONLY a) when the model is opened and b) when the paramters are changed in the mask.
What I was doing was opening the model, running it (it would work the first time), then deleting the variables in the workspace and trying to run it again (this would not work because the variables were not being created in the workspace in this fashion).
However, if I delete the workspace variables and then go back to the mask and change fc_lo and fc_hi, they are once again created in the workspace and the model runs fine.
This is just stuff to consider but it works fine, here is the final model for anyone interested!
Thanks so much for your inputs!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by