📄 psk_gui.asv
字号:
function [erro_bit_pro,erro_pro]=m_psk2(handles,SNR_dB,M)
%SNR_dB为系统信噪比
N=100;%传递的码元数
%产生数据源
x=rand(1,N);
x=floor(M*x);
[m,n]=size(x);
s0000=[0 0 0 0];
s0001=[0 0 0 1];
s0010=[0 0 1 0];
s0011=[0 0 1 1];
s0100=[0 1 0 0];
s0101=[0 1 0 1];
s0110=[0 1 1 0];
s0111=[0 1 1 1];
s1000=[1 0 0 0];
s1001=[1 0 0 1];
s1010=[1 0 1 0];
s1011=[1 0 1 1];
s1100=[1 1 0 0];
s1101=[1 1 0 1];
s1110=[1 1 1 0];
s1111=[1 1 1 1];
%转换为对应二进制的码元
bx=[];
for i=1:N
if(x(i)<1)
bx=[bx,s0000];
elseif(x(i)<2)
bx=[bx,s0001];
elseif(x(i)<3)
bx=[bx,s0010];
elseif(x(i)<4)
bx=[bx,s0011];
elseif(x(i)<5)
bx=[bx,s0100];
elseif(x(i)<6)
bx=[bx,s0101];
elseif(x(i)<7)
bx=[bx,s0110];
elseif(x(i)<8)
bx=[bx,s0111];
elseif(x(i)<9)
bx=[bx,s1000];
elseif(x(i)<10)
bx=[bx,s1001];
elseif(x(i)<11)
bx=[bx,s1010];
elseif(x(i)<12)
bx=[bx,s1011];
elseif(x(i)<13)
bx=[bx,s1100];
elseif(x(i)<14)
bx=[bx,s1101];
elseif(x(i)<15)
bx=[bx,s1110];
else
bx=[bx,s1111];
end
end
%确定信号的进制
M = max(x) + 1;
M = 2^(ceil(log(M)/log(2)));
M = max(2, M);
SNR=10^(SNR_dB/10);
sgma=log2(M)*sqrt(1/(2*SNR));
Fc=get(handles.edit6,'string');
Fc=str2num(Fc);%modulated signal Y with carrier frequency Fc (Hz)
Fd=get(handles.edit7,'string');
Fd=str2num(Fd);%he sample frequency of the message signal X is Fd (Hz)
Fs=get(handles.edit8,'string');
Fs=str2num(Fs);% the sample frequency of Y isFs (Hz)
y_psk=DMOD(x,Fc,Fd,Fs,'psk'); %频带调制
%产生高斯噪声
%ynoise=sqrt(Fs/Fd)*sgma*(rand(1,length(y_psk)));%+j*rand(1,length(y_psk)));
for i=1:length(y_psk)
u=rand;%均匀分布随机变量
z=sgma*(sqrt(2*log(1/(1-u))));%瑞利分布随机变量
u=rand;
ynoise(i)=z*cos(2*pi*u);
end
y_rece=y_psk+ynoise;
y_dpsk=DDEMOD(y_rece,Fc,Fd,Fs,'psk',M);%频带解调
%转换为对应二进制的码元
r_bx=[];
for i=1:N
if(y_dpsk(i)<1)
r_bx=[r_bx,s0000];
elseif(y_dpsk(i)<2)
r_bx=[r_bx,s0001];
elseif(y_dpsk(i)<3)
r_bx=[r_bx,s0010];
elseif(y_dpsk(i)<4)
r_bx=[r_bx,s0011];
elseif(y_dpsk(i)<5)
r_bx=[r_bx,s0100];
elseif(y_dpsk(i)<6)
r_bx=[r_bx,s0101];
elseif(y_dpsk(i)<7)
r_bx=[r_bx,s0110];
elseif(y_dpsk(i)<8)
r_bx=[r_bx,s0111];
elseif(y_dpsk(i)<9)
r_bx=[r_bx,s1000];
elseif(y_dpsk(i)<10)
r_bx=[r_bx,s1001];
elseif(y_dpsk(i)<11)
r_bx=[r_bx,s1010];
elseif(y_dpsk(i)<12)
r_bx=[r_bx,s1011];
elseif(y_dpsk(i)<13)
r_bx=[r_bx,s1100];
elseif(y_dpsk(i)<14)
r_bx=[r_bx,s1101];
elseif(y_dpsk(i)<15)
r_bx=[r_bx,s1110];
else
r_bx=[r_bx,s1111];
end
end
erro_bit=sum(r_bx-bx~=0);%错误的比特数
erro_bit_pro=erro_bit/(4*N);%错误比特率
erro_num=sum(x-y_dpsk~=0);%错误码元个数
erro_pro=erro_num/N;
sn=get(handles.edit9,'string');
sn=str2num(sn);
if SNR_dB==sn
figure
subplot(5,1,1)
stairs([x,x(end)])
axis([1,n+1,0,M])
ylabel('随机信号序列')
%title('随机信号序列')
subplot(5,1,2)
plot([1:length(y_psk)]/Fs,real(y_psk))
axis([0,length(y_psk)/Fs,-2,2])
ylabel('调制信号波形')
%title('调制信号波形')
subplot(5,1,3)
plot(ynoise)
ylabel('随机噪声波形')
%title('随机噪声波形')
subplot(5,1,4)
plot([1:length(y_rece)]/Fs,real(y_rece))
axis([0,length(y_psk)/Fs,-2,2])
ylabel('接受加噪波形')
%title('接受加噪波形')
subplot(5,1,5)
stairs([y_dpsk,y_dpsk(end)])
hold on
axis([1,n+1,0,M])
hold off
ylabel('解调信号序列')
%title('解调信号序列')
end
% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (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 edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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 edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (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 edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (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 edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (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 edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double% --- Executes during object creation, after setting all properties.function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (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 edit7 as text% str2double(get(hObject,'String')) returns contents of edit7 as a double% --- Executes during object creation, after setting all properties.function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (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 edit8 as text% str2double(get(hObject,'String')) returns contents of edit8 as a double% --- Executes during object creation, after setting all properties.function edit9_CreateFcn(hObject, eventdata, handles)% hObject handle to edit9 (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 set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (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 edit9 as text% str2double(get(hObject,'String')) returns contents of edit9 as a double
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -