From 07b520b48e2c37e76c8cb68e045da17b8e34dd99 Mon Sep 17 00:00:00 2001 From: Hardi Kadia <65995407+hardi15@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:08:14 +0530 Subject: [PATCH] Added some scilab examples --- first.sce | 26 ++++++++++++++++++++++++++ prac1(duty).sce | 17 +++++++++++++++++ randfilt.sce | 9 +++++++++ second.sce | 28 ++++++++++++++++++++++++++++ third.sce | 31 +++++++++++++++++++++++++++++++ xnxt.sce | 14 ++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 first.sce create mode 100644 prac1(duty).sce create mode 100644 randfilt.sce create mode 100644 second.sce create mode 100644 third.sce create mode 100644 xnxt.sce diff --git a/first.sce b/first.sce new file mode 100644 index 0000000..53c1a6e --- /dev/null +++ b/first.sce @@ -0,0 +1,26 @@ +// Namit Shah , AU1841067 +// Programming Assignment +// Signals & Systems , Semester 3 + +// Question 1 --> Sampling index + +clear; +clc; + +function y = n(x,k) + y = []; + len = length(x); + for i = 1:len + y($+1) = i-k; + end +endfunction + +vx = []; +l = input("Enter length of vector : "); +disp("Enter vector (Press Enter after each input) : "); +for i = 1:l + vx(i) = input(""); +end +k = input("Enter value of k : ") +ans = n(vx,k); +disp(ans); diff --git a/prac1(duty).sce b/prac1(duty).sce new file mode 100644 index 0000000..192f1e2 --- /dev/null +++ b/prac1(duty).sce @@ -0,0 +1,17 @@ +clear; +clf; +clc; +x=[ones(1:5),zeros(1:95)]; +y=[ones(1:50),zeros(1:50)]; +xf=fft(x); +yf=fft(y); +xfa=abs(xf); +yfa=abs(yf); +subplot(211); +plot2d3(xfa); +xgrid(4); +title("Spectrum of pluse waveform with 5% duty cycle","fontsize",4); +subplot(212); +plot2d3(yfa); +xgrid(4); +title("Spectrum of pluse waveform with 50% duty cycle","fontsize",4); diff --git a/randfilt.sce b/randfilt.sce new file mode 100644 index 0000000..67a29e6 --- /dev/null +++ b/randfilt.sce @@ -0,0 +1,9 @@ +clear; +clf; +r = rand(1, 100) - 0.5; +subplot(211); +plot(r); +subplot(212); +c = ffilt("lp", 21, 0.1); +y = filter(c, 1, r); +plot(y); \ No newline at end of file diff --git a/second.sce b/second.sce new file mode 100644 index 0000000..68627bf --- /dev/null +++ b/second.sce @@ -0,0 +1,28 @@ +// Namit Shah , AU1841067 +// Programming Assignment +// Signals & Systems , Semester 3 + +// Question 2 --> Down Sampling + +clear; +clc; + +function y = downsampling(x,M) + y = []; + len = length(x); + for i = 1:M:len + y($+1) = x(i); + end +endfunction + + +x = []; +l = input("Enter length of vector : "); +disp("Enter vector (Press Enter after each input) : "); +for i = 1:l + x(i) = input(""); +end +M = input("Enter the down sampling factor M : "); +ans = downsampling(x,M); +disp("Down Sampled Vector : "); +disp(ans); diff --git a/third.sce b/third.sce new file mode 100644 index 0000000..7e59000 --- /dev/null +++ b/third.sce @@ -0,0 +1,31 @@ +// Namit Shah , AU1841067 +// Programming Assignment +// Signals & Systems , Semester 3 + +// Question 3 --> Up Sampling + +clear; +clc; + +function y = upSampling(x,L) + y = []; + len = length(x); + for i = 1:L.*len + if modulo(i-1,L)==0 + y($+1) = x(((i-1)./L)+1); + else + y($+1) = 0; + end + end +endfunction + +x = []; +l = input("Enter length of vector : "); +disp("Enter vector (Press Enter after each input) : "); +for i = 1:l + x(i) = input(""); +end +L = input("Enter the up sampling factor L : "); +ans = upSampling(x,L); +disp("Up Sampled Vector : "); +disp(ans); diff --git a/xnxt.sce b/xnxt.sce new file mode 100644 index 0000000..b0b61de --- /dev/null +++ b/xnxt.sce @@ -0,0 +1,14 @@ +clear; +clf; +dn = 1; +dt = 1/50; +n = -1 : dn : 1; +t = -1 : dt : 1; +f = 5; +fs = 50; +x = cos(2*%pi*f*t); +y = cos(2*%pi*(f/fs)*n); +subplot(211); +plot2d(t, x); +subplot(212); +plot2d3(n, y);