⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot_mcgsm_tx_mask.m

📁 This is GMS down upper converter and down converter in simulink. you may understand the structure in
💻 M
字号:
function plot_mcgsm_tx_mask(Fs,scale,carriers,strict)
%
% PLOT_MCGSM_TX_MASK : function to plot a mask across the sampled band to
% indicate the allowable transmitted power spectrum for a multi-carrier
% signal.
% 'Fs' specifies the sampling frequency
% 'scale' specifies the frequency scaling, defaulting to Hz, with the
% option of using kHz or MHz (case insensitive.)
% 'carriers' specifies the carrier frequencies array passed to
% the function, either as a single value or listed in order of increasing
% frequency.  Minimum carrier separation should be observed to obtain a
% meaningful mask.  If no carrier is specified, or if the carrier is set to
% zero, the function will plot the mask at baseband.
% 'strict' specifies the level of strictness with which the mask is
% applied, and takes the strings 'strict' (default), 'moderate' or 'slack'.
% 'strict' mode uses linear masking between all defined attenuation points
% 'moderate' mode applies linear masking only between the points <600 kHz
% 'slack' mode applies no linear masking, i.e the mask is "blocky"

%% Argument processing
% Assume strict mask...
if (nargin < 4)
    strict = 'strict';
end
% If using just a DC carrier...
if (nargin < 3)
    carriers = [ 0 ];
end
% Determine scale
if (nargin < 2)
    scale = 'Hz';
end
% IF no Fs, assume sampling at 10 MHz (arbitrary, larger than mask)
if (nargin < 1)
    Fs=10e6;
end

%% Initialisation
% Mask arrays
offsets_x = [   0, 100e3, 200e3, 250e3, 400e3, 600e3, 1200e3, 1800e3, 6000e3 ];

if     strcmpi(scale,'Hz'),  offsets_x = offsets_x;     moderate_bound = 600e3;
elseif strcmpi(scale,'kHz'), offsets_x = offsets_x/1e3; moderate_bound = 600;
elseif strcmpi(scale,'MHz'), offsets_x = offsets_x/1e6; moderate_bound = 0.6;
else
    error('Specify scale as string value: ''Hz'' (default), ''kHz'' or ''MHz''')
end
    
levels_x  =     [ 0.5,  0.5,    -30,   -33,   -60,   -70,    -73,    -75,    -80 ];
% Adjust levels for different measurement bandwidth
adj = 10*log10(100/30);
adjusts  =     [    0,    0,      0,     0,     0,     0,      0,    adj,    adj ];
levels_x = levels_x - adjusts;

if strcmpi(strict,'slack')
    offsets=zeros(1,2*length(offsets_x)-2);
    offsets(1:length(offsets_x))=offsets_x;
    offsets(3:2:end) = offsets_x(3:end);
    offsets(4:2:end) = offsets_x(3:end);
    
    levels = zeros(1,length(offsets));
    levels(1:length(levels_x)) = levels_x;
    levels(3:2:end) = levels_x(2:end-1);
    levels(4:2:end) = levels_x(3:end);
elseif strcmpi(strict,'moderate')
    num_blocks = sum(offsets_x>moderate_bound)
    mark = length(offsets_x)-num_blocks+1
    
    offsets=zeros(1,length(offsets_x)+num_blocks)
    offsets(1:length(offsets_x))=offsets_x
    offsets(mark  :2:end) = offsets_x(mark:end)
    offsets(mark+1:2:end) = offsets_x(mark:end)
    
    levels = zeros(1,length(offsets))
    levels(1:length(levels_x)) = levels_x
    levels(mark+1:2:end) = levels_x(mark:end)
    levels(mark+2:2:end) = levels_x(mark:end-1)
else
    offsets=offsets_x;
    levels =levels_x;
end

% Start off mask vectors in top corner
ff = [ -Fs/2 ]; MM = [ 10 ];
% Add dummy first & final carrier below dc and beyond Fs to aid loop construction
carriers = [-Fs/2-6e6, carriers, Fs/2+6e6 ];
% If no dc carrier, set start level according to first real carrier
for j = length(offsets):-1:1
    if (carriers(2)-offsets(j)) > ff(end)
        ff = [ ff, ff(end) ];
        MM = [ MM, levels(j) ];
        break;
    end
end

%% Main loop
% Loop through carriers, ramping up then down - watch for overlaps
for i = 2:length(carriers)-1
    % Ramp up
    for j = length(offsets):-1:1
        if (carriers(i)-offsets(j)) >= (carriers(i-1)+offsets(j)) & (carriers(i)-offsets(j)) >= ff(end)
            ff = [ ff, carriers(i)-offsets(j) ];
            MM = [ MM, levels(j) ];
        end
    end
    %ff
    %MM
    % Ramp down
    for j = 1:length(offsets)
        if (carriers(i)+offsets(j)) >= ff(end) & (carriers(i)+offsets(j)) <= Fs/2
            if (carriers(i)+offsets(j)) <= (carriers(i+1)-offsets(j))
                ff = [ ff, carriers(i)+offsets(j) ];
                MM = [ MM, levels(j) ];
            else
                % Crossover between defined offsets, create a split point,
                % just to be completely thorough!
                split = (carriers(i)+carriers(i+1))/2;
                if split > ff(end)
                    ff = [ ff, split ];
                    adjust = (levels(j-1)-levels(j))*((split-(carriers(i)+offsets(j-1)))/(offsets(j)-offsets(j-1)));
                    MM = [ MM, levels(j-1) - adjust ];
                end
            end
        end
    end
end
%ff
%MM

%% Wrap-up and plot
% Finish off the mask by wrapping back to origin
ff = [ ff,      Fs/2, Fs/2 ];
MM = [ MM, MM(end), 10 ];
fillcolor = [0.95, 0.95, 1.0];
fill(ff, MM, fillcolor);
hold on; grid on; zoom on;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -