summaryrefslogtreecommitdiff
path: root/716/CH4/EX4.6/Solved_Ex_4_6.sce
blob: 46e4a1fc715f09d62c427a9c5eb770b9f13cc616 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//Determine the trigonometric form of fourier series of Given Signal
clc;
clear;
T=8;//Defining Time Period
A=2;//Defining Amplitude

t=-T:0.01:T;
w0=2*%pi/T;

function x=f(t),x=(4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T) ,endfunction  //given continuous signal
plot(t,f);
xlabel("time");
ylabel("x(t)");

//Check if Signal is even or odd
if(f(t)==f(-1*t))
    
        disp('even');
        disp('bn=0');
        function x=f(t),x=(4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T) ,endfunction//redefining signal
        //Evaluation of a0 & an
        //Evaluation of a0:       
        a0=4*intg(0,T/2,f)/T;  //definite integral of 'f' from 0 to T/2
        disp(a0,'a0');

        //Evaluation of an:
        disp('due to convergence,for all even values of n,an=0');
        disp('for odd values of n,an values are=>');
        y0=a0/2+zeros(1,length(t));
        for n=1:2:15                 //changing the end value of n,we can get more numbers of an
        function xn=f1(t),xn=((4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T)).*cos(n.*w0.*t) ,endfunction 
        an=4*intg(0,T/2,f1)/T;
        disp(n,'a');
        disp(an);
        y0=y0+an.*cos(n*w0.*t);
        xset('window',1);
        subplot(2,4,(n+1)/2);
        plot(t,y0);
        xtitle('signal x(t) for few harmonics','time t','x(t)');
        end
        
    else if(f(t)==(-1*f(-1*t)))
    
        disp('odd signal=>a0=an=0');
        function x=f(t),x=(4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T) ,endfunction//redefining signal
        disp('due to convergence,for all even values of n,bn=0');
        disp('for odd values of n,bn values are=>');
        //Evaluation of bn=>
        y0=zeros(1,length(t));
        for n=1:2:15                  //changing the end value of n,we can get more numbers of bn
        function x=f1(t),x=((4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T)).*sin(n.*w0.*t) ,endfunction
        bn=4*intg(0,T/2,f1)/T;
        disp(n,'b');
        disp(bn);
        y0=y0+bn.*sin(w0.*n.*t);
        xset('window',1);
        subplot(2,4,(n+1)/2);
        plot(t,y0);
        xtitle('signal x(t) for few harmonics','time t','x(t)');
        end
    
    else
    
        disp('neiher even nor odd');
        function x=f(t),x=(4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T) ,endfunction//redefining signal
        //Evaluation of a0,an & bn
        //Evaluation of a0:
        disp('due to convergence,for all even values of n,an=0');
        disp('for odd values of n,an values are=>');
        a0=0;  //definite integral of 'f' from 0 to T/2
        disp(a0,'a0');

        //Evaluation of an:
        y1=a0/2+zeros(1,length(t));
        for n=1:2:13                 //changing the end value of n,we can get more numbers of an
        function xn=f1(t),xn=((4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T)).*cos(n.*w0.*t) ,endfunction 
        an=4*intg(0,T/2,f1)/T;
        disp(n,'a');
        disp(an);
        y1=y1+an.*cos(n*w0.*t);
        xset('window',1);
        subplot(2,4,(n+1)/2);
        plot(t,y1);
        xtitle('signal x(t) for few harmonics','time t','x(t)*xcos(n*w0*t)');
        end
    
        //Evaluation of bn=>
        y2=zeros(1,length(t));
        for n=1:1:8                  //changing the end value of n,we can get more numbers of bn
        function x=f1(t),x=((4*A/T*t+4*A).*(t>=-T & t<=-3*T/4)+(-4*A/T*t-2*A).*(t>-3*T/4 & t<=-T/4)+(4*A/T*t).*(t>-T/4 & t<=T/4)+(-4*A/T*t+2*A).*(t>T/4 & t<=3*T/4)+(4*A/T*t-4*A).*(t>3*T/4 & t<=T)).*sin(n.*w0.*t) ,endfunction
        bn=4*intg(0,T/2,f1)/T;
        disp(n,'b');
        disp(bn);
        y2=y2+bn.*sin(w0.*n.*t);
        xset('window',2);
        subplot(2,4,n);
        plot(t,y2);
        xtitle('signal x(t) for few harmonics','time t','x(t)*sin(n*w0*t)');
        end  
    y0=y1+y2;
    end
end

xset('window',2);
plot(t,y0);//x(t) signal till 15 harmonics
xtitle('signal x(t) for 15 harmonics','time t','x(t)');