File: conv.dem.sce

package info (click to toggle)
scilab 6.0.1-10%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 365,292 kB
  • sloc: xml: 827,376; cpp: 273,125; ansic: 216,672; java: 190,706; fortran: 90,783; ml: 24,107; tcl: 16,853; sh: 13,608; makefile: 9,556; lex: 1,615; perl: 1,566; yacc: 1,263; php: 690; cs: 614
file content (43 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2012 - INRIA - Serge STEER
//
// Copyright (C) 2012 - 2016 - Scilab Enterprises
//
// This file is hereby licensed under the terms of the GNU GPL v2.0,
// pursuant to article 5.3.4 of the CeCILL v.2.1.
// This file was originally licensed under the terms of the CeCILL v2.1,
// and continues to be available under such terms.
// For more information, see the COPYING file which you should have received
// along with this program.

function demo_conv()

    //create a signal
    dt=0.02;
    t=0:dt:1;
    f=1;// frequency in Hertz
    y=sin(2*%pi*f*t)+0.1*rand(t);
    scf(1000);clf;
    demo_viewCode("conv.dem.sce");
    drawlater()

    subplot(211)
    plot(t,y) //given signal
    //low pass 8 points wfir filter
    Smooth=[0.1197912,0.1242239,0.1272323,0.1287527,0.1287527,0.1272323,0.1242239,0.1197912];
    ys=conv(y,Smooth,"same");
    plot(t,ys,"r")// filtered signal
    legend([_("given noisy signal"),_("filtered signal")])
    title(_("Signal"))

    subplot(212)
    //2 points derivative using convolution
    plot(t(1:$-1),conv(ys,[1,-1],"valid")/dt,"r")
    //3 points derivative  using convolution
    plot(t(1:$-2),conv(ys,[1, 0,-1]/2,"valid")/dt,"g")
    legend([_("2 points convolution"),_("3 points convolution")])
    title(_("Signal derivative estimate"))
    drawnow()
endfunction
demo_conv()
clear demo_conv