Returning coordinates from a plot function
Afficher commentaires plus anciens
Hello fellow members,
I want to return the x coordinate as a stored value (in my case the frequency in Hz) at the point that the plot of F,db (which is the difference between the plots of Px_f and Px_g as a function of F) has the maximum value (or in other words, the maximum difference). Obviously I can get the max by max(db) which returns the max value, however I need the frequency (along the x-axis) at that point.
data1= 65536x1 double array data2= 65536x1 double array
Just for some background. Data1 is faulty bearing data and data2 is good bearing data recorded from a data logger.
Code is below (If I haven't explained myself correctly then please let me know).
Thanks for your help.
% code
fs=48000; % Sampling rate at 48000Hz
figure
[Px_f,F]=pwelch(data1,1000,500,[],fs);
plot(F,20*log10(Px_f),'r');
hold on
[Px_g,F]=pwelch(data2,1000,500,[],fs);
plot(F,20*log10(Px_g),'g');
hold on
db=20*log10(Px_f)-20*log10(Px_g);
plot(F,db,'k');
grid on
xlabel('Frequency (Hz)')
ylabel('Power/frequency (dB/Hz)');
title('Welch Power Spectrum Density')
legend('Faulty Bearing','Good Bearings','Variance','Location','best');
Réponse acceptée
Plus de réponses (1)
Honglei Chen
le 8 Août 2012
0 votes
I would also suggest you to take a look at findpeaks function in case you need to detect multiple peaks.
Catégories
En savoir plus sur Spectral Estimation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!