Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ varargout ] = funkce2( varargin )
- %funkce2 Nacte data ze souboru a/nebo zobrazi grafy.
- % [f, Zin] = funkce2(fileName)
- % Nacte data ze souboru, ulozi je do vystupnich parametru a zobrazi
- % grafy.
- %
- % funkce2(f, Zin, isGrid, lineWidth)
- % Zobrazi grafy pro zadane vstupni vektory f a Zin. Pokud je isGrid
- % true nebo neni zadano, je v grafech zobrazena mrizka. Grafy jsou
- % vykresleny s tloustkou cary lineWidth, pokud neni zadano, vychozi
- % hodnota je 2px.
- %
- function [f, Zin, R] = readFile(fileName)
- if (exist(fileName, 'file') == 0)
- error('Soubor neexistuje.');
- end;
- S11 = xlsread(fileName);
- if (length(S11) > 5000)
- warning('myApp:longFile', 'Soubor je delší než 5000 řádků.');
- end;
- S11 = [S11(:,1), S11(:,2) .* exp(1i * S11(:,3) / 180 * pi)];
- Zin = Z0 .* ((1 + S11(:,2)) ./ (1 - S11(:,2)));
- f = S11(:,1);
- R = abs(S11(:,2));
- end
- function drawZPlot(f, Zin, isGrid, lineWidth)
- figure('Name', 'Vstupní impedance');
- plot(f, real(Zin), 'Color', 'blue', 'LineWidth', lineWidth, 'DisplayName', 'Real part');
- hold on;
- plot(f, imag(Zin), 'Color', 'green', 'LineWidth', lineWidth, 'DisplayName', 'Imaginary part');
- title('Vstupní impedance');
- xlabel('f [GHz]');
- ylabel('Zin [\Omega]');
- legend show;
- if(isGrid)
- grid on;
- end;
- end
- function drawRPlot(f, R, isGrid, lineWidth)
- figure('Name', 'Koeficient odrazu');
- plot(f, R, 'Color', 'blue', 'LineWidth', lineWidth);
- title('Koeficient odrazu');
- xlabel('f [GHz]');
- ylabel('|S11|');
- if(isGrid)
- grid on;
- end;
- end
- Z0 = 50;
- profile clear;
- profile on;
- tic;
- switch (nargin)
- case 1
- fileName = varargin{1};
- isGrid = true;
- lineWidth = 2;
- [f, Zin, R] = readFile(fileName);
- drawZPlot(f, Zin, isGrid, lineWidth);
- drawRPlot(f, R, isGrid, lineWidth);
- if (nargout >= 2)
- varargout{1} = f;
- varargout{2} = Zin;
- end;
- case {2, 3, 4}
- f = varargin{1};
- Zin = varargin{2};
- if (nargin >= 3)
- isGrid = varargin{3};
- else
- isGrid = true;
- end;
- if (nargin >= 4)
- lineWidth = varargin{4};
- else
- lineWidth = 2;
- end;
- if (length(f) ~= length(Zin))
- error('Vstupni argumenty nemaji stejnou delku.');
- end;
- R = abs((Zin - Z0) ./ (Zin + Z0));
- drawZPlot(f, Zin, isGrid, lineWidth);
- drawRPlot(f, R, isGrid, lineWidth);
- varargout = [];
- otherwise
- error('Neplatny pocet vstupnich parametru.');
- end;
- fprintf('Funkce bezela %f sekund.\n', toc());
- profile off;
- profile report;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement