How to plot peaks at higher resolution but at low frequency inbetween?

7 次查看(过去 30 天)
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%

采纳的回答

Infinite_king
Infinite_king 2023-12-12
编辑:Infinite_king 2023-12-12
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,
  1. https://www.mathworks.com/help/matlab/ref/gca.html
  2. https://www.mathworks.com/help/signal/ref/findpeaks.html
Hope this is helpful.

更多回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by