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')

Answer by KALYAN ACHARJYA
on 14 Jul 2019

Edited by 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:

KALYAN ACHARJYA
on 14 Jul 2019

OK, then please do explain

blue signal should be lagging green signal but it is doing opposite

Why?

Sayan
on 14 Jul 2019

KALYAN ACHARJYA
on 14 Jul 2019

Sorry, I have no idea, please do wait for experts answers or comments.

Sign in to comment.

Answer by Sayan
on 16 Jul 2019

Problem solved !

The error was in the following loop:

count = 1;

for t = 0.0001:1/(50*fs):0.0003

y1(count) = subs(yn1);

y2(count) = subs(yn2);

count = count+1;

end

Instead of the above loop, the code should be like :

t = 0.0001:1/(50*fs):0.0003

y1 = subs(yn1);

y2 = subs(yn2);

The exact reason behind the code is not known to me.

Hope any MATLAB expert helps in this matter.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.