이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
ressistors with small random offset in SIMULINK
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello , I want to have 10 resistors with a littles offset in resistance by random number arounk 1kohm
i have itried to use matlab simuling VAriable ressistor.
But i dont see how i enter there some random offset in the value.
Thanks.
댓글 수: 11
Walter Roberson
2020년 5월 27일
Under what circumstances should the random resistance change? For example can it be chosen once at the beginning of the run and will hold for the duration of the run? Or should it change (say) after every 3 seconds? Or do you want it to be different "every time" it is used (if so are you using continuous or discrete?) Or are you trying to model increased resistance as temperatures increase as the circuit gets warmer?
Walter Roberson
2020년 5월 28일
Use a MATLAB function that does set_param() to modify the resistances .
fima v
2020년 5월 28일
Hello walter,If i have 10 ressistors each one is 10Kohm,this is how i imagine it in matlab code.
in the matlab simulink using set_param(), how can i implement it?
Thanks.
R_basic=10000*ones(10);
R_random=R_basic+randn(1,10);
Walter Roberson
2020년 5월 28일
That should be ones(1,10);
I am having difficulty figuring out which block you are looking at. The blocks I find with similar descriptions do not have the same icon, but the icon can be important as it gives information about which Domain you are working with. The PS on the icon hints to me you might be using Specialized Power Systems (SPS), but the discussion I find for variable resistors for SPS use quite a different approach.
fima v
2020년 5월 28일
Hello walter,could you give me a resistor model where there is such option can be done?
Thanks.
Walter Roberson
2020년 5월 28일
Which Domain are you using? Are you using pure Simulink? Simscape Electrical? Specialized Power Systems?
Walter Roberson
2020년 5월 28일
Walter Roberson
2020년 5월 28일
I am having difficulty finding resistors in pure simulink. I find resistors in
- RF Blockset
- Simscape Electrical
- Specialized Power Systems
fima v
2020년 5월 28일
Hello Wolter , i am not sure regarding what exact simulink i am using, ithink i have here RF blockset.
could you please say on this platform how to define random argument in the resistor value?
Thanks.
채택된 답변
Walter Roberson
2020년 5월 29일
편집: Walter Roberson
2020년 5월 29일
The attached model is adapted (solver parameters updated) from the File Exchange Contribution
It happens to have 11 resistors from Specialized Power Systems (part of Simscape Electrical)
The resistances can be randomized using
for K = 1 : 11
pn = sprintf('SERIES_PARALLEL_RESISTORS/R_%d', K);
set_param(pn, 'Resistance', sprintf('%.5g', 1000 + randn(1)));
end
Here, SERIES_PARALLEL_RESISTORS is the model name, and each of the resistors happened to be named R_ followed by a number. Resistance is the name of the parameter used in SPS for resistance (some of the other forms of resistor in Simulink use 'R' as the name for the resistance.)
It was saved with R2020a (you did not indicate which version you are using.)
댓글 수: 20
fima v
2020년 5월 29일
Hello Walter i am using 2019a, from the code bellow i recognise that you write into a file.
What should i do in order to see those resistors physicly on simulink?
Thanks.
Walter Roberson
2020년 5월 29일
Model for R2019a attached.
modname = 'SERIES_PARALLEL_RESISTORS19a'
open_system(modname);
for K = 1 : 11
pn = sprintf('%s/R_%d', modname, K);
set_param(pn, 'Resistance', sprintf('%.5g', 1000 + randn(1)));
end
If you know double-click on R_1 in the model, you will see that it has a resistance parameter that is not exactly 1000.
That loop is not writing into a file: it is adjusting the parameters of the loaded model. If you were to run the loop part if it again and then look at R_1 again you will see a different resistance.
fima v
2020년 5월 30일
Hello Walter, i am not used to running code in parralel with simulink.
in simulink i know to grab blocks and make circuit out of it.
Where shoud i put this code in simulink?
I am having problem to immagine the procedure, assuming i run this code with this file in regular matlab window.
Then i enter simulink, what to do next in the simulink window to have 10 resistor of random values?
Thanks.
Walter Roberson
2020년 5월 30일
Easiest way: instead of using Simulink to Run the model, instead, In a MATLAB script (or function)
modname = 'SERIES_PARALLEL_RESISTORS19a'
open_system(modname);
for K = 1 : 11
pn = sprintf('%s/R_%d', modname, K);
set_param(pn, 'Resistance', sprintf('%.5g', 1000 + randn(1)));
end
sim(modname);
But it is also possible to set something up that will run in Simulink. I was not able to figure out how to set up the proper callbacks using the GUI, so once you have created the model, once do the following at the command line:
modname = 'SERIES_PARALLEL_RESISTORS19a'
open_system(modname);
for K = 1 : 11; set_param(sprintf('%s/R_%d', modname, K), 'InitFcn', 'set(gcbh, ''Resistance'', string(1000+randn()))'); end
Now you can save the model at the Simulink level.
Once the above is done, each time you Run the model in Simulink, each of the resistors will run initialization code that sets its resistance randomly.
You can of course change the formula 1000+randn() to whatever is appropriate for your purposes.
The same technique can be used with resistors from other domains such as RF Blocksets, but you may need to change the name of the parameter from Resistance to R
fima v
2020년 5월 31일
Hello Walter, I need to do this trick for DC voltage source create 10 DC souces with 0.5+0.1*rand(1) in them
and i need to have both of my random resistor and random DC voltage sources together so i will build something combined.
Should i use the same file?
what should i do to add 10 random DC voltage sources to it?
Thanks.
Walter Roberson
2020년 5월 31일
I added some DC Voltage Source. I deliberately renamed them to have DCV_ names to make it easier.
So the procedure is to add your resistors and voltages sources to your simulink model, then run code similar to the below:
modname = 'SERIES_PARALLEL_RESISTORS_NoVoltage_19a'
open_system(modname);
for K = 1 : 11; set_param(sprintf('%s/R_%d', modname, K), 'InitFcn', 'set(gcbh, ''Resistance'', string(1000+randn()))'); end
for K = 1 : 3; set_param(sprintf('%s/DCV_%d', modname, K), 'InitFcn', 'set(gcbh, ''Amplitude'', string(0.5+0.1*randn()))'); end
then save the model. After that, each time your Run the model, the voltages and resistances will be randomized.
Walter Roberson
2020년 6월 1일
편집: Walter Roberson
2020년 6월 1일
Are you really going to create and route 255 or 510 components by hand in the graphical interface? It would probably be easier to add by way of program, provided that you had an algorithm for which is connected to which.
fima v
2020년 6월 1일
Hello Walter, I need to do an 8 bit converter 2^8-1=256-1.
So is there some method you can recomend me where i could drag and drop a component an it will randomly puld a value as you implemented?
Thanks.
Walter Roberson
2020년 6월 1일
An 8 bit converter? As in a resistance ladder to determine an input voltage?
fima v
2020년 6월 2일
Hello Walter, yes to conver analog to digital signal .but i need voltage and resistor variance(not idial components
i have found in the following manual tolerance option for the resistor.
But for DC source i coudnt find such component with tollerance.
Walter Roberson
2020년 6월 2일
what is your diagram? The architectures that I find for flash ADC ("thermometer style") use only one voltage source.
fima v
2020년 6월 2일
편집: fima v
2020년 6월 2일
Hello Walter, Yes thats the idial model, the non idial model uses
resistor offset and comparator voltage offset.
in a component named "resistor" i have found an option called "tolerance" which exactly does what we need.
but i dont have any component the does "tollerance with voltage source"
I wish i knew how you did those 10 random voltage sources so i could do a version of 256 of those.
Could you please tell me a method how to accomplish such thing?
Thanks.
Walter Roberson
2020년 6월 2일
I posted the exact code that I used for the randomization.
I started from Chaitanya Jambotkar's existing model just to have something with resistors in it to work with.
Here is some example code that creates and positions DC Voltage Sources and Resistors automatically, and configures them to initialize their parameters randomly at run time. It also shows automatically connecting the output of a DC Voltage to the input of a Resistor.
I did not attempt to build the flash ADC for you; I am just giving you the tools to proceed with.
modname = 'test_model';
N_voltage_sources = 15;
N_resistor = 15;
SL_powergui_block = 'powerlib/powergui';
SL_DCV_block = 'powerlib/Electrical Sources/DC Voltage Source';
SL_resistor_block = 'powerlib/Elements/Series RLC Branch';
DCV_xbase = 50;
DCV_ybase = -150; %yes, negative!
DCV_width = 20;
DCV_height = 35;
DCV_yspacing = 75;
R_xbase = 125;
R_ybase = DCV_ybase;
R_width = 80;
R_height = 35;
R_yspacing = DCV_yspacing;
modfile = sprintf('%s.slx', modname);
if exist(modfile, 'file'); delete(modfile); end
try
h = new_system(modname);
catch
Simulink.BlockDiagram.deleteContents(modname);
end
add_block(SL_powergui_block, sprintf('%s/powergui', modname)); %required solver component
DCV_blocknames = cell(N_voltage_sources, 1);
DCV_ports = cell(N_voltage_sources, 1);
R_blocknames = cell(N_resistor, 1);
R_ports = cell(N_resistor, 1);
xbase = DCV_xbase;
xend = xbase + DCV_width - 1;
for K = 1 : N_voltage_sources
ybase = DCV_ybase + (K-1)*DCV_yspacing;
yend = ybase + DCV_height;
blockname = sprintf('%s/DCV_%d', modname, K);
DCV_blocknames{K} = blockname;
add_block(SL_DCV_block, blockname, ...
'Position', [xbase, ybase, xend, yend], ...
'InitFcn', 'set(gcbh, ''Amplitude'', string(0.5+0.1*randn()))' );
DCV_ports{K} = get_param(blockname, 'PortHandles');
end
xbase = R_xbase;
xend = xbase + R_width - 1;
for K = 1 : N_resistor
ybase = R_ybase + (K-1)*R_yspacing;
yend = ybase + R_height;
blockname = sprintf('%s/R_%d', modname, K);
R_blocknames{K} = blockname;
add_block(SL_resistor_block, blockname, 'BranchType', 'R', ...
'Position', [xbase, ybase, xend, yend], ...
'InitFcn', 'set(gcbh, ''Resistance'', string(1000+randn()))');
R_ports{K} = get_param(blockname, 'PortHandles');
end
for K = 1 : N_voltage_sources
add_line(modname, DCV_ports{K}.RConn, R_ports{K}.LConn);
end
save_system(modname);
open_system(modname);
fima v
2020년 6월 3일
Hello Walter, The code generated me 255 resistors and 255 voltage sources but they all have the same value.
I have tried to make them with random values by putting 1 inside the randn as shown bellow, still it gives me a constant value in all of them.
Where did i go wrong?
Thanks.
'InitFcn', 'set(gcbh, ''Amplitude'', string(0.5+0.1*randn(1)))' );
'InitFcn', 'set(gcbh, ''Resistance'', string(1000+randn(1)))');
Walter Roberson
2020년 6월 3일
For reasons I do not currently understand, when the model is saved, InitFcn is being cleared.
The model will work correctly if you use it when it pops up (the open_system), but not if you close that and load it from disk.
This will require further investigation.
fima v
2020년 6월 3일
편집: fima v
2020년 6월 3일
Hello Walter, it works great. unfortunetly when i tried to connect SIMSCAPE opamp(to act as comparator) and a scope to see DC output. these componets do not connect to each other. i tried to use a ps-simulink converter as shown in the link post bellow. and still i could not connect them together
Where did i go wrong?
Thanks.
Walter Roberson
2020년 6월 5일
I extended the code to show adding Voltage Measurements, Current Measurements, and Scopes.
The positioning of the Voltage Measurements and Current Measurements, and Scope,could use some improvement -- I positioned them too closely together, so the connecting lines do not show up well.
I have not worked out Op Amps yet. Do you actually want Op Amps, or do you want comparitors? What should the output be for the case where the comparison succeeds?
modname = 'test_model';
N_voltage_sources = 15;
N_resistor = 15;
N_scopes = 1;
N_VM = 1;
N_CM = 1;
SL_powergui_block = 'powerlib/powergui';
SL_DCV_block = 'powerlib/Electrical Sources/DC Voltage Source';
SL_resistor_block = 'powerlib/Elements/Series RLC Branch';
SL_VM_block = 'powerlib/Measurements/Voltage Measurement';
SL_CM_block = 'powerlib/Measurements/Current Measurement';
SL_Scope_block = 'simulink/Sinks/Scope';
DCV_xbase = 50;
DCV_ybase = -150; %yes, negative!
DCV_width = 20;
DCV_height = 35;
DCV_yspacing = 75;
R_xbase = 125;
R_ybase = DCV_ybase;
R_width = 80;
R_height = 35;
R_yspacing = DCV_yspacing;
modfile = sprintf('%s.slx', modname);
if exist(modfile, 'file'); delete(modfile); end
try
h = new_system(modname);
catch
Simulink.BlockDiagram.deleteContents(modname);
end
add_block(SL_powergui_block, sprintf('%s/powergui', modname)); %required solver component
DCV_blocknames = cell(N_voltage_sources, 1);
DCV_ports = cell(N_voltage_sources, 1);
R_blocknames = cell(N_resistor, 1);
R_ports = cell(N_resistor, 1);
VM_blocknames = cell(N_VM, 1);
VM_ports = cell(N_VM, 1);
CM_blocknames = cell(N_CM, 1);
CM_ports = cell(N_CM, 1);
Scope_blocknames = cell(N_scopes, 1);
Scope_ports = cell(N_scopes, 1);
xbase = DCV_xbase;
xend = xbase + DCV_width - 1;
for K = 1 : N_voltage_sources
ybase = DCV_ybase + (K-1)*DCV_yspacing;
yend = ybase + DCV_height;
blockname = sprintf('%s/DCV_%d', modname, K);
DCV_blocknames{K} = blockname;
add_block(SL_DCV_block, blockname, ...
'Position', [xbase, ybase, xend, yend], ...
'InitFcn', 'set(gcbh, ''Amplitude'', string(0.5+0.1*randn()))' );
DCV_ports{K} = get_param(blockname, 'PortHandles'); %- (L) || + (R)
end
xbase = DCV_xbase + 50;
xend = xbase + R_width - 1;
for K = 1 : N_resistor
ybase = R_ybase + (K-1)*R_yspacing;
yend = ybase + R_height;
blockname = sprintf('%s/R_%d', modname, K);
R_blocknames{K} = blockname;
add_block(SL_resistor_block, blockname, 'BranchType', 'R', ...
'Position', [xbase, ybase, xend, yend], ...
'InitFcn', 'set(gcbh, ''Resistance'', string(1000+randn()))');
R_ports{K} = get_param(blockname, 'PortHandles'); %L || R
end
xbase = R_xbase + 50;
for K = 1 : N_VM
ybase = R_ybase + (K-1)*R_yspacing;
yend = ybase + R_height;
blockname = sprintf('%s/VM_%d', modname, K);
VM_blocknames{K} = blockname;
add_block(SL_VM_block, blockname, ...
'Position', [xbase, ybase, xbase + 35, yend]);
VM_ports{K} = get_param(blockname, 'PortHandles'); % + - || outport
end
xbase = R_xbase + 100;
for K = 1 : N_CM
ybase = DCV_ybase + (K-1)*R_yspacing;
yend = ybase + R_height;
blockname = sprintf('%s/CM_%d', modname, K);
CM_blocknames{K} = blockname;
add_block(SL_CM_block, blockname, ...
'Position', [xbase, ybase, xbase+35, yend]); % + || outport -
CM_ports{K} = get_param(blockname, 'PortHandles');
end
xbase = R_xbase + 150;
for K = 1 : N_scopes
ybase = DCV_ybase + (K-1)*R_yspacing;
yend = ybase + R_height;
blockname = sprintf('%s/Scope_%d', modname, K);
Scope_blocknames{K} = blockname;
add_block(SL_Scope_block, blockname, ...
'Position', [xbase, ybase, xbase + 35, yend], ...
'NumInputPorts', '2');
Scope_ports{K} = get_param(blockname, 'PortHandles');
end
for K = 1 : N_voltage_sources
add_line(modname, DCV_ports{K}.RConn, R_ports{K}.LConn);
end
add_line(modname, R_ports{1}.RConn, VM_ports{1}.LConn(1));
add_line(modname, VM_ports{1}.LConn(2), CM_ports{1}.LConn);
add_line(modname, CM_ports{1}.RConn, DCV_ports{1}.LConn);
add_line(modname, VM_ports{1}.Outport, Scope_ports{1}.Inport(1));
add_line(modname, CM_ports{1}.Outport, Scope_ports{1}.Inport(2));
save_system(modname);
fima v
2020년 6월 5일
편집: fima v
2020년 6월 5일
Hello Walter, My comperator needs to have input noise 10nV/sqrt(Hz), bandwidth(100MHZ) ,amplitude(200) , the theshhold of the comperator is 0.6v.
VDD=1V VCC=0V .
so if for example (V_plus-V_minus)*Amplitude>0.6 the output is 1V else 0V.
I have tried to used the simscape bandlimited component to achieve those properties.
but then i couldnt connect with the other components as shown above.
If you could make N such comparators , it would be great.
Thanks you very much.
Walter Roberson
2020년 6월 8일
There does not appear to be any one block to implement what you describe. See however https://www.mathworks.com/help/physmod/sps/examples/op-amp-with-noise.html
추가 답변 (1개)
Fangjun Jiang
2020년 5월 27일
편집: Fangjun Jiang
2020년 5월 28일
This "Variable Resistor" is not the right one to use. This "Variable Resistor" represents a physical variable resistor in the lab where you can move a handle or turn a knob to adjust the value of the resistor. The "PS" port of this block can be connect to a motor (for example) to move the handle or turn the knob thus change the resistor.
To implement what you want, you just need to set "R=10e3-10+20*rand(10,1)" in workspace and drop 10 regular resistor blocks in your model, set the parameter for the first resistor to be R(1), ... and the last one to be R(10).
댓글 수: 1
fima v
2020년 5월 28일
could you please show a print screen of "R=10e3-10+20*rand(10,1) in workspace"?
and drop 10 resistors.i am having trouble visualise it.
Thabks.
참고 항목
카테고리
Help Center 및 File Exchange에서 Detect and Diagnose Faults에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)