Determine the direction of travelling waves in Fourier Analysis

5 views (last 30 days)
% I am conducting a FFT analysis and i I observed that there is travelling
% wave. Please, how do I determine the direction of the travelling waves?
% Compute the phase of the FFT: theta_phase = angle(Ytheta);
% Compute the mean phase difference: p = polyfit(f, theta_phase, 1);
% slope = p(1); % The slope of the phase vs. frequency plot
% Store the mean phase difference: mean_phase_diff(i) = slope;
% Then I test the mean_phase_diff(i) > 0 implies rightward direction or if
% mean_phase_diff(i) < 0 leftward direction. I am wondering if there is a
% better way or function to do this.
clear
%close all
pars.W = 20e-6;
pars.D = 2e-6;
% time discretisation - start, step and end
t = 0:0.025:5;
% Extract theta data
loaded_data = load('thetam.mat');
thetam = loaded_data.thetam;
% Sample frequency
Fs = 1/(t(2) - t(1));
% Number of samples
L = length(t);
% Number of ramp slopes
num_ramp_slopes = size(thetam, 1);
% Frequency vector for FFT
f = (-L/2 : L/2-1) * (Fs / L);
% Loop through each ramp_slope
for i = 1:num_ramp_slopes
% Extract the theta data for the current ramp_slope
theta_data = thetam(i, :);
% Compute the FFT of the theta data
Ytheta = fft(theta_data);
% Shift zero frequency component to center
Ytheta = fftshift(Ytheta);
end
% Plot the magnitude of the FFT for the first ramp_slope
fig1 = figure;
plot(f, abs(fftshift(fft(thetam(1, :)))), 'LineWidth', 0.8);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('FFT Magnitude for Ramp Slope 1');
xlim([-Fs/2 Fs/2]);
grid on;

Answers (1)

Ayush
Ayush on 14 Sep 2024
Hi there
You can use the approach of analyzing the phase slope to determine the direction of traveling waves using FFT as:
clear
%close all
% Parameters
pars.W = 20e-6;
pars.D = 2e-6;
% Time discretization: start, step, and end
t = 0:0.025:5;
% Load theta data
loaded_data = load('thetam.mat');
thetam = loaded_data.thetam;
% Sample frequency
Fs = 1/(t(2) - t(1));
% Number of samples
L = length(t);
% Number of ramp slopes
num_ramp_slopes = size(thetam, 1);
% Frequency vector for FFT
f = (-L/2 : L/2-1) * (Fs / L);
% Initialize storage for mean phase differences
mean_phase_diff = zeros(1, num_ramp_slopes);
% Loop through each ramp_slope
for i = 1:num_ramp_slopes
% Extract the theta data for the current ramp_slope
theta_data = thetam(i, :);
% Compute the FFT of the theta data
Ytheta = fft(theta_data);
% Shift zero frequency component to center
Ytheta = fftshift(Ytheta);
% Compute the phase of the FFT
theta_phase = angle(Ytheta);
% Compute the mean phase difference using linear fit
p = polyfit(f, theta_phase, 1);
slope = p(1); % The slope of the phase vs. frequency plot
% Store the mean phase difference
mean_phase_diff(i) = slope;
% Determine the direction based on the slope
if slope > 0
direction = 'rightward';
else
direction = 'leftward';
end
fprintf('Ramp Slope %d: Mean Phase Difference = %.3f, Direction = %s\n', i, slope, direction);
end
% Plot the magnitude of the FFT for the first ramp_slope
fig1 = figure;
plot(f, abs(Ytheta), 'LineWidth', 0.8);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('FFT Magnitude for Ramp Slope 1');
xlim([-Fs/2 Fs/2]);
grid on;
I hope this helps!

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!