simulink

simulink之S函数

此生再无相见时 提交于 2020-01-21 01:02:51
s函数是system Function的简称,用它来写自己的simulink模块。(够简单吧,^_^,详细的概念介绍大伙看帮助吧)可以用matlab、C、C++、Fortran、Ada等语言来写,这儿我只介绍怎样用matlab语言来写吧(主要是它比较简单) 先讲讲为什么要用s函数,我觉得用s函数可以利用matlab的丰富资源,而不仅仅局限于simulink提供的模块,而用c或c++等语言写的s函数还可以实现对硬件端口的操作,还可以操作windows API等的 先介绍一下simulink的仿真过程(以便理解s函数),simulink的仿真有两个阶段:一个为初始化,这个阶段主要是设置一些参数,像系统的输入输出个数、状态初值、采样时间等;第二个阶段就是运行阶段,这个阶段里要进行计算输出、更新离散状态、计算连续状态等等,这个阶段需要反复运行,直至结束。 在matlab的workspace里打edit sfuntmpl(这是matlab自己提供的s函数模板),我们看它来具体分析s函数的结构。 它的第一行是这样的:function [sys,x0,str,ts]=sfuntmpl(t,x,u,flag) 先讲输入与输出变量的含义:t是采样时间,x是状态变量,u是输入(是做成simulink模块的输入),flag是仿真过程中的状态标志(以它来判断当前是初始化还是运行等)

Simulink home thermal system as an AC

断了今生、忘了曾经 提交于 2020-01-16 19:44:38
问题 I'm trying to modify this thermal system of a house to make it for an AC instead of a heater. The page says that if I want to modify it I need to add the cold air input part and edit the thermostat. I managed to fix the thermostat and now I can get the status as 1 when the AC is on (temperature drops) and 0 when it's off (temperature rises). How do I flip the heat transfer equations to get the cold air gain instead of the heat gain. They are using some equations in the link, is it okay to use

how to detect 2nd crossing to point simulink

ⅰ亾dé卋堺 提交于 2020-01-16 09:35:28
问题 How to detect the 2nd falling crossing when it reaches the 2nd point. The signal will rise again after the 2nd crossing and then repeats. Each time the signal falls at 20(2nd time) i want to capture it via relational block like the output signal in the image Input Signal: Model: Output 回答1: There are multiple ways this could be done. One approach is to create a triggered counter, using a Triggered Subsystem, with the counter resetting itself if the count tries to go above 2 . An example of

Simulink: Perform math operations with multilevel bus signals

被刻印的时光 ゝ 提交于 2020-01-16 04:11:27
问题 I am seeking a method to sum multilevel bus signals at the lowest level within their hierarchy without loss of the bus signal structure. MWE For example, in the MWE below, the bus signal is summed at the lowest level automatically, however, the bus signal is lost after passing through the Add block. A vector signal is produced instead. I would have preferred a method which yields: red + blue = purple or more specifically: red.[a b c].[1 2] + blue.[a b c].[1 2] --> purple.[a b c].[1 2] where

Get Errors when running Simulink block, but get Success when running respective M-file alone

随声附和 提交于 2020-01-15 19:16:51
问题 I would like to transmit an encoded image using USRP. The first step is to load the image using Matlab and encode it. The respective codes are shown as follows. function msg = genMsg1 %#codegen persistent msgStrSet count; if isempty(msgStrSet) count = 0; msgStrSet = imread('cameraman.tif'); % Load the image of cameraman.tif end msgtemp = dec2bin(msgStrSet); % Covert msgStrSet into binary value msg_1ine = msgtemp(count+1,:).'; % Take msgtemp line by line and tranpose it msg = str2num(msg_1ine)

Get Errors when running Simulink block, but get Success when running respective M-file alone

青春壹個敷衍的年華 提交于 2020-01-15 19:16:14
问题 I would like to transmit an encoded image using USRP. The first step is to load the image using Matlab and encode it. The respective codes are shown as follows. function msg = genMsg1 %#codegen persistent msgStrSet count; if isempty(msgStrSet) count = 0; msgStrSet = imread('cameraman.tif'); % Load the image of cameraman.tif end msgtemp = dec2bin(msgStrSet); % Covert msgStrSet into binary value msg_1ine = msgtemp(count+1,:).'; % Take msgtemp line by line and tranpose it msg = str2num(msg_1ine)

MATLAB / SIMULINK: Simulate filling and emptying of a river

喜你入骨 提交于 2020-01-15 10:27:08
问题 Background: A river has a non-constant cross-section. Under standard conditions, the water level amounts h_Std (see figure below). As it begins to rain, the water level rises until it is equal to h_Rain (see figure below) After the rain stops, the water level decreases back to the standard water level. As one can see from the diagrams, the relation between water level and volume is non-constant. However, the function can be desribed mathematically and is known for my particular cross-section

How does Simulink simulation engine work?

▼魔方 西西 提交于 2020-01-14 07:39:09
问题 I would like to understand how Simulink simulation engine works. Does it use a discrete event simulation mecanism (then how continous time is handled ?) ? Does it rely on a static cycle-based code generation ? Or ? 回答1: Before the first cycle, it figures out the order of execution of the blocks (starting with the ones that don't require inputs from any other blocks) Each cycle, it calculates the output of each block based on the inputs and the block's code. Each block's code is static, it

Convert first order transfer function to c code [closed]

谁说我不能喝 提交于 2020-01-14 06:08:25
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have a simple first order transfer such as "3/s+3" or "tf(3,[1 3])" function and I would like to implement in c code. I have a C function that is called with the delta time since the last iteration: double

Matlab Parallel Computing with Simulink Model

那年仲夏 提交于 2020-01-13 06:31:27
问题 I'm working on a project in which parallel computing would be a huge advantage. The project simulates multiple Simulink models. I did the simulation with a normal for-Loop, but since it takes days to simulate I decided to try the "parfor"-Loop . But that's where the problem begins. First I'll give you pictures of my code, the workspace and the Simulink-part which is causing me problems: Here's my code: apool = gcp('nocreate'); if isempty(apool) apool = parpool('local'); end wpath = pwd;