How to plot peaks at higher resolution but at low frequency inbetween?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ben van Zon
le 1 Déc 2023
Modifié(e) : Infinite_king
le 12 Déc 2023
I'm trying to plot the Airy transmission function for a cavity but I'm encountering issues when I try to plot them.
The peaks are way too low resolution, while the area inbetween them is 0 for a long time and doesnt need such a high resolution; how do I change this?
As shown above, what the peak looks like.
And below is the full image, but the peak is missing quite a bit of its height at the peak as that should be 100%
1 commentaire
Mathieu NOE
le 4 Déc 2023
why not increase the frequency vector resolution, eventually only where it makes sense (rane -0.02 to +0.02 MHz) ?
Réponse acceptée
Infinite_king
le 12 Déc 2023
Modifié(e) : Infinite_king
le 12 Déc 2023
Hi Ben van Zon,
I understand that you are trying to plot Airy transmission function for some cavity and was not able to see the peaks clearly in the plot.
Solution 1 – Plot the data using ‘findpeaks’ function.
‘findpeaks’ function will place a marker at every peak, so we can see the peaks clearly. Refer the following code snippet,
% creating sample data
data(1:1000) = 0;
data(500) = 100;
% plotting data
plot(data);
% using findpeaks to plot the data
figure(2) % create another figure
findpeaks(data);
% get the current axis
axis = gca;
% Now, change the axis properties
% For example updating lables
axis.XLabel.String = 'Frequency [MHz]';
axis.YLabel.String = 'Intensity%';
Solution 2 – Get the locations of the peaks and plot the area surrounding the peaks for better view.
‘findpeaks’ function will return the location of the peaks. Using this location, we can plot the graph surrounding the peaks for better view. Refer the following code snippet.
% creating sample data
data(1:1000) = 0;
data(250) = 100;
data(750) = 200;
% plotting data
plot(data);
% using findpeaks to find the peak locations
[peaks,locations] = findpeaks(data);
% width before and after peak
width = 2; % 10 data points
for i = 1:numel(locations)
% take care of corner conditions
sub_data = data((locations(i)-width):(locations(i)+width));
figure;
plot(sub_data);
% get the current axis
axis = gca;
% Now, change the axis properties
% For example updating lables
axis.XLabel.String = 'Frequency [MHz]';
axis.YLabel.String = 'Intensity%';
% changing scale
axis.YLim = [-20 300];
end
For more information on ‘findpeaks’ and ‘axis’, refer the following MATLAB documentation,
- https://www.mathworks.com/help/matlab/ref/gca.html
- https://www.mathworks.com/help/signal/ref/findpeaks.html
Hope this is helpful.
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!