Variable number of filter channels in Simulink

4 visualizzazioni (ultimi 30 giorni)
In Simulink, I am modelling a MIMO system. P inputs, Q outputs, and all possible (P -> Q) impulse responses are known. I could simply implement P x Q FIR blocks, and everything would normally be fine.
The problem is that I need to run the model, then modify P or Q, then run the model again. Multiple times, changing P or Q each time. edit : The model will ultimately run on an outboard FPGA-based device with limited processing capacity, it is therefore important to avoid unnecessary calculations.
A similar problem occurs elsewhere in the same model, with vector-array addition blocks in which the i/o sizes need to be variable.
Currently, the model uses a Matlab function block, for which P and Q are inputs along with all necessary signals and coefficients.
Thank you for any advice !

Risposta accettata

Shivam Gothi
Shivam Gothi il 5 Dic 2024
Hello @Ruairidh,
What I understand from your question is:
You have a MIMO system which has P inputs and Q outputs. You have all the possible impulse responses corresponding to input-output pair.You want to apply different inputs to the system and observe the outputs "Q". instead of manually changing the inputs each time and running the simulation again, you want to automate the process.
For any system, its input and output ports are fixed. As you mentioned that there are a variable number of inputs, I understand that some input ports may not receive any signal, resulting in a zero input.
Let us consider that you want to apply signals as per you specifications at some of the input ports. But, manualy changing the input signal each time and running the simulation again and again is not preferable.
In order to overcome this, I will suggest the following workaround:
Define the input signals as a functioon of time in Command window. Run the simulink model directly from the command window using the command "sim". This will enable you to run the model multiple times by taking different combinations of input signals.
Follow the below given steps to implement the workaround:
  • In the base workspace, define a variable "t" which is an array of timesteps taken by the simulation.
  • Suppose that the system has input ports P1, P2, P3, P4 and P5
  • Suppose that the system has output ports Q1 and Q2. As mentioned in the question, you have information regarding all the possible impulse responses. Therefore you can calculate Q1 from the given input signal.
  • Define the input signals as function of time (t) as per your specifications in the base workspace. For example, suppose that you want to apply input signals only at the ports P1 and P3. Define them as function of "t". Set all the remaining input signals corresponding to the other input ports to zero.
% demo code to define the signals to MIMO system in the command window
% (Paste this code in editor window and execute the below code. It will
% automatically run the simulation by taking the inputsignals defined by
% you for each iteration.
clc;
clear;
time_step = 0.0001;
simulation_time = 1;
t = 0:time_step:simulation_time;
t=t';
n = 3; %n = number of times you want to do simulation by varying the inputs to the system
Output_Q1=zeros(length(t),n); %this is a 2d array of the plant output "Q1". each column holds the output "Q1" vector corresponding to the perticular iteration.
Output_Q2=zeros(length(t),n);
%First iteration: P1 and P3 are applied. All other inputs = 0.
P1 = 10*sin(2*pi*t);
P2 = zeros(length(t),1);
P3 = cos(0.5*t);
P4 = zeros(length(t),1);
P5 = zeros(length(t),1);
out=sim('Simulink_model_name'); %replace "simulink_model_name" with the name of your simulink model.
Output_Q1(:,1)=out.yout{1}.Values.Data; %(Store the result of first iteration in first coloumn of Output_Q1 vector)
Output_Q2(:,1)=out.yout{2}.Values.Data;
%Second iteration: P2 and P2 are applied. All other inputs = 0.
P1 = zeros(length(t),1);
P2 = sin(t)+cos(0.5*t);
P3 = zeros(length(t),1);
P4 = cos(t)+sin(0.5*t);
P5 = zeros(length(t),1);
out=sim('Simulink_model_name'); %replace "simulink_model_name" with the name of your simulink model.
Output_Q1(:,2)=out.yout{1}.Values.Data; %(Store the result of second iteration in second coloumn of Output_Q1 vector)
Output_Q2(:,2)=out.yout{2}.Values.Data;
%third iteration: only P5 is applied. All other inputs = 0.
P1 = zeros(length(t),1);
P2 = zeros(length(t),1);
P3 = zeros(length(t),1);
P4 = zeros(length(t),1);
P5 = cos(2*t);
out=sim('Simulink_model_name'); %replace "simulink_model_name" with the name of your simulink model.
Output_Q1(:,1)=out.yout{1}.Values.Data; %(Store the result of third iteration in third coloumn of Output_Q1 vector)
Output_Q2(:,1)=out.yout{2}.Values.Data;
%Now you can analyse the output stored in "Output_Q1" and "Output_Q2" for
%each iteration.
  • Using the impulse responses, organize your MIMO system into a subsystem as depicted in the figure. Utilize Simulink's "Inport" and "Outport" blocks to input signals from the workspace into the system and export the system's output back to the workspace.
  • Open the "configuration properties" by pressing "Ctrl+E". Navigate to the "Data Import/Export" tab and make the below given changes:
  • Now navigate to the "Solver" tab and make the following changes:
  • After making the above changes, save the simulink madel and you may close it.
  • Run the aboove attached matlab script. It will run the simulation three times. Each time it will take a different combination of inputs. It will store the result of each iteration in 2d arrays named "Output_Q1" and "Output_Q2".
I hope you find the information useful !!
  3 Commenti
Shivam Gothi
Shivam Gothi il 9 Dic 2024
Hello @Ruairidh,
Sorry for the delayed reply.
I have not worked much on hardware prototyping on FPGA-based machine.
I recommend you to post a new question in the community. Someone in the community, working on the hardware prototyping might be able to help you out.
Make sure that you add proper tags to your question and elaborate the issue faced by you in detail.
Thanks !
Ruairidh
Ruairidh il 12 Dic 2024
Thank you kindly for your advice Shivam, I'll do as you suggest.
Go well !

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by