I am getting error in the line MM=length(FBG).Please tell me what is the problem?
1 view (last 30 days)
Show older comments
function [WLC, BW]=f_FBG_BW(WL, FBG, BWP);
% this function find the FBG bandwidth at a given power level
% Inputs:
% WL: wavelength
% FBG: FBG power
% BWP: power level at which the BW is calculated
% Output
% WLC: center wavelength
% BW: Bandwidth
% First created by Prof. Haiying Huang at Univeristy of Texas Arlington
MM=length(FBG);
plot(WL, FBG,'b', WL, BWP*ones(size(WL)), 'r');
grid on;
hold on;
FBG=FBG-BWP;
FBGM=FBG(1:MM-1,1).*FBG(2:MM,1);
WL0=[];
index=find(FBGM==0); % find data point with zero value
if(~isempty(index))
index0=find(FBG(index)==0);
if (~isempty(index0))
WL0=[WL0; WL(index(index0))];
end
index0=find(FBG(index+1)==0);
if(~isempty(index0))
WL0=[WL0; WL(index(index0)+1)];
end
plot(WL0, BWP(size(WL0)), 'kd');
end
index=find(FBGM<0); % find zero-crossings
if(~isempty(index))
WL_Zc=[WL(index), WL(index+1)];
FBG_Zc=[FBG(index), FBG(index+1)];
WL0=[WL0;WL_Zc(:,1)-FBG_Zc(:,1).*(WL_Zc(:,2)-WL_Zc(:,1))./(FBG_Zc(:,2)-FBG_Zc(:,1))];
plot(WL0, BWP*ones(size(WL0)), 'k*');
end
% if(length(WL0)~=2)
% disp('warning: more than two intersection, take first & last for BW calculation');
% end
% WLC=(WL0(2)+WL0(1))/2;
% BW=WL0(2)-WL0(1);
WLC=(max(WL0)+ min(WL0))/2;
BW= max(WL0)- min(WL0);
Return
% this program process the FBG transmission spectrum to produce the frequency shift and
% bandwidth changes
clear all
close all
clc
[filename, pathname] = uigetfile({'*.xlsm'},'Open File','Multiselect','off'); %
choose file to open
addpath(pathname); % add path to the matlab search path
FBGT=xlsread(filename, 'Reflection', 't4:ad8195'); %transmission
FBGR=xlsread(filename, 'Reflection', 't4:ad8195'); %reflection
CaseNum=[1:10]; %[num, Case, raw]=xlsread(filename, 'Air', 'E2:H2');
rmpath(pathname); % remove path
[MM, NN]=size(FBGT);
WL=FBGT(:,1);
figure(5); subplot(2,1,1); plot(WL, FBGT(:,2:NN));title('Transmission');grid on;
subplot(2,1,2); plot(WL, FBGR(:, 2:NN));title('Reflection');grid on;
%process resonance
proceed=input('process resonant (Y/N)? ', 's');
kk=0;
figure(10);
while(proceed=='Y')
clf(10);
kk=kk+1;
WLstart=input('Starting wavelength: ');
WLend=input('Ending wavelength: ');
index=find(WL>=WLstart & WL<=WLend);
WL1=WL(index);
FBG1=FBGT(index, 2:NN);
FBG2=FBGR(index, 2:NN);
figure(10); plot(WL1, FBG1);grid on; title('Transmission');
BW_offsetT=input('Offset from min for BW measurement - Transmission (enter 0 if no resonance): ');
plot(WL1, FBG2);grid on; title('Reflection');
BW_offsetR=input('Offset from min for BW measurement - Reflection (enter 0 if no resonance): ');
for ii=1:NN-1
if (BW_offsetT==0) % no obvious peak
WL_T(ii,kk)=(WLstart+WLend)/2;
BW_T(ii,kk)=0;
else
[WL_T(ii, kk), BW_T(ii, kk)]=f_FBG_BW(WL1, FBG1(:,ii),min(FBG1(:,ii))+BW_offsetT);
end
if (BW_offsetR==0) % no obvious peak
WL_R(ii,kk)=(WLstart+WLend)/2;
BW_R(ii,kk)=0;
else
[WL_R(ii, kk), BW_R(ii, kk)]=f_FBG_BW(WL1, FBG2(:,ii),max(FBG2(:,ii))-BW_offsetR);
end
end
proceed=input('process resonant (Y/N)? ', 's');
end
figure(20);
subplot(2,2,1); plot(CaseNum, WL_T); title('Wavelength shift-Transmission');
xlabel('Case'); ylabel('Wavelength (nm)');
subplot(2,2,2); plot(CaseNum, BW_T); title('FBG BW-Transmission'); xlabel('Case');
ylabel('Wavelength (nm)');
subplot(2,2,3); plot(CaseNum, WL_R); title('Wavelength shift-Reflection');
xlabel('Case'); ylabel('Wavelength (nm)');
subplot(2,2,4); plot(CaseNum, BW_R); title('FBG BW-Reflection'); xlabel('Case');
ylabel('Wavelength (nm)');
% print the output
fid=fopen('FBG_WL_BW.txt', 'w');
for jj=1:kk % loop over number of resonance
fprintf(fid, '%s\n', ['Resonant No. ', num2str(jj)]);
fprintf(fid, '%s \t %s \t %s \t %s \t %s \n','Case', 'Transmission-Freq.','Transmission-BW', 'Reflection-Freq.', 'Reflection-BW');
fprintf(fid, '%10.4f \t %10.4f \t %10.4f \t %10.4f \t %10.4f\n', [CaseNum.',
WL_T(:,jj), BW_T(:,jj), WL_R(:,jj), BW_R(:,jj)].');
end
fclose(fid);
type FBG_WL_BW.txt; % displace the output data
0 Comments
Answers (1)
Walter Roberson
on 15 Dec 2021
You tried to run the code by pressing the Green Run button.
Instead you need to go down to the MATLAB command line and invoke the function, passing in values for WL, FBG, and BWP.
If you try to run the function without passing in any arguments, MATLAB will not hunt around looking to see if it can find variables whose names happen to match the names used inside the function. You must pass in values explicitly.
(This does not actually have to be done at the command line. You could write a function or script that arranged the input data and called the function, passing in the inputs.)
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!