selection of specific data from graph and extract data

4 visualizzazioni (ultimi 30 giorni)
%For given graph only peck values between 10 and 20hz is valuble and i like to extract phase value for specific point.
%Right now my peck function is taking all the small changes, is there any way i can pass some filter or anything?
%Code:
header = 9;
delimiter = '\t';
ind = 1:100;
for i = 1:4
filname = sprintf('H1, 2_I1sv%05d.txt',i);
dat(i) =importdata(filname,delimiter,header);
FRFdata = dat(i).data;
f = FRFdata(:,1);
a = FRFdata(:,2);
b = FRFdata(:,3);
amp = sqrt(a.^2 + b.^2);
pha = (180/pi)* atan2(b,a);
[Ypk,Xpk,Wpk1,Ppk] = findpeaks(amp(ind));
figure(i)
subplot(2,1,1),plot(f,amp,f(Xpk),Ypk,'dr')
grid on
ylabel('Amp')
xlim([0 40])
ylim([0 2.4])
subplot(2,1,2),plot(f,pha)
grid on
xlim([0 40])
xlabel('Hz')
ylabel('Phase')
end
%I am doing FRF analysis to find vibration modes

Risposta accettata

Star Strider
Star Strider il 14 Mar 2023
The findpeaks function has a number of name-value pair arguments that can be used to return only selected information.
See if:
[Ypk,Xpk,Wpk1,Ppk] = findpeaks(amp(ind), 'MinPeakProminence',0.5);
does what you want.
I also tweaked your code a bit to make it abit mor efficient, specifically using readmatrix and changing ‘amp’ and ‘pha’
header = 9;
delimiter = '\t';
ind = 1:100;
i = 1;
% for i = 1:4
% filname = sprintf('H1, 2_I1sv%05d.txt',i);
filname = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323755/H1,%202_I1sv00001.txt';
% dat(i) =importdata(filname,delimiter,header);
FRFdata = readmatrix(filname, 'HeaderLines',9);
% FRFdata = dat;
f = FRFdata(:,1);
a = FRFdata(:,2);
b = FRFdata(:,3);
amp = hypot(a,b); % Changed
pha = atan2d(b,a); % Changed
[Ypk,Xpk,Wpk1,Ppk] = findpeaks(amp(ind), 'MinPeakProminence',0.5); % Changed
figure(i)
subplot(2,1,1),plot(f,amp,f(Xpk),Ypk,'dr')
grid on
ylabel('Amp')
xlim([0 40])
ylim([0 2.4])
subplot(2,1,2),plot(f,pha, f(Xpk),pha(Xpk),'dr') % Changed
grid on
xlim([0 40])
xlabel('Hz')
ylabel('Phase')
% end
.
  7 Commenti
AL
AL il 15 Mar 2023
I have solved the issue.
% Combine the results from all files into a single table
all_results = table();
for i = 1:num_files
% Add the results for the current file to the table
curr_results = table(freq{i}, Ypkc{i}, pha_{i}, Xpkc{i}, ...
'VariableNames', {'Frequency', 'PeakAmplitude', 'Phase', 'PeakLocation'});
curr_results = sortrows(curr_results, 'Frequency','ascend');
% Add a suffix to the variable names to avoid duplicates
suffix = ['_file' num2str(i)];
curr_results.Properties.VariableNames = strcat(curr_results.Properties.VariableNames, suffix);
all_results = [all_results curr_results]; % Concatenate horizontally
end
% Display the final table
disp(all_results);
clear a amp b dat delimiter f filname freq FRFdata suffix curr_results Results;
clear header i ind mpp mxidx Ppk Ppkc pv Wpk Wpkc Xpk Xpkc Ypk Ypkc pha pha_ num_files;
Have a wonderful day. Thank you so much for your effort and it was a good experience learning new things with you.
Star Strider
Star Strider il 15 Mar 2023
As always, my pleasure!
It appears that you got everything working the way you want!
You can put the file name in the sgtitle if you want to:
sgtitle("File: H1, 2\_I1s" + i + "v.txt")
.The backslant (\) is necessary to ‘escape’ the underscore so that it prints as an underscore and does not subscript the ‘I’ that follows it.
.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by