{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2: Linear Time Invariant System" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.17_a: Check_for_causal_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.17a\n", "clc;\n", "disp(' y[n]=3x[n-2]+3x[n+2] ');\n", "disp('THE GIVEN SYSTEM IS NON-CAUSAL');\n", "disp('Since the value of output depends on future input');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.17_b: Check_for_causal_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.17b\n", "clc;\n", "disp(' y[n]=x[n-1]+a*x[n-2] ');\n", "disp('THE GIVEN SYSTEM IS CAUSAL');\n", "disp('Since the value of output doesnot depends on future input');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.17_c: Check_for_causal_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.17c\n", "clc;\n", "disp(' y[n]=x[-n] ');\n", "disp('THE GIVEN SYSTEM IS NON-CAUSAL');\n", "disp('Since the value of output depends on future input');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.19_a: Check_for_linear_systems.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.19a\n", "clc;\n", "x1=[1,1,1,1]\n", "x2=[2,2,2,2]\n", "a=1\n", "b=1\n", "a1=0.5\n", "b1=0.5\n", "for n=1:length(x1)\n", " x3(n)=a*x1(n)+b*x2(n)\n", "end\n", "for n=1:length(x1)\n", " y1(n)=a1*n*x1(n)+b1\n", " y2(n)=a1*n*x2(n)+b1\n", " y3(n)=a1*n*x3(n)+b1\n", "end\n", "for n=1:length(y1)\n", " z(n)=a*y1(n)+b*y2(n)\n", "end\n", "count=0\n", "for n=1:length(y1)\n", " if(y3(n)==z(n))\n", " count=count+1;\n", " end \n", "end\n", "if(count==length(y3))\n", "disp('It satisfy the superposition principle');\n", "disp('THE GIVEN SYSTEM IS LINEAR ');\n", "else\n", " disp('It does not satisfy superposition principle ');\n", " disp('THE GIVEN SYSTEM IS NON LINEAR');\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.19_b: Check_for_linear_systems.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.19b\n", "clc;\n", "x1=[1,1,1,1]\n", "x2=[2,2,2,2]\n", "a=1\n", "b=1\n", "for n=1:length(x1)\n", " x3(n)=a*x1(n)+b*x2(n)\n", "end\n", "for n=1:length(x1)\n", " y1(n)=exp(x1(n))\n", " y2(n)=exp(x2(n))\n", " y3(n)=exp(x3(n))\n", "end\n", "for n=1:length(y1)\n", " z(n)=a*y1(n)+b*y2(n)\n", "end\n", "count=0\n", "for n=1:length(y1)\n", " if(y3(n)==z(n))\n", " count=count+1;\n", " end \n", "end\n", "if(count==length(y3))\n", "disp('It satisfy the superposition principle');\n", "disp('THE GIVEN SYSTEM IS LINEAR ');\n", "else\n", " disp('It does not satisfy superposition principle ');\n", " disp('THE GIVEN SYSTEM IS NON LINEAR');\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1: Convolution_of_two_continous_time_functions.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.1\n", "clc;\n", "t=-8:1/100:8;\n", "for i=1:length(t)\n", " x(i)=exp(-t(i)^2);\n", " h(i)=3*t(i)^2;\n", "end\n", "y=convol(x,h);\n", "figure\n", "plot2d(t,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d(t,x);\n", "title('Input signal');\n", "figure\n", "t2=-16:1/100:16\n", "plot2d(t2,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.21_a: Check_for_linear_systems.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.21\n", "clc;\n", "x1=[1,1,1,1]\n", "x2=[2,2,2,2]\n", "a=1\n", "b=1\n", "for t=1:length(x1)\n", " x3(t)=a*x1(t)+b*x2(t)\n", "end\n", "for t=1:length(x1)\n", " y1(t)=5*sin(x1(t))\n", " y2(t)=5*sin(x2(t))\n", " y3(t)=5*sin(x3(t))\n", "end\n", "for t=1:length(y1)\n", " z(t)=a*y1(t)+b*y2(t)\n", "end\n", "count=0\n", "for n=1:length(y1)\n", " if(y3(t)==z(t))\n", " count=count+1;\n", " end \n", "end\n", "if(count==length(y3))\n", "disp('It satisfy the superposition principle');\n", "disp('THE GIVEN SYSTEM IS LINEAR ');\n", "else\n", " disp('It does not satisfy superposition principle ');\n", " disp('THE GIVEN SYSTEM IS NON LINEAR');\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.21_b: Check_for_linear_systems.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.21b\n", "clc;\n", "x1=[1,1,1,1]\n", "x2=[2,2,2,2]\n", "a=1\n", "b=1\n", "for t=1:length(x1)\n", " x3(t)=a*x1(t)+b*x2(t)\n", "end\n", "for t=1:length(x1)\n", " y1(t)=7*x1(t)+5\n", " y2(t)=7*x2(t)+5\n", " y3(t)=7*x3(t)+5\n", "end\n", "for t=1:length(y1)\n", " z(t)=a*y1(t)+b*y2(t)\n", "end\n", "count=0\n", "for n=1:length(y1)\n", " if(y3(t)==z(t))\n", " count=count+1;\n", " end \n", "end\n", "if(count==length(y3))\n", "disp('It satisfy the superposition principle');\n", "disp('THE GIVEN SYSTEM IS LINEAR ');\n", "else\n", " disp('It does not satisfy superposition principle ');\n", " disp('THE GIVEN SYSTEM IS NON LINEAR');\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.25: Check_for_linear_systems.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.25\n", "clc;\n", "x1=[1,1,1,1]\n", "x2=[2,2,2,2]\n", "a=1\n", "b=1\n", "for n=1:length(x1)\n", " x3(n)=a*x1(n)+b*x2(n)\n", "end\n", "for n=1:length(x1)\n", " y1(n)=x1(n)^2\n", " y2(n)=x2(n)^2\n", " y3(n)=x3(n)^2\n", "end\n", "for n=1:length(y1)\n", " z(n)=a*y1(n)+b*y2(n)\n", "end\n", "count=0\n", "for n=1:length(y1)\n", " if(y3(n)==z(n))\n", " count=count+1;\n", " end \n", "end\n", "if(count==length(y3))\n", "disp('It satisfy the superposition principle');\n", "disp('THE GIVEN SYSTEM IS LINEAR ');\n", "else\n", " disp('It does not satisfy superposition principle ');\n", " disp('THE GIVEN SYSTEM IS NON LINEAR');\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.2: Find_responce_of_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.2\n", "clc;\n", "t=-8:1/100:8;\n", "for i=1:length(t)\n", " if t(i)<0 then\n", " x(i)=0;\n", " h(i)=0;\n", " else\n", " x(i)=exp(-3.*t(i));\n", " h(i)=1;\n", " end\n", "end\n", "t1=t+1;\n", "y=convol(x,h);\n", "figure\n", "plot2d(t1,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d(t,x);\n", "title('Input signal');\n", "figure\n", "t2=-16:1/100:16\n", "plot2d(t2,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3: Find_unit_step_responce_of_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.3\n", "clc;\n", "R=100;\n", "L=100;\n", "t=-8:1/100:8;\n", "for i=1:length(t)\n", " if t(i)<0 then\n", " x(i)=0;\n", " h(i)=0;\n", " else\n", " h(i)=(R/L)*exp(-(R/L).*t(i));\n", " x(i)=1;\n", " end\n", "end\n", "y=convol(x,h);\n", "figure\n", "plot2d(t,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d(t,x);\n", "title('Input signal');\n", "figure\n", "t2=-16:1/100:16\n", "plot2d(t2,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.4: Convolution_of_two_continous_time_functions.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.4\n", "clc;\n", "t=-8:1/100:8;\n", "for i=1:length(t)\n", " x(i)=3*cos(2.*t(i));\n", " h(i)=exp(-abs(t(i)));\n", "end\n", "y=convol(x,h);\n", "figure\n", "plot2d(t,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d(t,x);\n", "title('Input signal');\n", "figure\n", "t2=-16:1/100:16\n", "plot2d(t2,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.59: Convolution_of_two_discrete_time_signals.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.59\n", "clc;\n", "n=-8:1:8;\n", "for i=1:length(n)\n", " if n(i)<0 then\n", " x(i)=0;\n", " h(i)=0;\n", " else\n", " x(i)=1;\n", " h(i)=2^n(i);\n", " end\n", "end\n", "y=convol(x,h);\n", "figure\n", "a=gca();\n", "plot2d3(n,h);\n", "a.x_location='origin';\n", "a.y_location='origin';\n", "title('Impulse responce');\n", "figure\n", "a=gca();\n", "plot2d3(n,x);\n", "a.x_location='origin';\n", "a.y_location='origin';\n", "title('Input signal');\n", "figure\n", "a=gca();\n", "n1=-16:1:16\n", "plot2d3(n1,y);\n", "a.x_location='origin';\n", "a.y_location='origin';\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.5: Evaluation_of_output_of_LTI_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.5\n", "clc;\n", "Max_Limit=10;\n", "h=ones(1,Max_Limit);\n", "N2=0:length(h)-1;\n", "a=0.5;//constant a>0\n", "for t=1:Max_Limit\n", "x(t)=exp(-a*(t-1));\n", "end\n", "N1=0:length(x)-1;\n", "y=convol(x,h)-1;\n", "N=0:length(x)+length(h)-2;\n", "figure\n", "a=gca();\n", "plot2d(N2,h)\n", "xtitle('Impulse Response','t','h(t)');\n", "a.thickness=2;\n", "figure\n", "a=gca();\n", "plot2d(N1,x)\n", "xtitle('Input Response','t','x(t)');\n", "a.thickness=2;\n", "figure\n", "a=gca ();\n", "plot2d(N(1:Max_Limit),y(1:Max_Limit))\n", "xtitle('Output Response','t','y(t)');\n", "a.thickness=2;" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.6: Find_responce_of_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.6\n", "clc;\n", "t=-8:1/100:8;\n", "for i=1:length(t)\n", " if t(i)<0 then\n", " x(i)=exp(2.*t(i));\n", " h(i)=0;\n", " else\n", " x(i)=0;\n", " h(i)=1;\n", " end\n", "end\n", "t1=t+3;\n", "y=convol(x,h);\n", "figure\n", "plot2d(t1,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d(t,x);\n", "title('Input signal');\n", "figure\n", "t2=-16:1/100:16\n", "plot2d(t2,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.7: Convolution_of_two_discrete_time_signals.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.7\n", "clc;\n", "n=-8:1:8;\n", "for i=1:length(n)\n", " x(i)=exp(-n(i)^2);\n", " h(i)=3.*n(i)^2;\n", "end\n", "y=convol(x,h);\n", "figure\n", "plot2d3(n,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d3(n,x);\n", "title('Input signal');\n", "figure\n", "n1=-16:1:16\n", "plot2d3(n1,y);\n", "title('Output signal');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.8: Find_responce_of_system.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//Example 2.8\n", "clc;\n", "n=-8:1:8;\n", "for i=1:length(n)\n", " if n(i)<0 then\n", " x(i)=2^n(i);\n", " h(i)=0;\n", " else\n", " x(i)=0;\n", " h(i)=1;\n", " end\n", "end\n", "y=convol(x,h);\n", "figure\n", "plot2d3(n,h);\n", "title('Impulse responce');\n", "figure\n", "plot2d3(n,x);\n", "title('Input signal');\n", "figure\n", "n1=-16:1:16\n", "plot2d3(n1,y);\n", "title('Output signal');" ] } ], "metadata": { "kernelspec": { "display_name": "Scilab", "language": "scilab", "name": "scilab" }, "language_info": { "file_extension": ".sce", "help_links": [ { "text": "MetaKernel Magics", "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" } ], "mimetype": "text/x-octave", "name": "scilab", "version": "0.7.1" } }, "nbformat": 4, "nbformat_minor": 0 }