sigplot2.m
来自「阵列信号处理的工具箱」· M 代码 · 共 877 行 · 第 1/2 页
M
877 行
% ************** Get indices for plotting axes **************% When the index is ':' replace it by a vector with the correspondig indices.%maxNoIndex = 6;XX = signal.signals;sizeXX = sizem(XX);%sizeXX = [sizeXX ones(1,maxNoIndex-size(sizeXX,2))];if (isstr(pulseIx) & (pulseIx == ':')) pulseIx = 1:sizeXX(1,1);endif (isstr(rangeIx) & (rangeIx == ':')) rangeIx = 1:sizeXX(1,2);endif (isstr(thetaIx) & (thetaIx == ':')) thetaIx = 1:sizeXX(1,3);endif (isstr(extraIx) & (extraIx == ':')) extraIx = 1:sizeXX(1,4);endif (isstr(cpiIx) & (cpiIx == ':')) cpiIx = 1:sizeXX(1,5);end% ****************** Possibly plot in a GUI ******************if (guiFlag) disp('sigplot2: guiFlag') cfh = sigplot2win(signal); set(findobj(cfh, 'Tag','EditTextStartIndexPulse'),'String', ... num2str(pulseIx(1))); set(findobj(cfh,'tag','EditTextLengthPulse'),'String',... num2str(pulseIx(length(pulseIx)) - pulseIx(1) + 1)); set(findobj(cfh, 'Tag','EditTextStartIndexRange'),'String', ... num2str(rangeIx(1))); set(findobj(cfh,'tag','EditTextLengthRange'),'String',... num2str(rangeIx(length(rangeIx)) - rangeIx(1) + 1)); set(findobj(cfh, 'Tag','EditTextStartIndexSpace'),'String', ... num2str(thetaIx(1))); set(findobj(cfh,'tag','EditTextLengthSpace'),'String',... num2str(thetaIx(length(thetaIx)) - thetaIx(1) + 1)); set(findobj(cfh, 'Tag','EditTextStartIndexExtra'),'String', ... num2str(extraIx(1))); set(findobj(cfh,'tag','EditTextLengthExtra'),'String',... num2str(extraIx(length(extraIx)) - extraIx(1) + 1)); set(findobj(cfh, 'Tag','EditTextStartIndexCPI'),'String', ... num2str(cpiIx(1))); set(findobj(cfh,'tag','EditTextLengthCPI'),'String',... num2str(cpiIx(length(cpiIx)) - cpiIx(1) + 1)); %set(findobj(cfh, 'Tag','EditTextStartIndexTrial'),'String', ... % num2str(trialIx(1))); %set(findobj(cfh,'tag','EditTextLengthTrial'),'String',... % num2str(trialIx(length(trialIx)) - trialIx(1) + 1)); set(findobj(cfh,'Tag','EditTextAxisValuesPulse'),'String',... ['[',num2str(pulAxis(:).'),']']); set(findobj(cfh,'Tag','EditTextAxisValuesRange'),'String',... ['[',num2str(ranAxis(:).'),']']); set(findobj(cfh,'Tag','EditTextAxisValuesSpace'),'String',... ['[',num2str(spaAxis(:).'),']']); set(findobj(cfh,'Tag','EditTextAxisValuesExtra'),'String',... ['[',num2str(extraAxis(:).'),']']); set(findobj(cfh,'Tag','EditTextAxisValuesCPI'),'String',... ['[',num2str(cpiAxis(:).'),']']); %set(findobj(cfh,'Tag','EditTextAxisValuesTrial'),'String',... % ['[',num2str(trialAxis(:).'),']']); scaleTypeHandle = findobj(cfh,'Tag','PopupMenuScaleType'); altTxt = get(scaleTypeHandle,'String') altIx = find(strcmp(altTxt,scaleType)) set(scaleTypeHandle,'Value',altIx);else % (guiFlag)% ************** Get the right part (indices) of the signal **************X = getm(XX,pulseIx,rangeIx,thetaIx,extraIx,cpiIx);%if (yindex > xindex)% X = X.';%endtitleText = '[';% ****************** Labels and values of the axes ******************pulseStr = 'Pulses or doppler ch.';rangeStr = 'Range bins';thetaStr = 'Theta channels or beams';phiStr = 'Phi channels or beams';trialStr = 'Trials';xErrStr = 'Wrong x-axis index.';yErrStr = 'Wrong y-axis index.';if ~isempty(pulAxis) pulAxisValues = pulAxis;else pulAxisValues = pulseIx;end%ifif ~isempty(ranAxis) ranAxisValues = ranAxis;else ranAxisValues = rangeIx;end%ifif ~isempty(spaAxis) spaAxisValues = spaAxis(1,:);else spaAxisValues = thetaIx;end%ifif (xindex == 1) xstr = pulseStr; xValues = pulAxisValues;elseif (xindex == 2) xstr = rangeStr; xValues = ranAxisValues;elseif (xindex == 3) xstr = thetaStr; xValues = spaAxisValues;elseif (xindex == 4) xstr = phiStr; xValues = extraIx;elseif (xindex == 5) xstr = trialStr; xValues = cpiIx;elseif (xindex == 999) xstr = 'xstr is not used.';else error(xErrStr)end%ifif (yindex == 1) ystr = pulseStr; yValues = pulAxisValues;elseif (yindex == 2) ystr = rangeStr; yValues = ranAxisValues;elseif (yindex == 3) ystr = thetaStr; yValues = spaAxisValues;elseif (yindex == 4) ystr = phiStr; yValues = extraIx;elseif (yindex == 5) ystr = trialStr; yValues = cpiIx;else error(yErrStr)end%if%if (length(pulseIx) = 1)% display pulseIx somewhere in the graph.%end%if%Do the same with the other indices.% ****************** Signal types ******************if (strcmp(sigType,'sig')) % Do nothing.elseif (strcmp(sigType,'fft')) fprintf('sigplot2: size(X) %d',size(X)) fprintf('sigplot2: Should it be fftshift1 instead of fftshift?') X = fftshift(fft(X)); % Should it be fftshift1 ?else error('DBT-Error: Invalid sigType.')end%iftitleText = [titleText,sigType,','];% ****************** Signal parts ******************if (strcmp(sigPart,'abs')) X = abs(X);elseif (strcmp(sigPart,'angle')) X = angle(X);elseif (strcmp(sigPart,'uwangle')) X = unwrap(angle(X));elseif (strcmp(sigPart,'real')) X = real(X);elseif (strcmp(sigPart,'imag')) X = imag(X);else error('DBT-Error: Invalid sigPart.')end%iftitleText = [titleText,sigPart,','];% ****************** Normalization ******************if (strcmp(normType,'none')) % Do nothing.elseif (strcmp(normType,'max')) X = normMaxLevel * X./max(max(X));elseif (strcmp(normType,'min')) X = normMinLevel * X./min(min(X));elseif (strcmp(normType,'minmax')) % Not implemented.else error('DBT-Error: Invalid normType.')end%if% ****************** Scale types ******************if (strcmp(scaleType,'lin')) % Do nothing.elseif (strcmp(scaleType,'dB')) X = 20*log10(X+eps); % "+eps" to avoid log of zero.elseif (strcmp(scaleType,'log')) X = 10*log10(X+eps); % "+eps" to avoid log of zero.elseif (strcmp(scaleType,'radians')) % Do nothing.elseif (strcmp(scaleType,'degrees')) X = r2d(X);elseif (strcmp(scaleType,'pirad')) X = X/pi;else error('DBT-Error: Invalid scaleType.')end%iftitleText = [titleText,scaleType,','];% ****************** Min and max values to plot ******************if ~isempty(plotMaxLevel) X(X > plotMaxLevel) = NaN;end%ifif ~isempty(plotMinLevel) X(X < plotMinLevel) = sigMinVal;end%if% ****************** Plot ******************[viewAz, viewEl] = view;cax = newplot; %Returns current axes. Retores view to 2D.holdState = ishold; % The correct way to create or relate to a figure and axes according to [Using MATLAB Graphics. Version 5] p. 8-34 -- 8-36.%cfi = get(cax,'Parent') % Returns current figure (parent of cax).%set(cfi,'DefaultColormap',pink)%viewAngles = [-37 50];if ~strcmp(plotType,'noplot') if (min(size(X)) >=3) % **** Plot a 2D-signal. **** if strcmp(plotType,'surfl') h = surfl(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'surf') h = surf(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'surfc') h = surfc(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'mesh') h = mesh(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'meshc') h = meshc(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'meshz') h = meshz(xValues, yValues, X); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'pcolor') h = pcolor(xValues, yValues, X); noDimGraph = 2; elseif strcmp(plotType,'contour') %[contMat,h] = contour(xValues, yValues, X); [contMat,h] = contourhlp(plotType, xValues, yValues, X, ... extraPlotParam, lineSpec); noDimGraph = 2; elseif strcmp(plotType,'contourf') %[contMat,h] = contourf(xValues, yValues, X); [contMat,h] = contourhlp(plotType, xValues, yValues, X, ... extraPlotParam, lineSpec); noDimGraph = 2; elseif strcmp(plotType,'contour3') %[contMat,h] = contour3(xValues, yValues, X); [contMat,h] = contourhlp(plotType, xValues, yValues, X, ... extraPlotParam, lineSpec); %view(viewAngles) noDimGraph = 3; elseif strcmp(plotType,'plot') % Like plotting a matrix with MATLABs "plot". Several lines are % plotted on each other in 2D. % On the x-axis there is either ranges or pulses. % Each curve corresponds to a certain antenna channel, extraIndex, % CPI or trial. h = plot(yValues,X,lineSpec); %tmpStr = xstr; xstr = ystr; %ystr = tmpStr; ystr = ''; noDimGraph = 2; else dbterror('This signal must be plotted with a 3D-plot.') end%if if (0) curColorMap = colormap; colormap('default') defaultColorMap = colormap; if (all(all(curColorMap == defaultColorMap))) colormap(pink); else colormap(curColorMap); end%if end%if (0) shading flat xlabel([xstr ]); ylabel([ystr ]) elseif ((size(X,1) == 1) | (size(X,2) == 1)) % **** Plot a 1D-signal. **** if strcmp(plotType,'bar') h = bar(X,lineSpec); elseif strcmp(plotType,'barh') h = barh(X,lineSpec); %xlabelTxt = ylabelTxt; %ylabelTxt = ''; elseif strcmp(plotType,'bar3') h = bar3(X,lineSpec); %xlabelTxt = ''; %ylabelTxt = ''; elseif strcmp(plotType,'plot') h = plot(yValues,X,lineSpec); elseif strcmp(plotType,'stem') h = stem(X,lineSpec); elseif strcmp(plotType,'stairs') stairs(X,lineSpec); h = []; else h = plot(yValues, X,lineSpec); end%if xlabel([ystr ]); noDimGraph = 2; else error(['DBT-Error: The signal X must be at least 3-by-3 or an ', ... 'one-dimensional vector.']) end%if titleText = [titleText,']']; if (0) %get(get(gca,'Title'),'String') if (isempty(get(get(gca,'Title'),'String'))) %disp('Settting title') % Only set title if there already is no title. %set(gca,'Title',text('String','New Title')) title(titleText) end%if end%if (0) %set(cax,'DefaultTitle',titleText) if (~holdState) if (noDimGraph == 2) view(2) elseif (noDimGraph == 3) if ((viewAz == 0) & (viewEl == 90)) % Currently 2D view. change the view to 3D. view(3) else % Already 3D view. Restore to the view before the plot command. view([viewAz, viewEl]); end%if else dbterror('Internal error: Unknown view dimension.') end%if %title(titleText) %colormap(pink) end%if (~holdState)end%if plotType% ****************** Output parameters ******************if (nargout > 0) Xout = X; handles = h;end%if (nargout)end%if (guiFlag)%endfunction sigplot2% ----------------------------------------------------------------------- %% function contourhlp%% Start: 9xxxxx Svante Bj鰎klund (svabj).% ----------------------------------------------------------------------- %function [contMat,h] = contourhlp(plotType, xValues, yValues, X, plotParam, lineSpec) if (isempty(plotParam)) if (isempty(lineSpec)) [contMat,h] = eval([plotType, '(xValues, yValues, X)']); else [contMat,h] = eval([plotType, '(xValues, yValues, X, lineSpec)']); end%if lineSpec else if (isempty(lineSpec)) [contMat,h] = eval([plotType, '(xValues, yValues, X, plotParam)']); else [contMat,h] = eval([plotType,'(xValues,yValues,X,plotParam,lineSpec)']); end%if lineSpec end%if plotParam%endfunction contourhlp
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?