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

조회 수: 5 (최근 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%
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2023년 12월 4일
why not increase the frequency vector resolution, eventually only where it makes sense (rane -0.02 to +0.02 MHz) ?

댓글을 달려면 로그인하십시오.

채택된 답변

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개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by