-
Notifications
You must be signed in to change notification settings - Fork 1
/
addsj.m
44 lines (40 loc) · 1.26 KB
/
addsj.m
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
function out = addsj( I,fz,rc1,jj,wz )
%Add charge discharge triangular wave¡£IFor the input signal, rc1 is the 1/4
%peak valley distance, ...
% fz is the amplitude percentage, jj is the spacing, ...
% and wz is the position where the charge discharge triangular wave is added
N=length(I);
asj=zeros(1,N);
big=max(I);
e=fix(big*fz); %Conversion of amplitude percentage to actual amplitude
len=rc1*40+jj; %Length of single positive and negative phase charging and discharging waveform
n=fix(N/len);
sk=fix(cfdian(e,rc1,rc1*3,jj));
sj=zeros(1,len);
for i=141:len
sj(i-140)=sk(i);
end
%--------------------------------------
switch wz %Determine the position of adding charge discharge triangular waves based on wz
case 0
for i=1:n
asj((i*len-len+1):i*len)=sj(1:len);
end
case 1
for i=1:fix(n/3)
asj((i*len-len+1):i*len)=sj(1:len);
end
case 2
for i=fix(n/3):fix(n/3*2)
asj((i*len-len+1):i*len)=sj(1:len);
end
case 3
for i=fix(n/3*2):n
asj((i*len-len+1):i*len)=sj(1:len);
end
otherwise
for i=fix(n/2):n
asj((i*len-len+1):i*len)=sj(1:len);
end
end
out=I+asj;