필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Sayan
Sayan 2019년 7월 13일
답변: Sayan 2019년 7월 16일
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')

답변 (3개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 14일
편집: KALYAN ACHARJYA 2019년 7월 14일
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
Sayan
Sayan 2019년 7월 14일
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 2019년 7월 14일
Sorry, I have no idea, please do wait for experts answers or comments.

댓글을 달려면 로그인하십시오.


Sayan
Sayan 2019년 7월 15일
Can anyone please help me with the solution ?

Sayan
Sayan 2019년 7월 16일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by