現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)