Difference between revisions of "Scilab/C4/Calling-User-Defined-Functions-in-XCOS/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) (Created page with '{| Border=1 || Time || Narration |- | 00.01 | Welcome to the spoken tutorial on ''' “Calling user-defined functions in Xcos”''' |- | 00.07 | In this tutorial we will le…') |
|||
Line 1: | Line 1: | ||
{| Border=1 | {| Border=1 | ||
− | | | + | |'''Time''' |
− | + | ||
− | + | ||
+ | |'''Narration''' | ||
|- | |- | ||
− | | 00 | + | | 00:01 |
| Welcome to the spoken tutorial on ''' “Calling user-defined functions in Xcos”''' | | Welcome to the spoken tutorial on ''' “Calling user-defined functions in Xcos”''' | ||
|- | |- | ||
− | | 00 | + | | 00:07 |
| In this tutorial we will learn, | | In this tutorial we will learn, | ||
|- | |- | ||
− | |00 | + | |00:09 |
|To write a squaring function in '''Scilab''' | |To write a squaring function in '''Scilab''' | ||
|- | |- | ||
− | |00 | + | |00:12 |
|To use the ''' scifunc''' block in ''' Xcos''' | |To use the ''' scifunc''' block in ''' Xcos''' | ||
|- | |- | ||
− | | 00 | + | | 00:15 |
| To use MUX block to draw multiple plots | | To use MUX block to draw multiple plots | ||
|- | |- | ||
− | |00 | + | |00:19 |
|To call functions having multiple inputs and outputs | |To call functions having multiple inputs and outputs | ||
|- | |- | ||
− | | 00 | + | | 00:24 |
|''' Ubuntu''' 12.04 is the ''' operating system''' used with '''Scilab version 5.3.3 installed.''' | |''' Ubuntu''' 12.04 is the ''' operating system''' used with '''Scilab version 5.3.3 installed.''' | ||
|- | |- | ||
− | | 00 | + | | 00:32 |
| You should have Basic knowledge of ''' Scilab''' | | You should have Basic knowledge of ''' Scilab''' | ||
|- | |- | ||
− | |00 | + | |00:35 |
|Basic knowledge of ''' Xcos''' | |Basic knowledge of ''' Xcos''' | ||
|- | |- | ||
− | | 00 | + | | 00:38 |
| If not, for relevant tutorials please visit ''' spoken hyphen tutorial dot org''' | | If not, for relevant tutorials please visit ''' spoken hyphen tutorial dot org''' | ||
|- | |- | ||
− | | 00 | + | | 00:44 |
| Start ''' Scilab''' on your computer. | | Start ''' Scilab''' on your computer. | ||
|- | |- | ||
− | |00 | + | |00:47 |
|In the ''' Scilab''' console, type ''' editor''' and press ''' Enter''' | |In the ''' Scilab''' console, type ''' editor''' and press ''' Enter''' | ||
Line 60: | Line 59: | ||
|- | |- | ||
− | |00 | + | |00:53 |
|Then type the following code | |Then type the following code | ||
|- | |- | ||
− | |00 | + | |00:55 |
|function space ''' y ''' is equal to squareit open bracket a close bracket | |function space ''' y ''' is equal to squareit open bracket a close bracket | ||
Line 71: | Line 70: | ||
|- | |- | ||
− | |01 | + | |01:07 |
|Press the enter key and type | |Press the enter key and type | ||
Line 77: | Line 76: | ||
|- | |- | ||
− | |01 | + | |01:10 |
|''' y''' is equal to '''a''' raise to 2 | |''' y''' is equal to '''a''' raise to 2 | ||
Line 83: | Line 82: | ||
|- | |- | ||
− | | 01 | + | | 01:14 |
|put a semicolon in the end | |put a semicolon in the end | ||
Line 90: | Line 89: | ||
|- | |- | ||
− | | 01 | + | | 01:17 |
|The function has one input variable ''' a''' and one output variable ''' y ''' | |The function has one input variable ''' a''' and one output variable ''' y ''' | ||
|- | |- | ||
− | |01 | + | |01:24 |
|The name of the function is ''' squareit ''' | |The name of the function is ''' squareit ''' | ||
Line 101: | Line 100: | ||
|- | |- | ||
− | |01 | + | |01:27 |
|This function will do the job of squaring the variable ''' a.''' | |This function will do the job of squaring the variable ''' a.''' | ||
|- | |- | ||
− | |01 | + | |01:31 |
|It will store the result in ''' y.''' | |It will store the result in ''' y.''' | ||
Line 113: | Line 112: | ||
|- | |- | ||
− | |01 | + | |01:34 |
|Let us save this file in the desired directory. | |Let us save this file in the desired directory. | ||
Line 120: | Line 119: | ||
|- | |- | ||
− | |01 | + | |01:38 |
|I will save this file with file name ''' squareit''' and extension ''' .sci ''' | |I will save this file with file name ''' squareit''' and extension ''' .sci ''' | ||
|- | |- | ||
− | | 01 | + | | 01:44 |
|Here we are following the convention of saving functions in '''.sci''' format. | |Here we are following the convention of saving functions in '''.sci''' format. | ||
|- | |- | ||
− | |01 | + | |01:50 |
|Switch to the ''' Scilab''' console | |Switch to the ''' Scilab''' console | ||
Line 136: | Line 135: | ||
|- | |- | ||
− | |01 | + | |01:53 |
| Now, type ''' Xcos''' and press '''Enter.''' | | Now, type ''' Xcos''' and press '''Enter.''' | ||
Line 142: | Line 141: | ||
|- | |- | ||
− | |01 | + | |01:57 |
|Two windows will open | |Two windows will open | ||
Line 148: | Line 147: | ||
|- | |- | ||
− | | 01 | + | | 01:59 |
|A ''' palette browser''' and an '''untitled Xcos''' window. | |A ''' palette browser''' and an '''untitled Xcos''' window. | ||
Line 154: | Line 153: | ||
|- | |- | ||
− | | 02 | + | | 02:04 |
|Now we will make the ''' Xcos''' diagram. | |Now we will make the ''' Xcos''' diagram. | ||
|- | |- | ||
− | |02 | + | |02:06 |
| This will access the function '''squareit''' created just now. | | This will access the function '''squareit''' created just now. | ||
|- | |- | ||
− | |02 | + | |02:10 |
| This can be done by using '''scifunc''' block. | | This can be done by using '''scifunc''' block. | ||
|- | |- | ||
− | | 02 | + | | 02:14 |
|Switch to the ''' palette browser''' window | |Switch to the ''' palette browser''' window | ||
|- | |- | ||
− | | 02 | + | | 02:17 |
|Click on the ''' User-Defined''' function in the pallet browser. | |Click on the ''' User-Defined''' function in the pallet browser. | ||
Line 179: | Line 178: | ||
|- | |- | ||
− | | 02 | + | | 02:21 |
|Locate the block '''scifunc_block_m''' in this section. | |Locate the block '''scifunc_block_m''' in this section. | ||
|- | |- | ||
− | | 02 | + | | 02:27 |
|Drag and drop it in '''untitled Xcos''' window. | |Drag and drop it in '''untitled Xcos''' window. | ||
|- | |- | ||
− | |02 | + | |02:32 |
|I will zoom the untitled Xcos window for better view. | |I will zoom the untitled Xcos window for better view. | ||
|- | |- | ||
− | | 02 | + | | 02:36 |
|I will use the Zoom button as you see. | |I will use the Zoom button as you see. | ||
Line 198: | Line 197: | ||
|- | |- | ||
− | | 02 | + | | 02:40 |
|Now double click on the '''scifunc''' block to configure it. | |Now double click on the '''scifunc''' block to configure it. | ||
Line 205: | Line 204: | ||
|- | |- | ||
− | |02 | + | |02:44 |
|A window named ''' Scilab multiple values request''' will open | |A window named ''' Scilab multiple values request''' will open | ||
Line 211: | Line 210: | ||
|- | |- | ||
− | | 02 | + | | 02:49 |
| This window will allow you to change the number of input and output ports of the '''scifunc''' block. | | This window will allow you to change the number of input and output ports of the '''scifunc''' block. | ||
|- | |- | ||
− | | 02 | + | | 02:56 |
|Our function '''squareit''' has only one input and output variable. | |Our function '''squareit''' has only one input and output variable. | ||
Line 223: | Line 222: | ||
|- | |- | ||
− | | 03 | + | | 03:00 |
| 'Hence, we will keep the settings unchanged. | | 'Hence, we will keep the settings unchanged. | ||
Line 229: | Line 228: | ||
|- | |- | ||
− | | 03 | + | | 03:03 |
| Click on Ok. | | Click on Ok. | ||
Line 235: | Line 234: | ||
|- | |- | ||
− | |03 | + | |03:05 |
||A new '''Scilab input value request''' window will open. | ||A new '''Scilab input value request''' window will open. | ||
Line 242: | Line 241: | ||
|- | |- | ||
− | |03 | + | |03:09 |
|In the text box, type the function name along with input and output variables. | |In the text box, type the function name along with input and output variables. | ||
|- | |- | ||
− | | 03 | + | | 03:14 |
|This function will be called by the scifunc block | |This function will be called by the scifunc block | ||
Line 255: | Line 254: | ||
|- | |- | ||
− | | 03 | + | | 03:18 |
|In the text box available, | |In the text box available, | ||
Line 262: | Line 261: | ||
|- | |- | ||
− | | 03 | + | | 03:20 |
|edit the default function name. | |edit the default function name. | ||
Line 268: | Line 267: | ||
|- | |- | ||
− | | 03 | + | | 03:22 |
|Type '''y1''' equal to '''squareit''' open bracket '''u1''' close the bracket | |Type '''y1''' equal to '''squareit''' open bracket '''u1''' close the bracket | ||
Line 274: | Line 273: | ||
|- | |- | ||
− | | 03 | + | | 03:31 |
|Note that, here the input and output variables are '''u1''' and '''y1''' respectively. | |Note that, here the input and output variables are '''u1''' and '''y1''' respectively. | ||
Line 281: | Line 280: | ||
|- | |- | ||
− | | 03 | + | | 03:37 |
|These should be strictly in '''u''' and '''y''' form and not as per the variable names used in the actual function. | |These should be strictly in '''u''' and '''y''' form and not as per the variable names used in the actual function. | ||
Line 288: | Line 287: | ||
|- | |- | ||
− | | 03 | + | | 03:45 |
|Cick on '''OK.''' | |Cick on '''OK.''' | ||
Line 294: | Line 293: | ||
|- | |- | ||
− | | 03 | + | | 03:47 |
|Another '''Scilab input value request''' window will open. | |Another '''Scilab input value request''' window will open. | ||
Line 300: | Line 299: | ||
|- | |- | ||
− | | 03 | + | | 03:51 |
|Keep clicking on '''Ok''' in the subsequent 3 windows that will appear. | |Keep clicking on '''Ok''' in the subsequent 3 windows that will appear. | ||
Line 307: | Line 306: | ||
|- | |- | ||
− | |03 | + | |03:56 |
|The '''scifunc''' block is now configured. | |The '''scifunc''' block is now configured. | ||
Line 314: | Line 313: | ||
|- | |- | ||
− | | 04 | + | | 04:00 |
|Next we will include a '''sinusoid''' generator block. | |Next we will include a '''sinusoid''' generator block. | ||
Line 320: | Line 319: | ||
|- | |- | ||
− | | 04 | + | | 04:04 |
| In the '''palette browser''' window, click on '''Sources section. ''' | | In the '''palette browser''' window, click on '''Sources section. ''' | ||
Line 327: | Line 326: | ||
|- | |- | ||
− | | 04 | + | | 04:08 |
|Drag and drop the '''Sinusoid Generator''' block in '''untitled Xcos''' window. | |Drag and drop the '''Sinusoid Generator''' block in '''untitled Xcos''' window. | ||
Line 333: | Line 332: | ||
|- | |- | ||
− | | 04 | + | | 04:14 |
|Place the block towards the left of the '''scifunc''' block for convenience. | |Place the block towards the left of the '''scifunc''' block for convenience. | ||
|- | |- | ||
− | | 04 | + | | 04:20 |
| Now we need a block to plot the output variable. | | Now we need a block to plot the output variable. | ||
|- | |- | ||
− | | 04 | + | | 04:23 |
|'In the '''palette browser window,''' click on '''Sinks''' section. | |'In the '''palette browser window,''' click on '''Sinks''' section. | ||
|- | |- | ||
− | | 04 | + | | 04:29 |
|Drag and drop the '''CScope''' block in the '''untitled Xcos''' window. | |Drag and drop the '''CScope''' block in the '''untitled Xcos''' window. | ||
Line 354: | Line 353: | ||
|- | |- | ||
− | | 04 | + | | 04:34 |
| Place the block towards the right of the '''scifunc''' block | | Place the block towards the right of the '''scifunc''' block | ||
Line 362: | Line 361: | ||
|- | |- | ||
− | | 04 | + | | 04:38 |
| Place it away from scifunc block, for convenience. | | Place it away from scifunc block, for convenience. | ||
Line 369: | Line 368: | ||
|- | |- | ||
− | | 04 | + | | 04:43 |
|Notice that the '''CScope''' block has a red input port. | |Notice that the '''CScope''' block has a red input port. | ||
Line 375: | Line 374: | ||
|- | |- | ||
− | | 04 | + | | 04:47 |
| This is an event input | | This is an event input | ||
Line 382: | Line 381: | ||
|- | |- | ||
− | | 04 | + | | 04:49 |
|we need an event generator block. | |we need an event generator block. | ||
Line 389: | Line 388: | ||
|- | |- | ||
− | | 04 | + | | 04:52 |
|In the ''' palette browser window,''' click on '''Sources''' section. | |In the ''' palette browser window,''' click on '''Sources''' section. | ||
Line 396: | Line 395: | ||
|- | |- | ||
− | | 04 | + | | 04:57 |
|Drag and drop the clock underscore c block in the '''untitled Xcos''' window. | |Drag and drop the clock underscore c block in the '''untitled Xcos''' window. | ||
Line 402: | Line 401: | ||
|- | |- | ||
− | | 05 | + | | 05:05 |
|Place it above the '''CScope''' block. | |Place it above the '''CScope''' block. | ||
Line 408: | Line 407: | ||
|- | |- | ||
− | | 05 | + | | 05:08 |
|Notice that the '''CScope''' block has only one input port. | |Notice that the '''CScope''' block has only one input port. | ||
Line 414: | Line 413: | ||
|- | |- | ||
− | | 05 | + | | 05:13 |
|But we want to plot both the input and output variables in a single plot window. | |But we want to plot both the input and output variables in a single plot window. | ||
Line 420: | Line 419: | ||
|- | |- | ||
− | | 05 | + | | 05:18 |
|Hence, we need a multiplexer block, | |Hence, we need a multiplexer block, | ||
Line 426: | Line 425: | ||
|- | |- | ||
− | | 05 | + | | 05:22 |
|This block will multiplex two inputs and generate output on one output port. | |This block will multiplex two inputs and generate output on one output port. | ||
Line 434: | Line 433: | ||
|- | |- | ||
− | | 05 | + | | 05:28 |
|In the ''' palette browser window,''' click on '''Signal Routing''' section. | |In the ''' palette browser window,''' click on '''Signal Routing''' section. | ||
Line 440: | Line 439: | ||
|- | |- | ||
− | | 05 | + | | 05:33 |
|Drag and drop the '''MUX''' block in the '''untitled Xcos''' window. | |Drag and drop the '''MUX''' block in the '''untitled Xcos''' window. | ||
Line 447: | Line 446: | ||
|- | |- | ||
− | | 05 | + | | 05:39 |
|Place the block between the '''scifunc''' block and '''CScope''' block. | |Place the block between the '''scifunc''' block and '''CScope''' block. | ||
Line 453: | Line 452: | ||
|- | |- | ||
− | | 05 | + | | 05:43 |
|Let me resize and realign the '''Mux block''' | |Let me resize and realign the '''Mux block''' | ||
Line 459: | Line 458: | ||
|- | |- | ||
− | | 05 | + | | 05:47 |
|Now let us connect the blocks together. | |Now let us connect the blocks together. | ||
Line 466: | Line 465: | ||
|- | |- | ||
− | | 05 | + | | 05:51 |
|Connect the output port of '''Sinusoid generator''' block to the input port of '''scifunc''' block | |Connect the output port of '''Sinusoid generator''' block to the input port of '''scifunc''' block | ||
Line 474: | Line 473: | ||
|- | |- | ||
− | | 05 | + | | 05:57 |
|Now connect the output port of '''scifunc''' block to the lower input port of the '''MUX.''' | |Now connect the output port of '''scifunc''' block to the lower input port of the '''MUX.''' | ||
Line 480: | Line 479: | ||
|- | |- | ||
− | | 06 | + | | 06:04 |
|Connect the output port of '''MUX''' block to the input port of '''CScope''' block. | |Connect the output port of '''MUX''' block to the input port of '''CScope''' block. | ||
Line 486: | Line 485: | ||
|- | |- | ||
− | | 06 | + | | 06:10 |
|Connect the output port of clock underscore c block to the event input port of '''CScope''' block. | |Connect the output port of clock underscore c block to the event input port of '''CScope''' block. | ||
|- | |- | ||
− | | 06 | + | | 06:19 |
|We also have to plot '''sine''' input. | |We also have to plot '''sine''' input. | ||
Line 497: | Line 496: | ||
|- | |- | ||
− | | 06 | + | | 06:22 |
|We have to connect the '''Sinusoid generator''' block to the '''MUX.''' | |We have to connect the '''Sinusoid generator''' block to the '''MUX.''' | ||
Line 503: | Line 502: | ||
|- | |- | ||
− | | 06 | + | | 06:26 |
|Click on the upper input port of the '''MUX''' block. | |Click on the upper input port of the '''MUX''' block. | ||
Line 509: | Line 508: | ||
|- | |- | ||
− | | 06 | + | | 06:30 |
|Then without releasing, move your mouse pointer towards the link between the ''' Sinusoid generator''' block and '''scifunc''' block. | |Then without releasing, move your mouse pointer towards the link between the ''' Sinusoid generator''' block and '''scifunc''' block. | ||
Line 516: | Line 515: | ||
|- | |- | ||
− | | 06 | + | | 06:39 |
|To bend the link, release the mouse button or click at places | |To bend the link, release the mouse button or click at places | ||
Line 522: | Line 521: | ||
|- | |- | ||
− | | 06 | + | | 06:44 |
|As you bring the pointer on the link, the link turns green. | |As you bring the pointer on the link, the link turns green. | ||
Line 528: | Line 527: | ||
|- | |- | ||
− | | 06 | + | | 06:49 |
|Release the mouse button or click once to create a link between these two blocks. | |Release the mouse button or click once to create a link between these two blocks. | ||
Line 534: | Line 533: | ||
|- | |- | ||
− | | 06 | + | | 06:55 |
|Now let us see the configuration of other blocks | |Now let us see the configuration of other blocks | ||
Line 540: | Line 539: | ||
|- | |- | ||
− | | 06 | + | | 06:59 |
| We can change the '''frequency, magnitude''' and '''phase''' of the '''sinusoid generator''' block. | | We can change the '''frequency, magnitude''' and '''phase''' of the '''sinusoid generator''' block. | ||
Line 547: | Line 546: | ||
|- | |- | ||
− | | 07 | + | | 07:04 |
|To do this, double click on the '''Sinusoid''' generator block. | |To do this, double click on the '''Sinusoid''' generator block. | ||
Line 553: | Line 552: | ||
|- | |- | ||
− | | 07 | + | | 07:09 |
|The configuration window will open. | |The configuration window will open. | ||
Line 559: | Line 558: | ||
|- | |- | ||
− | | 07 | + | | 07:11 |
|We will keep the '''magnitude''' and '''frequency''' as 1 and ''' phase''' as 0 | |We will keep the '''magnitude''' and '''frequency''' as 1 and ''' phase''' as 0 | ||
Line 565: | Line 564: | ||
|- | |- | ||
− | | 07 | + | | 07:18 |
|Click on ''' Ok''' to close the configuration window. | |Click on ''' Ok''' to close the configuration window. | ||
Line 571: | Line 570: | ||
|- | |- | ||
− | | 07 | + | | 07:21 |
|Now let us configure the '''CScope''' block. | |Now let us configure the '''CScope''' block. | ||
Line 577: | Line 576: | ||
|- | |- | ||
− | | 07 | + | | 07:25 |
|Double click on the '''CScope''' block to open its configuration window. | |Double click on the '''CScope''' block to open its configuration window. | ||
Line 583: | Line 582: | ||
|- | |- | ||
− | | 07 | + | | 07:30 |
|Change the ''' Ymin''' parameter to minus 2 and '''Ymax''' parameter to 2 | |Change the ''' Ymin''' parameter to minus 2 and '''Ymax''' parameter to 2 | ||
Line 589: | Line 588: | ||
|- | |- | ||
− | | 07 | + | | 07:37 |
|Change the '''Refresh period''' value to 10. | |Change the '''Refresh period''' value to 10. | ||
Line 595: | Line 594: | ||
|- | |- | ||
− | | 07 | + | | 07:41 |
|Make a mental note of this value. | |Make a mental note of this value. | ||
Line 601: | Line 600: | ||
|- | |- | ||
− | | 07 | + | | 07:44 |
|Change the '''buffer size''' value to 2 . | |Change the '''buffer size''' value to 2 . | ||
Line 607: | Line 606: | ||
|- | |- | ||
− | | 07 | + | | 07:47 |
|click on '''OK''' | |click on '''OK''' | ||
Line 614: | Line 613: | ||
|- | |- | ||
− | | 07 | + | | 07:50 |
|Now let us configure the '''CLOCK_c''' block | |Now let us configure the '''CLOCK_c''' block | ||
Line 620: | Line 619: | ||
|- | |- | ||
− | | 07 | + | | 07:54 |
|Double click on the block to open its configuration window. | |Double click on the block to open its configuration window. | ||
Line 626: | Line 625: | ||
|- | |- | ||
− | | 07 | + | | 07:58 |
|Keep the value of ''' Period''' as 0.1 | |Keep the value of ''' Period''' as 0.1 | ||
Line 632: | Line 631: | ||
|- | |- | ||
− | | 08 | + | | 08:02 |
|Change the ''' Initialisation Time''' to be 0. | |Change the ''' Initialisation Time''' to be 0. | ||
Line 638: | Line 637: | ||
|- | |- | ||
− | | 08 | + | | 08:06 |
|Click on OK | |Click on OK | ||
Line 644: | Line 643: | ||
|- | |- | ||
− | | 08 | + | | 08:08 |
|Now let us change the '''Simulation''' parameters. | |Now let us change the '''Simulation''' parameters. | ||
Line 650: | Line 649: | ||
|- | |- | ||
− | | 08 | + | | 08:12 |
|On the menu bar of the '''untitled Xcos''' window click on the '''Simulation tab.''' | |On the menu bar of the '''untitled Xcos''' window click on the '''Simulation tab.''' | ||
Line 656: | Line 655: | ||
|- | |- | ||
− | | 08 | + | | 08:17 |
|Now click on ''' Setup from the drop down menu.''' | |Now click on ''' Setup from the drop down menu.''' | ||
Line 662: | Line 661: | ||
|- | |- | ||
− | | 08 | + | | 08:22 |
|Change the ''' Final Integration time''' to match the '''Refresh period''' of '''CScope''' block. | |Change the ''' Final Integration time''' to match the '''Refresh period''' of '''CScope''' block. | ||
Line 668: | Line 667: | ||
|- | |- | ||
− | | 08 | + | | 08:28 |
|The value of '''Refresh period''' was 10. | |The value of '''Refresh period''' was 10. | ||
Line 674: | Line 673: | ||
|- | |- | ||
− | | 08 | + | | 08:32 |
|Hence, put the value of '''Final integration''' time as 10. | |Hence, put the value of '''Final integration''' time as 10. | ||
Line 680: | Line 679: | ||
|- | |- | ||
− | | 08 | + | | 08:36 |
|Click on '''OK''' | |Click on '''OK''' | ||
Line 686: | Line 685: | ||
|- | |- | ||
− | | 08 | + | | 08:38 |
|Now, click on '''File''' and then click on '''Save''' to save the '''Xcos''' diagram. | |Now, click on '''File''' and then click on '''Save''' to save the '''Xcos''' diagram. | ||
Line 693: | Line 692: | ||
|- | |- | ||
− | | 08 | + | | 08:44 |
|Choose a desired directory to save the '''Xcos''' diagram. | |Choose a desired directory to save the '''Xcos''' diagram. | ||
Line 699: | Line 698: | ||
|- | |- | ||
− | | 08 | + | | 08:48 |
|However, it is advised to save it in the folder where you have saved the '''squareit.sci''' file. | |However, it is advised to save it in the folder where you have saved the '''squareit.sci''' file. | ||
Line 705: | Line 704: | ||
|- | |- | ||
− | | 08 | + | | 08:56 |
|Click on OK | |Click on OK | ||
Line 712: | Line 711: | ||
|- | |- | ||
− | | 08 | + | | 08:58 |
|Note that the '''scifunc''' block will call the ''' squareit''' function. | |Note that the '''scifunc''' block will call the ''' squareit''' function. | ||
Line 719: | Line 718: | ||
|- | |- | ||
− | | 09 | + | | 09:02 |
|This means that we should first load the ''' squareit''' function before we execute the xcos diagram. | |This means that we should first load the ''' squareit''' function before we execute the xcos diagram. | ||
Line 725: | Line 724: | ||
|- | |- | ||
− | | 09 | + | | 09:09 |
|Switch to the ''' Scilab editor''' window, which has the '''squareit.sci''' file open. | |Switch to the ''' Scilab editor''' window, which has the '''squareit.sci''' file open. | ||
Line 731: | Line 730: | ||
|- | |- | ||
− | | 09 | + | | 09:16 |
|Click on the '''Execute''' button available on the '''menu bar''' of the editor. | |Click on the '''Execute''' button available on the '''menu bar''' of the editor. | ||
Line 737: | Line 736: | ||
|- | |- | ||
− | | 09 | + | | 09:21 |
|This will load the '''squareit''' function. | |This will load the '''squareit''' function. | ||
Line 744: | Line 743: | ||
|- | |- | ||
− | | 09 | + | | 09:24 |
|Now we can execute the '''Xcos''' diagram. | |Now we can execute the '''Xcos''' diagram. | ||
Line 750: | Line 749: | ||
|- | |- | ||
− | | 09 | + | | 09:28 |
|Open the Xcos diagram file | |Open the Xcos diagram file | ||
Line 756: | Line 755: | ||
|- | |- | ||
− | | 09 | + | | 09:31 |
|Click on the '''Start''' button available on the '''menu bar''' of '''Xcos''' window | |Click on the '''Start''' button available on the '''menu bar''' of '''Xcos''' window | ||
Line 763: | Line 762: | ||
|- | |- | ||
− | | 09 | + | | 09:37 |
|A graphic window will appear. | |A graphic window will appear. | ||
Line 769: | Line 768: | ||
|- | |- | ||
− | | 09 | + | | 09:39 |
|This window will have two plots. | |This window will have two plots. | ||
Line 775: | Line 774: | ||
|- | |- | ||
− | | 09 | + | | 09:42 |
|Input '''sine wave''' in black color and output '''sine wave''' in green color. | |Input '''sine wave''' in black color and output '''sine wave''' in green color. | ||
|- | |- | ||
− | | 09 | + | | 09:47 |
|Notice that the squaring function implemented in the '''squareit''' function, has indeed squared the input sine wave. | |Notice that the squaring function implemented in the '''squareit''' function, has indeed squared the input sine wave. | ||
Line 786: | Line 785: | ||
|- | |- | ||
− | | 09 | + | | 09:55 |
|Hence, the output '''sine''' wave has been shifted to the positive axis. | |Hence, the output '''sine''' wave has been shifted to the positive axis. | ||
Line 792: | Line 791: | ||
|- | |- | ||
− | | 10 | + | | 10:00 |
|Close the plot window | |Close the plot window | ||
Line 798: | Line 797: | ||
|- | |- | ||
− | | 10 | + | | 10:02 |
|Now, let us see how to edit the scifunc block to call a function which has more than one input and output variables. | |Now, let us see how to edit the scifunc block to call a function which has more than one input and output variables. | ||
Line 804: | Line 803: | ||
|- | |- | ||
− | | 10 | + | | 10:10 |
|Switch to '''scilab''' editor window. | |Switch to '''scilab''' editor window. | ||
Line 810: | Line 809: | ||
|- | |- | ||
− | | 10 | + | | 10:13 |
|Edit the '''squareit''' function to have two input and output variables. | |Edit the '''squareit''' function to have two input and output variables. | ||
Line 816: | Line 815: | ||
|- | |- | ||
− | | 10 | + | | 10:19 |
|Edit the output variable as open square bracket y comma z close the square bracket . | |Edit the output variable as open square bracket y comma z close the square bracket . | ||
Line 822: | Line 821: | ||
|- | |- | ||
− | | 10 | + | | 10:28 |
|Edit the input variables as open bracket '''a''' comma '''b''' close bracket | |Edit the input variables as open bracket '''a''' comma '''b''' close bracket | ||
Line 828: | Line 827: | ||
|- | |- | ||
− | | 10 | + | | 10:36 |
|We will change the function to shift the squared output by 1 unit. | |We will change the function to shift the squared output by 1 unit. | ||
Line 834: | Line 833: | ||
|- | |- | ||
− | | 10 | + | | 10:41 |
|Edit the main function line as | |Edit the main function line as | ||
Line 840: | Line 839: | ||
|- | |- | ||
− | | 10 | + | | 10:44 |
|'''y''' is equal to '''b''' plus '''a''' raise to two put a semicolon in the end | |'''y''' is equal to '''b''' plus '''a''' raise to two put a semicolon in the end | ||
Line 848: | Line 847: | ||
|- | |- | ||
− | | 10 | + | | 10:51 |
|Also generate an output whose amplitude will be half of the input. | |Also generate an output whose amplitude will be half of the input. | ||
Line 854: | Line 853: | ||
|- | |- | ||
− | | 10 | + | | 10:56 |
|Go to next line by pressing enter key and type | |Go to next line by pressing enter key and type | ||
Line 860: | Line 859: | ||
|- | |- | ||
− | | 11 | + | | 11:01 |
|'''z''' is equal to 0.5 multiplied by a put a semicolon in the end | |'''z''' is equal to 0.5 multiplied by a put a semicolon in the end | ||
Line 866: | Line 865: | ||
|- | |- | ||
− | | 11 | + | | 11:10 |
|Now save the file | |Now save the file | ||
Line 873: | Line 872: | ||
|- | |- | ||
− | | 11 | + | | 11:12 |
| switch to the xcos window | | switch to the xcos window | ||
Line 879: | Line 878: | ||
|- | |- | ||
− | | 11 | + | | 11:15 |
|Double click on the '''scifunc''' block to configure it. | |Double click on the '''scifunc''' block to configure it. | ||
Line 885: | Line 884: | ||
|- | |- | ||
− | | 11 | + | | 11:19 |
|In the ''' input port size field,''' put a semi colon after 1 comma 1 and type 1 comma one again | |In the ''' input port size field,''' put a semi colon after 1 comma 1 and type 1 comma one again | ||
Line 891: | Line 890: | ||
|- | |- | ||
− | | 11 | + | | 11:27 |
|Similarly, in the output port size field, put a semi colon after 1 comma 1 and type 1 comma 1 again | |Similarly, in the output port size field, put a semi colon after 1 comma 1 and type 1 comma 1 again | ||
Line 897: | Line 896: | ||
|- | |- | ||
− | | 11 | + | | 11:36 |
|Click on Ok | |Click on Ok | ||
Line 904: | Line 903: | ||
|- | |- | ||
− | | 11 | + | | 11:38 |
|A new '''Scilab input value request''' window will open. | |A new '''Scilab input value request''' window will open. | ||
Line 910: | Line 909: | ||
|- | |- | ||
− | | 11 | + | | 11:41 |
|In the text box, | |In the text box, | ||
Line 916: | Line 915: | ||
|- | |- | ||
− | | 11 | + | | 11:43 |
|Put a comma after y1 and type y2. | |Put a comma after y1 and type y2. | ||
Line 922: | Line 921: | ||
|- | |- | ||
− | | 11 | + | | 11:48 |
|Put y1 and y2 in square brackets | |Put y1 and y2 in square brackets | ||
Line 928: | Line 927: | ||
|- | |- | ||
− | | 11 | + | | 11:52 |
|Now put a comma after '''u1''' and type '''u2''' | |Now put a comma after '''u1''' and type '''u2''' | ||
Line 934: | Line 933: | ||
|- | |- | ||
− | | 11 | + | | 11:57 |
|Click on OK | |Click on OK | ||
Line 940: | Line 939: | ||
|- | |- | ||
− | | 11 | + | | 11:59 |
|Another '''Scilab input value request''' window will open. | |Another '''Scilab input value request''' window will open. | ||
Line 946: | Line 945: | ||
|- | |- | ||
− | | 12 | + | | 12:03 |
|Keep clicking on '''Ok''' in the subsequent 3 windows that will appear. | |Keep clicking on '''Ok''' in the subsequent 3 windows that will appear. | ||
Line 952: | Line 951: | ||
|- | |- | ||
− | | 12 | + | | 12:08 |
|The '''scifunc''' block is now configured. | |The '''scifunc''' block is now configured. | ||
Line 958: | Line 957: | ||
|- | |- | ||
− | | 12 | + | | 12:11 |
|Let me realign the scifunc block | |Let me realign the scifunc block | ||
|- | |- | ||
− | | 12 | + | | 12:14 |
|Switch to the ''' palette browser''' window. | |Switch to the ''' palette browser''' window. | ||
Line 969: | Line 968: | ||
|- | |- | ||
− | | 12 | + | | 12:17 |
|In the '''sources''' section, drag and drop the Constant underscore m block in the xcos window. | |In the '''sources''' section, drag and drop the Constant underscore m block in the xcos window. | ||
Line 975: | Line 974: | ||
|- | |- | ||
− | | 12 | + | | 12:24 |
|Place it below the sinusoid generator block. | |Place it below the sinusoid generator block. | ||
Line 982: | Line 981: | ||
|- | |- | ||
− | | 12 | + | | 12:28 |
|Connect the ''' Constant underscore m''' block to the lower input of the '''scifunc''' block | |Connect the ''' Constant underscore m''' block to the lower input of the '''scifunc''' block | ||
Line 988: | Line 987: | ||
|- | |- | ||
− | | 12 | + | | 12:36 |
|The default value of this block is 1. | |The default value of this block is 1. | ||
Line 994: | Line 993: | ||
|- | |- | ||
− | | 12 | + | | 12:39 |
|Keep it unchanged. | |Keep it unchanged. | ||
Line 1,000: | Line 999: | ||
|- | |- | ||
− | | 12 | + | | 12:41 |
|Double click on the '''MUX''' block. | |Double click on the '''MUX''' block. | ||
Line 1,006: | Line 1,005: | ||
|- | |- | ||
− | | 12 | + | | 12:44 |
|Change the ''' input port size''' to 3 | |Change the ''' input port size''' to 3 | ||
Line 1,012: | Line 1,011: | ||
|- | |- | ||
− | | 12 | + | | 12:47 |
|Click on '''OK''' | |Click on '''OK''' | ||
Line 1,018: | Line 1,017: | ||
|- | |- | ||
− | | 12 | + | | 12:48 |
|Let me resize the '''MUX''' block and I will connect '''MUX''' and '''CSCOPE''' block properly. | |Let me resize the '''MUX''' block and I will connect '''MUX''' and '''CSCOPE''' block properly. | ||
Line 1,024: | Line 1,023: | ||
|- | |- | ||
− | | 12 | + | | 12:59 |
|Connect the lower output port of the '''scifunc''' block to the lower input port of '''MUX''' block | |Connect the lower output port of the '''scifunc''' block to the lower input port of '''MUX''' block | ||
Line 1,031: | Line 1,030: | ||
|- | |- | ||
− | | 13 | + | | 13:07 |
|Click on '''File''' and choose '''Save''' to save the xcos file. | |Click on '''File''' and choose '''Save''' to save the xcos file. | ||
Line 1,037: | Line 1,036: | ||
|- | |- | ||
− | | 13 | + | | 13:12 |
|Switch to the '''Scilab editor''' which has the '''squareit.sci''' file open. | |Switch to the '''Scilab editor''' which has the '''squareit.sci''' file open. | ||
Line 1,043: | Line 1,042: | ||
|- | |- | ||
− | | 13 | + | | 13:18 |
|Click on the '''Execute''' button available on the '''menu bar''' of the editor. | |Click on the '''Execute''' button available on the '''menu bar''' of the editor. | ||
Line 1,049: | Line 1,048: | ||
|- | |- | ||
− | | 13 | + | | 13:23 |
|This will load the '''squareit''' function. | |This will load the '''squareit''' function. | ||
Line 1,055: | Line 1,054: | ||
|- | |- | ||
− | | 13 | + | | 13:26 |
|Now we can execute the '''Xcos''' diagram. | |Now we can execute the '''Xcos''' diagram. | ||
Line 1,061: | Line 1,060: | ||
|- | |- | ||
− | | 13 | + | | 13:30 |
|Click on the '''Start''' button available on the '''menu bar''' of the '''Xcos''' window. | |Click on the '''Start''' button available on the '''menu bar''' of the '''Xcos''' window. | ||
Line 1,067: | Line 1,066: | ||
|- | |- | ||
− | | 13 | + | | 13:35 |
|A graphic window will appear. | |A graphic window will appear. | ||
Line 1,073: | Line 1,072: | ||
|- | |- | ||
− | | 13 | + | | 13:38 |
|This window will have three plots. | |This window will have three plots. | ||
Line 1,079: | Line 1,078: | ||
|- | |- | ||
− | | 13 | + | | 13:40 |
|Input '''sine wave''' in black color, | |Input '''sine wave''' in black color, | ||
Line 1,085: | Line 1,084: | ||
|- | |- | ||
− | | 13 | + | | 13:43 |
|output ''' sine wave''' in green color and | |output ''' sine wave''' in green color and | ||
|- | |- | ||
− | | 13 | + | | 13:45 |
| amplitude scaled input in red colour | | amplitude scaled input in red colour | ||
Line 1,096: | Line 1,095: | ||
|- | |- | ||
− | | 13 | + | | 13:49 |
|Notice that the function has indeed squared the input '''sine wave''' and also shifted it by an offset of 1 unit, which is as expected. | |Notice that the function has indeed squared the input '''sine wave''' and also shifted it by an offset of 1 unit, which is as expected. | ||
Line 1,102: | Line 1,101: | ||
|- | |- | ||
− | | 13 | + | | 13:59 |
|We also get the amplitude scaled of the input '''sine wave,''' as expected | |We also get the amplitude scaled of the input '''sine wave,''' as expected | ||
Line 1,108: | Line 1,107: | ||
|- | |- | ||
− | | 14 | + | | 14:05 |
|Close the plot window | |Close the plot window | ||
Line 1,114: | Line 1,113: | ||
|- | |- | ||
− | | 14 | + | | 14:08 |
|Now let us summarize. | |Now let us summarize. | ||
Line 1,120: | Line 1,119: | ||
|- | |- | ||
− | | 14 | + | | 14:10 |
|In this tutorial we learnt, | |In this tutorial we learnt, | ||
Line 1,127: | Line 1,126: | ||
|- | |- | ||
− | | 14 | + | | 14:12 |
|To write a squaring function in '''Scilab''' | |To write a squaring function in '''Scilab''' | ||
Line 1,133: | Line 1,132: | ||
|- | |- | ||
− | | 14 | + | | 14:15 |
|To use the '''scifunc''' block in '''Xcos ''' | |To use the '''scifunc''' block in '''Xcos ''' | ||
Line 1,139: | Line 1,138: | ||
|- | |- | ||
− | | 14 | + | | 14:19 |
|To use '''MUX ''' block to draw multiple plots | |To use '''MUX ''' block to draw multiple plots | ||
Line 1,145: | Line 1,144: | ||
|- | |- | ||
− | | 14 | + | | 14:22 |
|To call functions having multiple input and output | |To call functions having multiple input and output | ||
Line 1,151: | Line 1,150: | ||
|- | |- | ||
− | |14 | + | |14:26 |
| Watch the video available at the following link | | Watch the video available at the following link | ||
|- | |- | ||
− | | 14 | + | | 14:29 |
| It summarises the Spoken Tutorial project | | It summarises the Spoken Tutorial project | ||
Line 1,164: | Line 1,163: | ||
|- | |- | ||
− | |14 | + | |14:33 |
||If you do not have good bandwidth, you can download and watch it | ||If you do not have good bandwidth, you can download and watch it | ||
Line 1,170: | Line 1,169: | ||
|- | |- | ||
− | |14 | + | |14:37 |
||The spoken tutorial project Team | ||The spoken tutorial project Team | ||
Line 1,176: | Line 1,175: | ||
|- | |- | ||
− | |14 | + | |14:40 |
||Conducts workshops using spoken tutorials | ||Conducts workshops using spoken tutorials | ||
Line 1,183: | Line 1,182: | ||
|- | |- | ||
− | |14 | + | |14:43 |
||Gives certificates for those who pass an online test | ||Gives certificates for those who pass an online test | ||
Line 1,190: | Line 1,189: | ||
|- | |- | ||
− | |14 | + | |14:47 |
||For more details, please write to contact@spoken-tutorial.org | ||For more details, please write to contact@spoken-tutorial.org | ||
Line 1,197: | Line 1,196: | ||
|- | |- | ||
− | |14 | + | |14:53 |
|Spoken Tutorial Project is a part of Talk to a Teacher project | |Spoken Tutorial Project is a part of Talk to a Teacher project | ||
Line 1,205: | Line 1,204: | ||
|- | |- | ||
− | | 14 | + | | 14:57 |
| It is supported by the National Mission on Eduction through ICT, MHRD, Government of India. | | It is supported by the National Mission on Eduction through ICT, MHRD, Government of India. | ||
|- | |- | ||
− | | 15 | + | | 15:05 |
|More information on this mission is available at spoken-tutorial.org/NMEICT-Intro | |More information on this mission is available at spoken-tutorial.org/NMEICT-Intro | ||
Line 1,218: | Line 1,217: | ||
|- | |- | ||
− | |15 | + | |15:15 |
| Thank you for joining .Hope you found this tutorial useful | | Thank you for joining .Hope you found this tutorial useful | ||
Line 1,224: | Line 1,223: | ||
|- | |- | ||
− | | 15 | + | | 15:19 |
|This is Anuradha Amruthkar from IIT Bombay signing off. | |This is Anuradha Amruthkar from IIT Bombay signing off. |
Revision as of 11:16, 11 July 2014
Time | Narration |
00:01 | Welcome to the spoken tutorial on “Calling user-defined functions in Xcos” |
00:07 | In this tutorial we will learn, |
00:09 | To write a squaring function in Scilab
|
00:12 | To use the scifunc block in Xcos
|
00:15 | To use MUX block to draw multiple plots |
00:19 | To call functions having multiple inputs and outputs |
00:24 | Ubuntu 12.04 is the operating system used with Scilab version 5.3.3 installed. |
00:32 | You should have Basic knowledge of Scilab
|
00:35 | Basic knowledge of Xcos |
00:38 | If not, for relevant tutorials please visit spoken hyphen tutorial dot org |
00:44 | Start Scilab on your computer. |
00:47 | In the Scilab console, type editor and press Enter
|
00:53 | Then type the following code |
00:55 | function space y is equal to squareit open bracket a close bracket |
01:07 | Press the enter key and type |
01:10 | y is equal to a raise to 2
|
01:14 | put a semicolon in the end
|
01:17 | The function has one input variable a and one output variable y |
01:24 | The name of the function is squareit
|
01:27 | This function will do the job of squaring the variable a. |
01:31 | It will store the result in y.
|
01:34 | Let us save this file in the desired directory.
|
01:38 | I will save this file with file name squareit and extension .sci |
01:44 | Here we are following the convention of saving functions in .sci format. |
01:50 | Switch to the Scilab console |
01:53 | Now, type Xcos and press Enter. |
01:57 | Two windows will open |
01:59 | A palette browser and an untitled Xcos window.
|
02:04 | Now we will make the Xcos diagram.
|
02:06 | This will access the function squareit created just now.
|
02:10 | This can be done by using scifunc block.
|
02:14 | Switch to the palette browser window |
02:17 | Click on the User-Defined function in the pallet browser.
|
02:21 | Locate the block scifunc_block_m in this section. |
02:27 | Drag and drop it in untitled Xcos window. |
02:32 | I will zoom the untitled Xcos window for better view. |
02:36 | I will use the Zoom button as you see. |
02:40 | Now double click on the scifunc block to configure it.
|
02:44 | A window named Scilab multiple values request will open |
02:49 | This window will allow you to change the number of input and output ports of the scifunc block. |
02:56 | Our function squareit has only one input and output variable.
|
03:00 | 'Hence, we will keep the settings unchanged. |
03:03 | Click on Ok. |
03:05 | A new Scilab input value request window will open.
|
03:09 | In the text box, type the function name along with input and output variables. |
03:14 | This function will be called by the scifunc block
|
03:18 | In the text box available,
|
03:20 | edit the default function name. |
03:22 | Type y1 equal to squareit open bracket u1 close the bracket |
03:31 | Note that, here the input and output variables are u1 and y1 respectively.
|
03:37 | These should be strictly in u and y form and not as per the variable names used in the actual function.
|
03:45 | Cick on OK. |
03:47 | Another Scilab input value request window will open. |
03:51 | Keep clicking on Ok in the subsequent 3 windows that will appear.
|
03:56 | The scifunc block is now configured.
|
04:00 | Next we will include a sinusoid generator block. |
04:04 | In the palette browser window, click on Sources section.
|
04:08 | Drag and drop the Sinusoid Generator block in untitled Xcos window. |
04:14 | Place the block towards the left of the scifunc block for convenience. |
04:20 | Now we need a block to plot the output variable. |
04:23 | 'In the palette browser window, click on Sinks section. |
04:29 | Drag and drop the CScope block in the untitled Xcos window.
|
04:34 | Place the block towards the right of the scifunc block
|
04:38 | Place it away from scifunc block, for convenience.
|
04:43 | Notice that the CScope block has a red input port. |
04:47 | This is an event input
|
04:49 | we need an event generator block.
|
04:52 | In the palette browser window, click on Sources section.
|
04:57 | Drag and drop the clock underscore c block in the untitled Xcos window. |
05:05 | Place it above the CScope block. |
05:08 | Notice that the CScope block has only one input port. |
05:13 | But we want to plot both the input and output variables in a single plot window. |
05:18 | Hence, we need a multiplexer block, |
05:22 | This block will multiplex two inputs and generate output on one output port.
|
05:28 | In the palette browser window, click on Signal Routing section. |
05:33 | Drag and drop the MUX block in the untitled Xcos window.
|
05:39 | Place the block between the scifunc block and CScope block. |
05:43 | Let me resize and realign the Mux block |
05:47 | Now let us connect the blocks together.
|
05:51 | Connect the output port of Sinusoid generator block to the input port of scifunc block
|
05:57 | Now connect the output port of scifunc block to the lower input port of the MUX. |
06:04 | Connect the output port of MUX block to the input port of CScope block. |
06:10 | Connect the output port of clock underscore c block to the event input port of CScope block. |
06:19 | We also have to plot sine input. |
06:22 | We have to connect the Sinusoid generator block to the MUX. |
06:26 | Click on the upper input port of the MUX block. |
06:30 | Then without releasing, move your mouse pointer towards the link between the Sinusoid generator block and scifunc block.
|
06:39 | To bend the link, release the mouse button or click at places |
06:44 | As you bring the pointer on the link, the link turns green. |
06:49 | Release the mouse button or click once to create a link between these two blocks. |
06:55 | Now let us see the configuration of other blocks |
06:59 | We can change the frequency, magnitude and phase of the sinusoid generator block.
|
07:04 | To do this, double click on the Sinusoid generator block. |
07:09 | The configuration window will open. |
07:11 | We will keep the magnitude and frequency as 1 and phase as 0 |
07:18 | Click on Ok to close the configuration window. |
07:21 | Now let us configure the CScope block. |
07:25 | Double click on the CScope block to open its configuration window. |
07:30 | Change the Ymin parameter to minus 2 and Ymax parameter to 2 |
07:37 | Change the Refresh period value to 10. |
07:41 | Make a mental note of this value. |
07:44 | Change the buffer size value to 2 . |
07:47 | click on OK
|
07:50 | Now let us configure the CLOCK_c block |
07:54 | Double click on the block to open its configuration window. |
07:58 | Keep the value of Period as 0.1 |
08:02 | Change the Initialisation Time to be 0. |
08:06 | Click on OK |
08:08 | Now let us change the Simulation parameters. |
08:12 | On the menu bar of the untitled Xcos window click on the Simulation tab. |
08:17 | Now click on Setup from the drop down menu. |
08:22 | Change the Final Integration time to match the Refresh period of CScope block. |
08:28 | The value of Refresh period was 10. |
08:32 | Hence, put the value of Final integration time as 10. |
08:36 | Click on OK |
08:38 | Now, click on File and then click on Save to save the Xcos diagram.
|
08:44 | Choose a desired directory to save the Xcos diagram. |
08:48 | However, it is advised to save it in the folder where you have saved the squareit.sci file. |
08:56 | Click on OK
|
08:58 | Note that the scifunc block will call the squareit function.
|
09:02 | This means that we should first load the squareit function before we execute the xcos diagram. |
09:09 | Switch to the Scilab editor window, which has the squareit.sci file open. |
09:16 | Click on the Execute button available on the menu bar of the editor. |
09:21 | This will load the squareit function.
|
09:24 | Now we can execute the Xcos diagram. |
09:28 | Open the Xcos diagram file |
09:31 | Click on the Start button available on the menu bar of Xcos window
|
09:37 | A graphic window will appear. |
09:39 | This window will have two plots. |
09:42 | Input sine wave in black color and output sine wave in green color. |
09:47 | Notice that the squaring function implemented in the squareit function, has indeed squared the input sine wave. |
09:55 | Hence, the output sine wave has been shifted to the positive axis. |
10:00 | Close the plot window |
10:02 | Now, let us see how to edit the scifunc block to call a function which has more than one input and output variables. |
10:10 | Switch to scilab editor window. |
10:13 | Edit the squareit function to have two input and output variables. |
10:19 | Edit the output variable as open square bracket y comma z close the square bracket . |
10:28 | Edit the input variables as open bracket a comma b close bracket |
10:36 | We will change the function to shift the squared output by 1 unit. |
10:41 | Edit the main function line as |
10:44 | y is equal to b plus a raise to two put a semicolon in the end
|
10:51 | Also generate an output whose amplitude will be half of the input. |
10:56 | Go to next line by pressing enter key and type |
11:01 | z is equal to 0.5 multiplied by a put a semicolon in the end |
11:10 | Now save the file
|
11:12 | switch to the xcos window |
11:15 | Double click on the scifunc block to configure it. |
11:19 | In the input port size field, put a semi colon after 1 comma 1 and type 1 comma one again |
11:27 | Similarly, in the output port size field, put a semi colon after 1 comma 1 and type 1 comma 1 again |
11:36 | Click on Ok
|
11:38 | A new Scilab input value request window will open. |
11:41 | In the text box, |
11:43 | Put a comma after y1 and type y2. |
11:48 | Put y1 and y2 in square brackets |
11:52 | Now put a comma after u1 and type u2 |
11:57 | Click on OK |
11:59 | Another Scilab input value request window will open. |
12:03 | Keep clicking on Ok in the subsequent 3 windows that will appear. |
12:08 | The scifunc block is now configured. |
12:11 | Let me realign the scifunc block |
12:14 | Switch to the palette browser window. |
12:17 | In the sources section, drag and drop the Constant underscore m block in the xcos window. |
12:24 | Place it below the sinusoid generator block.
|
12:28 | Connect the Constant underscore m block to the lower input of the scifunc block |
12:36 | The default value of this block is 1. |
12:39 | Keep it unchanged. |
12:41 | Double click on the MUX block. |
12:44 | Change the input port size to 3 |
12:47 | Click on OK |
12:48 | Let me resize the MUX block and I will connect MUX and CSCOPE block properly. |
12:59 | Connect the lower output port of the scifunc block to the lower input port of MUX block
|
13:07 | Click on File and choose Save to save the xcos file. |
13:12 | Switch to the Scilab editor which has the squareit.sci file open. |
13:18 | Click on the Execute button available on the menu bar of the editor. |
13:23 | This will load the squareit function. |
13:26 | Now we can execute the Xcos diagram. |
13:30 | Click on the Start button available on the menu bar of the Xcos window. |
13:35 | A graphic window will appear. |
13:38 | This window will have three plots. |
13:40 | Input sine wave in black color, |
13:43 | output sine wave in green color and |
13:45 | amplitude scaled input in red colour |
13:49 | Notice that the function has indeed squared the input sine wave and also shifted it by an offset of 1 unit, which is as expected. |
13:59 | We also get the amplitude scaled of the input sine wave, as expected |
14:05 | Close the plot window |
14:08 | Now let us summarize. |
14:10 | In this tutorial we learnt,
|
14:12 | To write a squaring function in Scilab |
14:15 | To use the scifunc block in Xcos |
14:19 | To use MUX block to draw multiple plots |
14:22 | To call functions having multiple input and output
|
14:26 | Watch the video available at the following link |
14:29 | It summarises the Spoken Tutorial project
|
14:33 | If you do not have good bandwidth, you can download and watch it |
14:37 | The spoken tutorial project Team |
14:40 | Conducts workshops using spoken tutorials
|
14:43 | Gives certificates for those who pass an online test
|
14:47 | For more details, please write to contact@spoken-tutorial.org
|
14:53 | Spoken Tutorial Project is a part of Talk to a Teacher project
|
14:57 | It is supported by the National Mission on Eduction through ICT, MHRD, Government of India. |
15:05 | More information on this mission is available at spoken-tutorial.org/NMEICT-Intro
|
15:15 | Thank you for joining .Hope you found this tutorial useful |
15:19 | This is Anuradha Amruthkar from IIT Bombay signing off. |