How to find corresponding frequencies for frequency magnitudes in FFT analysis
Show older comments
% I computed the fft for 10 values of xi and
% 10 values of l as shown below. I am trying to determine which values
% of xi and l oscillations occur. To achieve this, tried to find the
% maximum freq. and use it as a threshold, so that if frequency < threshold
% freq. then find the xi and l values that correspond to the frequency <
% threshold. Please can anyone help with this?
clc
clear all
%%
mydata =load('sol_data.mat');
% x and y
x =mydata.x;
y =mydata.y;
nx = length(x);
ny = length(y);
% xi and l
xival=mydata.xival;
lval =mydata.lval;
% theta
theta = mydata.theta;
X1 = mydata.X1;
Y1 = mydata.Y1;
% line in the HAN region
l = lval(end);
% x and y values at the centre of the channel
xm = (nx+1)/2;
ym = (ny+1)/2;
% Sampling frequency for planar and HAN regions
F = 1/(x(2)-x(1));
% Length of x planar ad HAN regions
L = length(x);
%% computing the fft
pfL = F/L*(0:L-1);
fig2 = figure(2);
for ixi=1:length(xival)
for il=1:length(lval)
YplanarHAN(:, ixi, il)= abs(fft(theta(:,ixi, il)));
hold on
plot(pfL, YplanarHAN(:, ixi, il))
end
end
% take the fftshift and exclude the zero values and remove the zero
% frequency
Fnotzero = [(-(L-1)/2):-1 1:(L-1)/2]*(F/L);
fig3 = figure(3);
for ixi=1:length(xival)
for il=1:length(lval)
% find the fft of theta
YfftplanarHAN(:, ixi,il) = abs(fftshift(fft(theta(:,ixi, il))));
% Remove the zero frequency
YfftnotzeroplanarHAN(:,ixi, il) = [YfftplanarHAN(1:((L-1)/2),ixi, il); YfftplanarHAN(((L+3)/2):L, ixi, il)];
% plot
hold on
plot(Fnotzero, YfftnotzeroplanarHAN(:, ixi, il), 'LineWidth',1)
end
end
%% Calculate the peak frequency
% length of fftshift of the FFT of the theta
LFnotzero = 1:numel(Fnotzero);
% Calculate the peak frequency
for ixi=1:length(xival)
for il=1:length(lval)
[peak_mag(:, ixi, il), locs(:, ixi, il)] = findpeaks(abs(YfftnotzeroplanarHAN(LFnotzero)), 'MinPeakProminence',0.25);
end
end
% Frequency corresponding to the peak magnitudes
Freq_peak = Fnotzero(locs);
% Maximum frequency for each xi
Max_freq = max(Freq_peak(:));
% Threshold frequency
threshold_max = max(Freq_peak(:));
% Test
test1 = abs(Fnotzero) < threshold_max;
[xivals1, Lvals1] = find(test1);
xi_1 = xival(xivals1);
Lv_1 = lval(Lvals1);
Accepted Answer
More Answers (0)
Categories
Find more on Transforms 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!











