How to find the peaks?
Ältere Kommentare anzeigen
How to find the peak values of the curve. I try, but not getting result.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a program for 1-D Photonic crystal
% For Photonic band structure calculation and Transmission Spectrum
% This program uses Transfer Matrix Method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
close all
tic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialization of parameters
dB=7778e-9; % Thickness of Second Layer
dA=5303e-9; % Thickness of First Layer
nA=3.3; % Refractive index of First Layer
nB=2.25; % Refraive index of Second Layer
n0=1; % Refractive index of Incident and transmission medium
c=3e8; % Velocity of Light (m/s)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Frequency Range
frequncy=0.1:0.001:50; % Frequncy in THz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for loop=1:length(frequncy)
% angular frequency
w=2*pi*frequncy*1e12;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d=dA+dB; DA=((w(loop))/c)*dA*nA; DB=((w(loop))/c)*dB*nB;
m11=cos(DA); m12=-1i*sin(DA)/nA; m21=-1i*nA*sin(DA); m22=cos(DA); mA=[m11 m12; m21 m22];
l11=cos(DB); l12=-1i*sin(DB)/nB; l21=-1i*nB*sin(DB); l22=cos(DB); mB=[l11 l12; l21 l22];
Da=((w(loop))/c)*(dA/2)*nA; Db=((w(loop))/c)*(dB/2)*nB;
ma11=cos(Da); ma12=-1i*sin(Da)/nA; ma21=-1i*nA*sin(Da); ma22=cos(Da); ma=[ma11 ma12; ma21 ma22];
lb11=cos(Db); lb12=-1i*sin(Db)/nB; lb21=-1i*nB*sin(Db); lb22=cos(Db); mb=[lb11 lb12; lb21 lb22];
% Unit cell
m10=(mA*mB);
% Whole 1-D PC structure
M10=(mb*mA*mb)^2*(ma*mB*ma)^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reflection and Transmission
T10(loop)=(2*n0/(n0*M10(1,1)+n0*n0*M10(1,2)+M10(2,1)+n0*M10(2,2)));Transmission10(loop)=(T10(loop)*conj(T10(loop)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g=double(Transmission10(:));
[t_max,loc]=findpeaks(g);
end
plot(frequncy,Transmission10(:),'LineWidth',1);hold on;
plot(frequncy,double(Transmission10),'or');hold off
ylim([0,1])
toc
1 Kommentar
akshatsood
am 5 Sep. 2023
Bearbeitet: akshatsood
am 5 Sep. 2023
Hi GULZAR,
I understand that you are facing an error while determining the peak values of a curve. I investigated your code and got an error message which points towards invalid input being supplied to the findpeaks function. As per the documentation page, the input data must be real and needs to have at least 3 elements to determine the peak values of a curve. In your case, you have supplied g to the findpeaks function during the first iteration of the loop which is a single double value causing the error you observe on running the code.
To address this, you can shift the following two statements after the for loop to compute the peak values of the curve.
g=double(Transmission10(:));
[t_max,loc]=findpeaks(g);
I hope this helps.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Descriptive Statistics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!