Very simple script but the result is really strange


#1

Hey guys,

I am adjusting the Q analysis group provided by Lumerical to include FSR and other results. However, when i am trying to sort the resonance frequency in incremental order, the result mistakenly swaps freq 1 and freq 3.

Here is the excerpt of the script:

for(i=1:number_resonances)
{peak_value=findpeaks(tr_w,1);
 sort_w(i)=tr_w(peak_value);
 sort_Q(i)=tr_Q(peak_value);
 tr_w(peak_value)=0;
 ?tr_w/(2*pi);
 ?peak_value;
}

the result is this:

result: 
1.9746e+14  
2.00847e+14  
1.94073e+14  
2.04291e+14  
0  
1.90686e+14  
result: 
5  
result: 
1.9746e+14  
2.00847e+14  
1.94073e+14  
0  
0  
1.90686e+14  
result: 
4  
result: 
1.9746e+14  
0  
1.94073e+14  
0  
0  
1.90686e+14  
result: 
2  
result: 
1.9746e+14  
0  
0  
0  
0  
1.90686e+14  
result: 
3  
result: 
0  
0  
0  
0  
0  
1.90686e+14  
result: 
1  
result: 
0  
0  
0  
0  
0  
1.90686e+14  
result: 
1

#2

Dear @wang2430

I do not have access your codes neither your simulation file, but this might be due to the fact that findpeaks command sorts the peaks from largest to smallest. So, if the smallest frequency does not have the largest peak, it will be listed later.

I hope this answered your question but please let me know if you had any further questions.
Thanks


#3

Thank you for this.
I have also found a solution to this problem. I found that the Findpeaks function won’t return value at two boundaries even when two boundaries have larger value than those inside. I solved it by adding two zeros at each boundary.