Why fft don't find oscillations ?
9 views (last 30 days)
Show older comments
I'm trying to find an FTT of an oscillatory data. In the first figure, you can observed an isolated white region. In this region I expect to see an oscillation instead I am seeing no oscillation. I set a threshold to determine whether there is oscillation or not. But even when I adjusted the threshold, the code can't still find the oscillation the isolated white region. I tried to explore by plotting the data around the isolated white region (i.e. in fig 3). You can see there is a bit oscillation around the white region. Please does one knows what might be the problem. I didn't use HANN widow because, it can't figure out what it does.
active_flow = load('sol_active_flow_varying_xiL.mat');
data1 = load('X1'); data2 = load('Y1')
% values xarray and yarray
x =active_flow.xvals;
y =active_flow.yvals;
% activity values and line at in the HAN region
xival=active_flow.xivals;
lval =active_flow.Lvals;
% extract parameters
paras = active_flow.pars;
% line in the HAN region
l = paras.L;
% width of the rectangle
w =paras.W;
% height of the rectangle
d = paras.D;
% extract dependent variables theta
theta = active_flow.thetaxmym;
X1 = data1.X1;
Y1 = data2.Y1;
% HAN region: using the mesh grid
HAN = (X1 >= -l/2 & X1 <= l/2);
% Index position of -l/2 and l/2
lstop=find(HAN(1,:),1,'last');
% x arrays in the right planar region
xplanarright = x(lstop:end);
%% Sampling Frequency
% Sampling frequency left HAN planar
Fsplanarright = 1/(xplanarright(2)-xplanarright(1));
% Length of x left planar region
Lplanarright = length(xplanarright);
%% PLOTTING
%% Compute the fftshift
for ixi=1:length(xival)
for il=1:length(lval)
% fftshift of theta
thetafftplanarright(:, ixi,il) = abs(fftshift(fft(theta(lstop:end,ixi, il))));
% shift the frequencies
Fshiftplanarright=(-Lplanarright/2:Lplanarright/2-1)*(Fsplanarright/Lplanarright);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate the Peaks and Frequencies
Iplanarright = 1:numel(xplanarright);
for k1 = 1:size(thetafftplanarright,2) % this get the xi values
for k2 = 1:size(thetafftplanarright, 3) % this get the l values
% planar right region
[peak_magplanarright, frequenciesplanarright] = findpeaks(thetafftplanarright(Iplanarright,k1,k2), Fshiftplanarright);
[ifreqplanarright]=find(peak_magplanarright==max(peak_magplanarright));
freq_maxpeakplanarright(k1,k2)=frequenciesplanarright(ifreqplanarright(1));
mag_maxpeakplanarright(k1,k2)= peak_magplanarright(ifreqplanarright(1));
end
end
%% DETERMINE OSCILLATION FOR ENTIRE REGION
% Define threshold for oscillation detection
threshold_freq = 3e5;
threshold_mag = 4.7;
% Planar right
osc_xivalplanarright = [];
osc_lvalplanarright = [];
non_osc_xivalplanarright = [];
non_osc_lvalplanarright = [];
%% Planar right: Iterate over each frequency peak
for k1 = 1:size(freq_maxpeakplanarright, 1)
for k2 = 1:size(freq_maxpeakplanarright, 2)
peak_freqplanarright = freq_maxpeakplanarright(k1, k2);
peak_magplanarright = mag_maxpeakplanarright(k1,k2);
% Check if peak frequency exceeds threshold
if abs(peak_freqplanarright) > threshold_freq && abs(peak_magplanarright)>threshold_mag
osc_xivalplanarright(end+1) = xival(k1);
osc_lvalplanarright(end+1) = lval(k2);
else
non_osc_xivalplanarright(end+1) = xival(k1);
non_osc_lvalplanarright(end+1) = lval(k2);
end
end
end
%% Plotting
[C,h1] = contourf(lval,xival,freq_maxpeakplanarright, 'ShowText','off','edgecolor','none');
c.TickLabelInterpreter='latex';
c.Label.String = 'frequency';
c.Label.Interpreter = 'latex';
colormap bone
clabel(C,h1)
set(gca,'clim',[min(min(freq_maxpeakplanarright)) max(max(freq_maxpeakplanarright))]);
hold on
% plot xival and lval for oscillation and non_oscillation
for i=1:length(non_osc_lvalplanarright)
p4a = plot(non_osc_lvalplanarright(i), non_osc_xivalplanarright(i), 'c.', 'LineWidth', 2, 'MarkerSize', 10);
end
for i=1:length(osc_lvalplanarright)
p4b = plot(osc_lvalplanarright(i), osc_xivalplanarright(i), 'r.', 'LineWidth', 2, 'MarkerSize', 10);
end
% fft and the function around the isolated region
fig11 = figure(11);
nxi = linspace(xival(3), xival(12),10);
for ixi = 1:length(nxi)
subplot(5, 2, ixi);
plot(Fshiftplanarright, thetafftplanarright(:, ixi, 13), 'LineWidth',1)
xlabel('frequency','Interpreter','latex')
ylabel('magnitude','Interpreter','latex');
xlim([min(Fshiftplanarright) max(Fshiftplanarright)])
title(['$\xi$ =', num2str(nxi(ixi)), '$, l$ = ', num2str(lval(13))], 'Interpreter','latex');
end
fig12 = figure(12);
for ixi = 1:length(nxi)
subplot(5, 2, ixi);
plot(xplanarright, squeeze(theta(lstop:end, ixi, 13)))
xlabel('$x$','Interpreter','latex')
ylabel('tilt angle, $\theta$','Interpreter','latex');
xlim([min(xplanarright) max(xplanarright)])
title(['$\xi$ =', num2str(nxi(ixi)), '$, l$ = ', num2str(lval(13))], 'Interpreter','latex');
end
5 Comments
Matt J
on 19 Mar 2024
I don't think anybody understands what your many variables and plots mean. But it's a frequency plot, so there shouldn't be oscillation. The Fourier transform of an oscillatory signal is a peak.
Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!