Phase shift correct estimation
이전 댓글 표시
Hello
I'm in need of some help if you please.
In the attached text file I have 3 columns, column 1 is the altitude from 20 to 110 km with an interval of 0.1km.
the other 2 columns are signals.
Please I want to calculate the phase shift between the signals in columns 2 and 3 as a function of the altitude to range from 0 to pi.
Here is a portion of the code for further understanding :
Please, any solution is welcome.
Pathf = "Signal_Test_Data.txt";
data = flipud(load(Pathf));
tt = data(:, 1);
Xt = data(:, 2);
Yt = data(:, 3);
tx = (data_alt>=20 & data_alt<=110);
t = tt(tx);
X = Xt(tx);
Y = Yt(tx);
figure; plot(t, x, t, y);
legend('x','y');
xh = hilbert(x);
yh = hilbert(y);
xphase = unwrap(angle(xh));
yphase = unwrap(angle(yh));
figure; plot(t, xphase, t, yphase,'.');
phase_diff = wrapToPi(xphase-yphase);
figure; plot(t, phase_diff, '-');
댓글 수: 5
Paul
2023년 5월 25일
Hi TTA,
What is the concern with the code that you have? Just looking at it, what are the lower case variables x and y? Shouldn't those be upper case in the plot and hilbert functions?
TTA
2023년 5월 25일
Paul
2023년 5월 26일
And what is the concern about the code? Is it not yielding the expected result?
TTA
2023년 5월 26일
David Goodmanson
2023년 5월 26일
Hi TTA,
Since phase shift runs from -pi to pi, or 0 to 2pi, or any other limits you choose whose range is 2pi, do you have a reason for the expectation that the range of phase angle in this case will have a range of only pi? The data does not appear to be cooperating.
답변 (1개)
Sulaymon Eshkabilov
2023년 5월 25일
편집: Sulaymon Eshkabilov
2023년 5월 25일
Here is how to compute the phase difference between two signals:
Pathf = 'Signal_Test_Data.txt';
data = flipud(load(Pathf));
tt = data(:, 1);
Xt = data(:, 2);
Yt = data(:, 3);
t = tt(:);
X = Xt(:);
Y = Yt(:);
figure;
plot(t, X, t, Y)
legend('x','y')
title('Data')
% Remove any offsets
X = X-mean(X);
Y = Y-mean(Y);
Tstep = 0.1; % Step size
Fs = 1/Tstep; % Sampling frequency
% Calculate FFT:
fft_x = fft(X);
fft_y = fft(Y);
N = ceil((numel(t)+1)/2);
freq = (0:N-1)*Fs/numel(t);
figure
subplot(211)
plot(freq, abs(fft_x(1:N)))
xlabel('Freq')
ylabel('|X|')
title('FFT of x and y signals')
subplot(212)
plot(freq, abs(fft_y(1:N)))
xlabel('Freq')
ylabel('|Y|')
% Find max values of the computed FFT of x and y signals
[Max_X, IDX_X] = max(abs(fft_x));
[Max_Y, IDX_Y] = max(abs(fft_y));
Phase_X = angle(fft_x(IDX_X));
Phase_Y = angle(fft_y(IDX_Y));
Phase_Diff = Phase_X-Phase_Y;
fprintf('Estimated phase shift: %f [rad] \n', Phase_Diff)
fprintf('Estimated phase shift: %f [deg] \n', rad2deg(Phase_Diff))
카테고리
도움말 센터 및 File Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

