While plotting, reverse phase shift of square wave is observed?
3 views (last 30 days)
Show older comments
I have generated an array S1 containing fourier coefficient of a square wave upto 20th harmonics. From the phase shifting property of Fourier Transform, I have generated another array S2 containing fourier coefficient of a square wave delayed by DTs, upto 20th harmonics. But while reconstructing the square wave it shows phase lead instead of lag. In the picture attached, blue signal should be lagging green signal but it is doing opposite. I apologize beforehand if there is any silly mistake from my part.
I have used the following property:
The code is as follows:
%% Square Wave
% S1 is array of Fourier coefficient of a square wave. S2 is array of
% fourier coefficient of phase shifted square wave. Phase shift is denoted
% by D.
nhmax = 20;% -nhmax to + nhmax number of harmonics considered for Toeplitz
D = 0.2; % Duty of the phase shift. D*Ts is the phase shift time.
fs = 15000;
ws = 2*pi*fs;
nh = 0;
S1 = zeros(1,2*nhmax+1);
S2 = zeros(1,2*nhmax+1);
count = 1;
for nh = -nhmax:nhmax
S1_nh = -1i/(nh*pi)*(1-cos(nh*pi));
S2_nh = exp(-1i*nh*2*pi*D)*S1_nh;
S1(count) = S1_nh;
S2(count) = S2_nh;
count = count+1;
end
S1(nhmax+1) = 0; %Entering coefficient of dc
S2(nhmax+1) = 0; %%Entering coefficient of dc
%% Time Domain Signal Construction
%Generating P matrix
syms t
count = 1;
for nh = -nhmax : nhmax
P(count) = exp(1i*nh*ws*t);
count = count + 1;
end
yn1 = P * S1';
yn2 = P * S2';
count = 1;
for t = 0.0001:1/(50*fs):0.0003
y1(count) = subs(yn1);
y2(count) = subs(yn2);
count = count+1;
end
t = 0.0001:1/(50*fs):0.0003;
plot(t,y1,'g',t,y2,'b')
0 Comments
Answers (3)
KALYAN ACHARJYA
on 14 Jul 2019
Edited: KALYAN ACHARJYA
on 14 Jul 2019
Your Code:
S2_nh = exp(-1i*nh*2*pi*D)*S1_nh;
%...........^^^
I have removed the - sign, as y2 (blue signal) depents on S2_nh, rest parameters are same for both y1 & y2
Modification:
S2_nh = exp(1i*nh*2*pi*D)*S1_nh;
%...........^- sign removed
Result:
4 Comments
KALYAN ACHARJYA
on 14 Jul 2019
Sorry, I have no idea, please do wait for experts answers or comments.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!