function varargout = NewFDM(varargin)
% NEWFDM MATLAB code for NewFDM.fig
% NEWFDM, by itself, creates a new NEWFDM or raises the existing
% singleton*.
%
% H = NEWFDM returns the handle to a new NEWFDM or the handle to
% the existing singleton*.
%
% NEWFDM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in NEWFDM.M with the given input arguments.
%
% NEWFDM('Property','Value',...) creates a new NEWFDM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before NewFDM_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to NewFDM_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 NewFDM
% Last Modified by GUIDE v2.5 13-Jan-2015 00:35:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @NewFDM_OpeningFcn, ...
'gui_OutputFcn', @NewFDM_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 NewFDM is made visible.
function NewFDM_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 NewFDM (see VARARGIN)
% Choose default command line output for NewFDM
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes NewFDM wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = NewFDM_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 录音1
global R
R = audiorecorder( 20000, 16 ,2 ) ;
record(R);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global R
global x1
%停止1
stop(R);
%将语音保存
myspeech = getaudiodata(R);
audiowrite('luyin1.wav',myspeech,20000);
%语音滤波为440~1700Hz,后保存
global fs
fs=20000;
fp1=550;fp2=1600;
fs1=440;fs2=1700;
wp1=2*pi*fp1/fs;wp2=2*pi*fp2/fs;
ws1=2*pi*fs1/fs;ws2=2*pi*fs2/fs;
Bt=wp1-ws1;
N0=ceil(6.2*pi/Bt);
N=N0+mod(N0+1,2);
wn=[(wp1+ws1)/2/pi,(wp2+ws2)/2/pi];
window3=blackman(N);
b3=fir1(N-1,wn,window3);
x1=filter(b3,1,myspeech);
audiowrite('ly1.wav',x1,20000);
%显示时域波形
axes(handles.axes1);
plot(x1);
xlabel('sec');ylabel('x1');
title('输入信号1的时域图');
%显示频域波形
N=length(x1);
fx=fft(x1);
dfx=fs/N;
n=0:N/2;
f=n*dfx;
axes(handles.axes2);
plot(f,abs(fx(n+1))*2/N);
xlabel('频率');ylabel('幅度');
title('输入信号1的频域图');
%播放
sound(x1,20000)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 录音2
global Q
Q = audiorecorder( 20000, 16 ,1 ) ;
record(Q);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%停止2
global Q
global x2
stop(Q);
myspeech = getaudiodata(Q);
audiowrite('luyin2.wav',myspeech,20000);
global fs
fs=20000;
fp1=550;fp2=1600;
fs1=440;fs2=1700;
wp1=2*pi*fp1/fs;wp2=2*pi*fp2/fs;
ws1=2*pi*fs1/fs;ws2=2*pi*fs2/fs;
Bt=wp1-ws1;
N0=ceil(6.2*pi/Bt);
N=N0+mod(N0+1,2);
wn=[(wp1+ws1)/2/pi,(wp2+ws2)/2/pi];
window3=blackman(N);
b3=fir1(N-1,wn,window3);
x2=filter(b3,1,myspeech);
audiowrite('ly2.wav',x2,20000);
%显示时域波形
axes(handles.axes3);
plot(x2);
xlabel('sec');ylabel('x2');
title('输入信号2的时域图');
%显示频域波形
N=length(x2);
fx=fft(x2);
dfx=fs/N;
n=0:N/2;
f=n*dfx;
axes(handles.axes4);
plot(f,abs(fx(n+1))*2/N);
xlabel('频率');ylabel('幅度');
title('输入信号2的频域图');
sound(x2,20000)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%获取语音信号
fs=20000;
[x1]=audioread('ly1.wav');
[x2]=audioread('ly2.wav');
%将语音信号前40000个序列赋值
for i=1:1:40000
x11(i)=x1(i);
end
for i=1:1:40000
x22(i)=x2(i);
end
%高频载波
t=0:1/fs:2-1/fs;
f01=4000;
f02=8000;
x01=cos(2*pi*f01*t);
x02=cos(2*pi*f02*t);
%信号合成
global y
y=x11.*x01+x22.*x02;
N=length(y);
%加入噪声
global ygauss
SNRpBit=160; %信噪比
M=2; %进制数
SNR=SNRpBit/log2(M);
ygauss=awgn(y,SNR-10*log10(0.5)-10*log10(N),'measured',[],'dB'); %在已调信号中加入高斯白噪声
%将合成信号写入文件中
audiowrite('FDM.wav',ygauss,20000)
%高斯信道中已调信号频谱
N=length(ygauss);
fx=fft(ygauss);
dfx=fs/N;
n=0:N/2;
f=n*dfx;
axes(handles.axes5);
plot(f,abs(fx(n+1))*2/N);title('高斯信道中已调信号频谱');
xlabel('频率');
ylabel('幅度');
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fs=20000;
[ygauss]=audioread('FDM.wav');
%设计滤波器通带截止频率为2100-5900Hz,阻带截止频率为2000-6000Hz,
Wp1=[2100 5900]/(fs/2);
Ws1=[2000 6000]/(fs/2);
%通带最大衰减为1db,阻带最小衰减为5d b
Rp=1;Rs=5;
[N1, Wn1] = buttord(Wp1, Ws1, Rp, Rs);
[B1,A1] = butter(N1,Wn1,'bandpass');
y1 = filter(B1,A1,ygauss);
audiowrite('filter1.wav',y1,20000)
%画出经过滤波器后的第一路高频载波
N=length(y1);
fx=fft(y1);
dfx=fs/N;
n=0:N/2;
f=n*dfx;
axes(handles.axes6);
plot(f,abs(fx(n+1))*2/N);
title('信号通过滤波器滤出的第一路载波频谱');
xlabel('Hz');
ylabel('幅度');
%以同样的方法设计第二个带通滤波器
fs=25000;
[ygauss]=audioread('FDM.wav');
Rp=1;Rs=5;
Wp2=[6100 9900]/(fs/2);
Ws2=[5300 10500]/(fs/2);
[N2, Wn2] = buttord(Wp2, Ws2, Rp, Rs);
[B2,A2] = butter(N2,Wn2,'bandpass');
y2 = filter(B2,A2,ygauss);
audiowrite('filter2.wav',y2,20000)
%画出经过滤波器后的第二路高频载波
N=length(y2);
fx=fft(y2);