While plotting, reverse phase shift of square wave is observed?

2 visualizaciones (últimos 30 días)
Sayan
Sayan el 13 de Jul. de 2019
Respondida: Sayan el 16 de Jul. de 2019
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')

Respuestas (3)

KALYAN ACHARJYA
KALYAN ACHARJYA el 14 de Jul. de 2019
Editada: KALYAN ACHARJYA el 14 de Jul. de 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 comentarios
Sayan
Sayan el 14 de Jul. de 2019
I just want to lag the second signal from the first signal. Ihave studied about phase shifting property of fourier transform. I have mentioned that in my question. According to the property lag induces negative sign and lead induces positive sign. Kindly correct me if I am wrong. And thus I feel that negative sign would be there. But I am no way able to justify the reverse phase shift obtained in the plot. I am seriously confused or I am missing a very simple thing. Please help in this regard.
KALYAN ACHARJYA
KALYAN ACHARJYA el 14 de Jul. de 2019
Sorry, I have no idea, please do wait for experts answers or comments.

Iniciar sesión para comentar.


Sayan
Sayan el 15 de Jul. de 2019
Can anyone please help me with the solution ?

Sayan
Sayan el 16 de Jul. de 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.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by