{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2: Signals An Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.10: Laplace_Transform.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "\n", "//x(t) = del(t)\n", "syms t s;\n", "\n", "L =laplace('delta(t)',t,s)\n", "disp(L)\n", "// x(t) = u(t)\n", "\n", "L1 =laplace('1',t,s);\n", "disp(L1)\n", "//x(t) = sin(w0*t)u(t)\n", "\n", "L2 =laplace('sin(w0*t)',t,s);\n", "disp(L2)" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.11: Z_transform.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "clc;\n", "clear;\n", "\n", "// a) z-transform of unit impulse function\n", "syms n z;\n", "x=1;\n", "X=symsum(x*(z^-n),n,0,0);\n", "disp(X,'X(z)=');\n", "\n", "//b) z-transform of unit step function\n", "\n", "y=ones(1);\n", "Y=symsum(y*(z^-n),n,0,%inf);\n", "disp(Y,'Y(z)=');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_A: Periodicity.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "clear;\n", "clc;\n", " //a) periodicity os 5sin(6t-pi/4)\n", "t=0:0.001:1;\n", "w=6;\n", "theta=%pi/4;\n", "T=2*%pi/w;\n", "x=cos(t*w+theta);\n", "y=cos((t+T)*w+theta);\n", "if ceil(x)==ceil(y) then\n", " disp(' a) cos(6t+pi/4) is periodic with T=2*pi/6 (sec) ')\n", " \n", "else\n", " disp('nonperiodic')\n", "end\n", "\n", "\n", " //b) periodicity of e^(j3t)\n", " \n", " w=3; \n", " t=0:0.001:1;\n", " T=2*%pi/w;\n", " x=exp(3*%i*t);\n", " y=exp(3*%i*(t+T));\n", " if ceil(x)==ceil(y) then\n", " disp(' b) exp(j3t) is periodic with T=2*pi/3 (sec) ')\n", " \n", "else\n", " disp('nonperiodic')\n", "end\n", " \n", " \n", " //c) periodicity of cot(3t+theta)\n", " \n", " t=0:0.001:1;\n", "w=5;\n", "T=%pi/w;\n", "\n", " x=cotg(t*w+theta);\n", " y=cotg((t+T)*w+theta);\n", "if ceil(x)==ceil(y) then\n", " disp(' c) cot(3t+Theta) is periodic with T=pi/5 (sec) ')\n", " \n", "else\n", " disp('nonperiodic')\n", "end\n", " \n", " " ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.2_A: Even_and_Odd_Part_of_function.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc;\n", "clear;\n", "t = 0:1:10;\n", "\n", "for i = 1:length(t)\n", " x(i) = (t(i)^6) + 2*(t(i)^4)+ 3*(t(i)^2)+4 ;\n", "end\n", "\n", "for i = 1:length(t)\n", " y(i) = ((-t(i))^6)+ 2*((-t(i))^4)+ 3*((-t(i))^2)+4 ;\n", "end\n", "\n", "// checking if the function is even x(t)=x(-t)\n", "if x==y then\n", " disp('the function is even');\n", "end\n", "//odd part of the signal=0.5(x(t)-x(-t))\n", "\n", "z=0.5*(x-y);\n", "if z==0 then\n", " disp('the odd part is 0')\n", "end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.2: Real_and_Imaginary_part.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc;\n", "clear;\n", "\n", "/// e^j(*2*pi*f*t+theta)\n", "\n", "syms pi f0 t theta A\n", "K=2*pi*f0*t+theta;\n", "\n", "disp('the given signal is complex');\n", "disp('e^(j*theta) can be written as');\n", "disp('cos(theta)+j*sin(theta)');\n", "\n", "Re=A*cos(K);\n", "Img=A*sin(K);\n", "mag=sqrt(Re^2+Img^2);\n", "\n", "disp(Re,'real part is ');\n", "disp(Img,'the imaginary part ');\n", "disp(mag,'Magnitude of signal is |A|=');\n", "disp(K,'phase of the signal ');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_A: Power_and_Rms_power_of_Signal.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clear;\n", "clc;\n", "\n", " //x(t)=5u(t)....\n", " amp=5; //amplitude is 5\n", "t=0:0.01:1;\n", "x0=0;\n", "x1=0:0.1:10; // over a time interval of T\n", "disp('the power of the signal (in watts) is');\n", " X=(integrate('25','x',x0,10)/(2*10)); // power of the signal\n", "disp(X);\n", "\n", "rms=amp/sqrt(2);\n", "disp(rms,'the rms value of power is (in watts)');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3: Energy_of_Signal.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc;\n", "clear;\n", "\n", "//x(t)=2 over an interval of (-2,2)\n", "\n", "disp('the energy of the signal (in J)is');\n", " Ex=(integrate('4','x',-2,2)); // energy content of the signal\n", "disp(Ex);" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.5: Properties_of_Impulse_Signal.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clc;\n", "clear;\n", "\n", "\n", "//delta(t)\n", "\n", " for j = 1:1000\n", " if j==1\n", " delta(j)=1;\n", " else\n", " delta(j)=0;\n", " end\n", " end\n", "\n", "// a)\n", "figure(1)\n", " t=-1;\n", " plot2d4(t,0);\n", " for j=1:1:10\n", " t=t+1;\n", " z(j)=(cosd(j-1)*delta(j));\n", " plot2d3(t,z(j));\n", " disp(z(j));\n", " \n", " end\n", "\n", "\n", "//b)\n", "figure(2)\n", " t=1.5;\n", " plot2d4(t,0);\n", " for j=3:1:10\n", " t=t+1;\n", " z(j)=abs(cosd(2.5)*delta(2*j-5));\n", " plot2d3(t,z(j));\n", " \n", " end\n", "\n", "//c)\n", "syms t;\n", "\n", "A=(-1)*exp(-1*t); //property 8\n", "disp(diff(A,t));\n", "\n", "disp('when t=3');\n", "\n", "A=exp(-3);\n", "disp(A);\n", "\n", "\n", "\n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " " ] } ], "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 }