selection of specific data from graph and extract data
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
AL
am 14 Mär. 2023
Kommentiert: Star Strider
am 15 Mär. 2023
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1323775/image.png)
%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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 14 Mär. 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 Kommentare
Star Strider
am 15 Mär. 2023
As always, my pleasure!
It appears that you got everything working the way you want!
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.
.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!