📄 modulation.m
字号:
function varargout = Analog_Modulation(varargin)
% ANALOG_MODULATION M-file for Analog_Modulation.fig
% ANALOG_MODULATION, by itself, creates a new ANALOG_MODULATION or raises the existing
% singleton*.
%
% H = ANALOG_MODULATION returns the handle to a new ANALOG_MODULATION or the handle to
% the existing singleton*.
%
% ANALOG_MODULATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANALOG_MODULATION.M with the given input arguments.
%
% ANALOG_MODULATION('Property','Value',...) creates a new ANALOG_MODULATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Analog_Modulation_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Analog_Modulation_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help Analog_Modulation
% Last Modified by GUIDE v2.5 15-Oct-2008 11:36:41
% Author: Alain DEMANGE, alain.demange@eseo.fr
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Analog_Modulation_OpeningFcn, ...
'gui_OutputFcn', @Analog_Modulation_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Analog_Modulation is made visible.
function Analog_Modulation_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Analog_Modulation (see VARARGIN)
% Choose default command line output for Analog_Modulation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Analog_Modulation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Analog_Modulation_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%-----------------------------------------------------------------------------------%
%-------------------------------INITIAL SETTINGS------------------------------------%
set(handles.modChoice,'Value',1) % Modulation set to DSB-SC
set(handles.modParam,'Visible','Off');
set(handles.text21,'Visible','Off');
set(handles.demodMethod,'Value',1) % Demodulation set to Coherent
set(handles.text14,'Visible','On');
set(handles.DemodSetting_1,'Visible','On');
set(handles.text13,'Visible','On');
set(handles.DemodSetting_2,'Visible','On');
set(handles.PLLOutputFilter,'Visible','Off');
set(handles.noiseConfToggle,'Value',1); % SNR noise mode entry setting
set(handles.noiseConfToggle,'String','Signal to noise ratio selected');
set(handles.ampLimit,'Value',0); % Magnitude clipping not enable
set(handles.soundCommand,'Visible','Off'); % Not yet file to sound!
set(handles.plotCommand,'Visible','Off'); % Not yet results to plot!
set(handles.mainButton,'Visible','Off'); % Not yet .wav file selected!
set(handles.ValidityResults,'Visible','Off');
set(handles.LFgenSelection,'Value',1); % Sine LF generator selected
sineLFGenParamVisibility(handles) % Display sine LF generator settings windows
% Run transmission process indicator
Busy = 0;
handles.Busy = Busy;
% Initialize "modifications flag" in order to indicate if some configuration
% parameters have been modified after the last transmission simulation.
firstSettingsFlag =1;
handles.firstSettingsFlag = firstSettingsFlag;
guidata(hObject,handles);
% Load file listbox from initial directory
initial_dir = pwd;
load_listbox(initial_dir,handles)
%---------------------------------MAIN FUNCTION6------------------------------------%
% --- Executes on button press in mainButton.
function mainButton_Callback(hObject, eventdata, handles)
% Prepare the window which displays required results after simulations.
figure(1)
set(gcf,'Name','Results')
set(gcf,'Visible','Off');
set(handles.soundCommand,'Visible','Off');
set(handles.plotCommand,'Visible','Off');
set(handles.ValidityResults,'Visible','Off');
% verify if simulation is not already running and modify mainButton color if
% necessary
Busy = handles.Busy;
if Busy == 1
return
end
Busy = 1;
firstSettingsFlag = 0;
handles.firstSettingsFlag = firstSettingsFlag;
set(handles.mainButton,'Backgroundcolor',[1 0 0]);
set(handles.mainButton,'String','Busy!');
pause(0.1)
% Read configuration values
Fs_min = str2double(get(handles.minFreq,'String')); %Initial variables settings
Fs_max = str2double(get(handles.maxFreq,'String'));
Fp = str2double(get(handles.carrierFreq,'String'));
A0 = str2double(get(handles.A0,'String'));
Clip_Lvl = str2double(get(handles.clipLvl,'String'));
Gain = str2double(get(handles.Gain,'String'));
Phi_error = eval(get(handles.DemodSetting_1,'String'));
F_error = eval(get(handles.DemodSetting_2,'String'));
k_fad = str2double(get(handles.k_fad,'String'));
NF = str2double(get(handles.NF,'String'));
SNR = str2double(get(handles.SNR,'String'));
% Select sources data
if get(handles.toggleSource,'Value') == 0
Fes = handles.Fes; % Audio source data
S_primaire = handles.S_primaire;%
k = ceil(str2double(get(handles.CarrierSampFactIn,'String')) ...
*(Fp + str2double(get(handles.SourceSampFactorIn,'String'))*Fs_max)/Fes); % Upsample factor
Fesim = k*Fes; % Simulation sample frequency
handles.Fesim = Fesim;
Sequence = repmat(S_primaire',k,1);
Sequence = Sequence (:);
clear k;
else
switch(get(handles.LFgenSelection,'Value'))
case 1 % Single Tone generator
Fesim = str2double(get(handles.CarrierSampFactIn,'String')) ...
*(Fp + str2double(get(handles.LFgenFrequency,'String'))); % Simulation sample frequency
samplePerPeriod = ceil(Fesim/str2double(get(handles.LFgenFrequency,'String')));
outLFGen = 0.5*str2double(get(handles.LFgenLevel,'String')) ...
*cos(2*pi*str2double(get(handles.LFgenFrequency,'String'))*[0:samplePerPeriod-1]/Fesim);
outLFGen = repmat(outLFGen',str2double(get(handles.LFgenPeriods,'String')),1);
case 2 % Rectangular/ sawtooth generator
Fesim = str2double(get(handles.CarrierSampFactIn,'String')) ...
*(Fp + str2double(get(handles.SourceSampFactorIn,'String')) ...
*str2double(get(handles.LFgenFrequency,'String'))); % Simulation sample frequency
minAmp = str2double(get(handles.LFgenOffset,'String')) - str2double(get(handles.LFgenLevel,'String'))/2;
maxAmp = str2double(get(handles.LFgenOffset,'String')) + str2double(get(handles.LFgenLevel,'String'))/2;
riseTime = eval(get(handles.LFgenParam_4,'String'));
fallTime = eval(get(handles.LFgenParam_5,'String'));
widthHigh = eval(get(handles.LFgenParam_6,'String'));
period = 1/(str2double(get(handles.LFgenFrequency,'String')));
periodNumber = str2double(get(handles.LFgenPeriods,'String'));
if (riseTime+fallTime+widthHigh) > period
errordlg('Erreur: Risetime+Falltime+Width > 1/frequency', ...
'Input value error')
return
end
if riseTime == 0
risePart = maxAmp;
else
delta = (maxAmp - minAmp)/round(riseTime*Fesim);
risePart = [minAmp:delta:maxAmp];
end
highPart = maxAmp*ones(1,round(widthHigh*Fesim));
if fallTime == 0
fallPart = minAmp;
else
delta = (maxAmp - minAmp)/round(fallTime*Fesim);
fallPart = [maxAmp:-delta:minAmp];
end
lowPart = minAmp*ones(1,(round(period*Fesim)- length(risePart) - length(highPart) - length(fallPart)));
baseSignal = [risePart highPart fallPart lowPart];
outLFGen = repmat(baseSignal',periodNumber,1);
clear baseSignal risePart highPart fallPart lowPart period delta maxAmp;
clear minAmp widthHigh period periodNumber riseTime fallTime;
case 3 % m-ary NRZ random sequence
Fesim = str2double(get(handles.CarrierSampFactIn,'String')) ...
*(Fp + str2double(get(handles.LFgenFrequency,'String'))); % Simulation sample frequency
samplePerPeriod = ceil(Fesim/str2double(get(handles.LFgenFrequency,'String')));
periodNumber = str2double(get(handles.LFgenPeriods,'String'));
stateNumber = str2double(get(handles.LFgenParam_4,'String'));
if sum(factor(stateNumber)~=2)~=0;
errordlg('The number of state/symbole is not a power of two','Value error')
end
%outLFGen = 2*randint(1,periodNumber,stateNumber)-stateNumber+1;
outLFGen = 2*floor(stateNumber*rand(1,periodNumber))-stateNumber+1;
outLFGen = repmat(outLFGen,samplePerPeriod,1);
outLFGen = outLFGen(:);
magFactor = str2double(get(handles.LFgenLevel,'String'))/(2*(stateNumber-1));
outLFGen = outLFGen*magFactor + str2double(get(handles.LFgenOffset,'String'));
clear magFactor stateNumber samplePerPeriod periodNumber;
case 4 % Uniformly distributed number in range "level"
Fesim = str2double(get(handles.CarrierSampFactIn,'String'))*Fp;
outLFGen = rand(str2double(get(handles.LFgenOffset,'String')),1)-0.5;
outLFGen = str2double(get(handles.LFgenLevel,'String'))*outLFGen;
end
handles.Fesim = Fesim;
Sequence =outLFGen;
clear outLFGen;
end
t=[1:numel(Sequence)]/Fesim; % Time vector
handles.time = t;
Original_sequence = Sequence; % Primary source copy in order to eventualy display it.
handles.Original_sequence = Original_sequence;
% Source frequency band reduction if required
if get(handles.SourceFreqControlValidation, 'Value') == 1
if get(handles.MatlabModulestoggle,'Value') == 0
if str2double(get(handles.minFreq,'String')) == 0
num =0.5*firFilter(-Fs_max,Fs_max,30,Fesim,'Blackman',handles);
else
num =firFilter(Fs_min,Fs_max,30,Fesim,'Blackman',handles);
end
den = 1;
else
if str2double(get(handles.minFreq,'String')) ~= 0
[num,den] = cheby1(6,1,2*Fs_min/Fesim,'high'); % High pass filter
Sequence = filter (num,den,Sequence);
else
[num,den] = ellip(7,1,60,2*Fs_max/Fesim); % Low pass filter coefficients
end
end
Filtered_Sequence = filter (num,den,Sequence);
clear num den Sequence;
else
Filtered_Sequence = Sequence;
end
clear Sequence;
handles.Filtered_Sequence = Filtered_Sequence;
% Carrier modulation
switch(get(handles.modChoice,'Value'))
case 1 % DSB-SC
envelope = Filtered_Sequence*A0;
Out_EX = envelope .* cos(2*pi*Fp.*t') ;
case 2 % DSB-TC
ka = str2double(get(handles.modParam,'String'));
envelope = (1+ka*Filtered_Sequence)*A0;
Out_EX = envelope .* cos(2*pi*Fp.*t') ;
case 3 % SSB-USB (Weaver method)
F1 = (Fs_min +Fs_max)/2; % Center frequency of baseband signal for second mixer
[envelope Out_EX] = VeawerSSB(1,Filtered_Sequence,(Fs_min +Fs_max)/2,Fp,A0,Fesim,t,handles);
case 4 % SSB-LSB (Weaver method)
F1 = (Fs_min +Fs_max)/2; % Center frequency of baseband signal for second mixer
[envelope Out_EX] = VeawerSSB(-1,Filtered_Sequence,(Fs_min +Fs_max)/2,Fp,A0,Fesim,t,handles);
case 5 % VSB-USB
envelope = Filtered_Sequence*A0; % Improper designation here but easy for future plot
[Out_EX] = RF_VSB(1,7,Filtered_Sequence,Fp,A0,Fesim,t,handles);
case 6 % VSB-LSB
envelope = Filtered_Sequence*A0; % Improper designation here but easy for future plot
[Out_EX] = RF_VSB(-1,7,Filtered_Sequence,Fp,A0,Fesim,t,handles);
case 7 % FM using VCO structure
envelope = Filtered_Sequence*A0; % Improper designation here but easy for future plot
Alpha =str2double(get(handles.modParam,'String')); % VCO frequency slope
SumSequence = mod((2*pi*cumsum(Fp + Alpha*Filtered_Sequence)/Fesim),2*pi); %g閚閞ation de la phase
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -