📄 twopointmodulation.asv
字号:
function varargout = TwoPointModulation(varargin)
% TWOPOINTMODULATION M-file for TwoPointModulation.fig
% TWOPOINTMODULATION, by itself, creates a new TWOPOINTMODULATION or raises the existing
% singleton*.
%
% H = TWOPOINTMODULATION returns the handle to a new TWOPOINTMODULATION or the handle to
% the existing singleton*.
%
% TWOPOINTMODULATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TWOPOINTMODULATION.M with the given input arguments.
%
% TWOPOINTMODULATION('Property','Value',...) creates a new TWOPOINTMODULATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before TwoPointModulation_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TwoPointModulation_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
% Edit the above text to modify the response to help TwoPointModulation
% Last Modified by GUIDE v2.5 28-Aug-2007 14:20:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TwoPointModulation_OpeningFcn, ...
'gui_OutputFcn', @TwoPointModulation_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 TwoPointModulation is made visible.
function TwoPointModulation_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 TwoPointModulation (see VARARGIN)
% Choose default command line output for TwoPointModulation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TwoPointModulation wait for user response (see UIRESUME)
% uiwait(handles.TwoPointModulation);
% --- Outputs from this function are returned to the command line.
function varargout = TwoPointModulation_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;
% --- Executes on button press in RandomSignal.
function RandomSignal_Callback(hObject, eventdata, handles)
% hObject handle to RandomSignal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of RandomSignal
% set the radio button parameter Value
set(handles.UserdefinedSignal,'Value',0);
set(handles.RandomSignal,'Value',1);
% set the parameter Enable
set(handles.RS_Data,'Enable','on');
set(handles.ImportfromText,'Enable','off');
set(handles.US_Data,'Enable','off');
% generate the random signal bit source
Fs=4.8; % the symbol frequency is 4.8 kHz
T=1/Fs;
t=0:T:30-T;
L=length(t); % the length of the symbols
rd=randn(L,2);
rd_max=max(abs(rd));
rd(:,1)=rd(:,1)/rd_max(1);
rd(:,2)=rd(:,2)/rd_max(2);
x=abs(floor(rd));
% mapping between symbols and bits (bit to symbol)
[m,n]=size(x);
dt=zeros(m,1);
for i=1:L
if isequal(x(i,:),[0 1])
dt(i)=+3;
elseif isequal(x(i,:),[0 0])
dt(i)=+1;
elseif isequal(x(i,:),[1 0])
dt(i)=-1;
else
dt(i)=-3;
end
end
% set the userdata the ud
ud.dt=dt;
set(handles.TwoPointModulation,'UserData',ud);
% transfer ud to the workspace
str=get(handles.RS_Data,'String');
assignin('base',str,dt);
function RS_Data_Callback(hObject, eventdata, handles)
% hObject handle to RS_Data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of RS_Data as text
% str2double(get(hObject,'String')) returns contents of RS_Data as a double
% transfer ud to the workspace
ud=get(handles.TwoPointModulation,'UserData');
dt=ud.dt;
str=get(handles.RS_Data,'String');
assignin('base',str,dt);
% --- Executes during object creation, after setting all properties.
function RS_Data_CreateFcn(hObject, eventdata, handles)
% hObject handle to RS_Data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in UserdefinedSignal.
function UserdefinedSignal_Callback(hObject, eventdata, handles)
% hObject handle to UserdefinedSignal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of UserdefinedSignal
% set the radio button parameter Value
set(handles.UserdefinedSignal,'Value',1);
set(handles.RandomSignal,'Value',0);
% set the parameter Enable
set(handles.ImportfromText,'Enable','on');
set(handles.US_Data,'Enable','on');
set(handles.RS_Data,'Enable','off');
% --- Executes on button press in ImportfromText.
function ImportfromText_Callback(hObject, eventdata, handles)
% hObject handle to ImportfromText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname, filterindex] = uigetfile( ...
{'*.txt','TXT-files (*.txt)'; ...
'*.mat','MAT-files (*.mat)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file');
if filterindex == 0
% if the data import from text is cancelled
set(handles.UserdefinedSignal,'Value',0);
set(handles.US_Data,'Enable','off');
else
% import data from the text
set(handles.US_Data,'String',filename);
dt = importdata(filename);
% set the userdata the ud
ud.dt=dt;
set(handles.TwoPointModulation,'UserData',ud);
% transfer ud to the workspace
assignin('base','my_inputdata',dt);
end
function US_Data_Callback(hObject, eventdata, handles)
% hObject handle to US_Data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of US_Data as text
% str2double(get(hObject,'String')) returns contents of US_Data as a double
% import data from the text
filename=get(handles.US_Data,'String');
dt = importdata(filename);
ud.dt=dt;
set(handles.TwoPointModulation,'UserData',ud);
% --- Executes during object creation, after setting all properties.
function US_Data_CreateFcn(hObject, eventdata, handles)
% hObject handle to US_Data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function M1_Callback(hObject, eventdata, handles)
% hObject handle to M1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of M1 as text
% str2double(get(hObject,'String')) returns contents of M1 as a double
% --- Executes during object creation, after setting all properties.
function M1_CreateFcn(hObject, eventdata, handles)
% hObject handle to M1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function M2_Callback(hObject, eventdata, handles)
% hObject handle to M2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of M2 as text
% str2double(get(hObject,'String')) returns contents of M2 as a double
% --- Executes during object creation, after setting all properties.
function M2_CreateFcn(hObject, eventdata, handles)
% hObject handle to M2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in ExporttoWorkspace.
function ExporttoWorkspace_Callback(hObject, eventdata, handles)
% hObject handle to ExporttoWorkspace (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% import the rrc filter
filename='win.txt';
rrc = importdata(filename);
ud.rrc=rrc;
% get the original data and 8-upsample it
ud=get(handles.TwoPointModulation,'UserData');
dt=ud.dt;
updt=upsample(dt,8);
ud.updt=updt;
% caculate the rrc output and set it to userdata
M1=str2double(get(handles.M1,'String'));
M2=str2double(get(handles.M2,'String'));
out=filter(rrc,1,updt);
out1=M1*out;
out2=M2*out;
ud.out1=out1;
ud.out2=out2;
set(handles.TwoPointModulation,'UserData',ud);
% export the two output data to a text file
out=[out1 out2]';
ud.out=out;
set(handles.TwoPointModulation,'UserData',ud);
str1=get(handles.Output,'String');
str2='.txt';
str=[str1 str2];
fid = fopen(str, 'wt');
% fid = fopen('a.txt','w+');
fprintf(fid,'%6.5f,%6.5f\n',out);
fclose(fid)
% transfer ud to the workspace
str=get(handles.Output,'String');
assignin('base',str,out);
function Output_Callback(hObject, eventdata, handles)
% hObject handle to Output (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Output as text
% str2double(get(hObject,'String')) returns contents of Output as a double
% export the output data to workspace
ud=get(handles.TwoPointModulation,'UserData');
out=ud.out;
str=get(handles.Output,'String');
assignin('base',str,out);
% --- Executes during object creation, after setting all properties.
function Output_CreateFcn(hObject, eventdata, handles)
% hObject handle to Output (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in OK.
function OK_Callback(hObject, eventdata, handles)
% hObject handle to OK (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
% --- Executes on button press in Cancel.
function Cancel_Callback(hObject, eventdata, handles)
% hObject handle to Cancel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -