gusucode.com > matlab编程一个频分复用系统的模拟源码程序 > matlab编程一个频分复用系统的模拟源码程序/code/DSP_test/DSP_test.m

    function varargout = DSP_test(varargin)
% DSP_TEST M-file for DSP_test.fig
%      DSP_TEST, by itself, creates a new DSP_TEST or raises the existing
%      singleton*.
%
%      H = DSP_TEST returns the handle to a new DSP_TEST or the handle to
%      the existing singleton*.
%
%      DSP_TEST('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DSP_TEST.M with the given input arguments.
%
%      DSP_TEST('Property','Value',...) creates a new DSP_TEST or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before DSP_test_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to DSP_test_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 DSP_test

% Last Modified by GUIDE v2.5 18-Nov-2015 16:38:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @DSP_test_OpeningFcn, ...
                   'gui_OutputFcn',  @DSP_test_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 DSP_test is made visible.
function DSP_test_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 DSP_test (see VARARGIN)

% Choose default command line output for DSP_test
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes DSP_test wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = DSP_test_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end


% --- 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)
val_pop3=get(handles.popupmenu3,'Value'); 
switch val_pop3
    case 1
        [x1 Fs nbits]=wavread('youki1.wav');
        [n m]=size(x1);
        t=0:1/Fs:(length(x1)/Fs-1/Fs);
        plot(handles.axes1,t,x1);
        title(handles.axes1,'Original signal 1');xlabel(handles.axes1,'Time(S)');
        [x2 Fs nbits]=wavread('youki2.wav');        
        plot(handles.axes2,t,x2);
        title(handles.axes2,'Original signal 2');xlabel(handles.axes2,'Time(S)');
        [x3 Fs nbits]=wavread('youki3.wav');
        plot(handles.axes3,t,x3);
        title(handles.axes3,'Original signal 3');xlabel(handles.axes3,'Time(S)');
    case 2
        x1=[0 1 0];
        x2=[0 1 0];
        x3=[0 1 0];
        n0=1024;
        x1=snrz(x1,n0);
        x2=snrz(x2,n0);
        x3=snrz(x3,n0);
        Fs=270000;
        Ts=1/Fs;
        t=-Ts:Ts/n0:2*Ts-Ts/n0;
        n=size(x1);
%         X1=fft(x1);
%        f=0:Fs/n:Fs/2;
        plot(handles.axes1,t,x1);
        axis(handles.axes1,[-Ts 2*Ts -0.5 1.5]);
        title(handles.axes1,'Original signal_1');xlabel(handles.axes1,'Time(S)');
        plot(handles.axes2,t,x2);
        axis(handles.axes2,[-Ts 2*Ts -0.5 1.5]);
        title(handles.axes2,'Original signal_1');xlabel(handles.axes2,'Time(S)');
        plot(handles.axes3,t,x3);
        axis(handles.axes3,[-Ts 2*Ts -0.5 1.5]);
        title(handles.axes3,'Original signal_1');xlabel(handles.axes3,'Time(S)');
end
handles.t=t;
handles.x1=x1;
handles.x2=x2;
handles.x3=x3;
handles.Fs=Fs;
guidata(hObject,handles);

% --- 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)
val_pop3=get(handles.popupmenu3,'Value'); 
val_pop1=get(handles.popupmenu1,'Value'); 

x1_LPF=handles.x1_LPF;
x2_LPF=handles.x2_LPF;
x3_LPF=handles.x3_LPF;
Fs=handles.Fs;
f=handles.f;
% switch val_pop3
%     case 1
%         f1=4000;w1=2*pi*f1;
%         f2=11000;w2=2*pi*f2;
%         f3=18000;w3=2*pi*f3;
%     case 2
%         f1=35000;w1=2*pi*f1;
%         f2=60000;w2=2*pi*f2;
%         f3=90000;w3=2*pi*f3;
% end
f1=str2num(get(handles.edit2,'String'));
f2=str2num(get(handles.edit3,'String'));
f3=str2num(get(handles.edit4,'String'));
w1=2*pi*f1;w2=2*pi*f2;w3=2*pi*f3;
switch val_pop3
    case 1
        switch val_pop1
            case 1
                x1_mod=Modulation_AM(x1_LPF,w1,Fs,0.5);
                x2_mod=Modulation_AM(x2_LPF,w2,Fs,0.5);
                x3_mod=Modulation_AM(x3_LPF,w3,Fs,0.5);
            case 2
                x1_mod=Modulation_FM(x1_LPF,w1,Fs);
                x2_mod=Modulation_FM(x2_LPF,w2,Fs);
                x3_mod=Modulation_FM(x3_LPF,w3,Fs);
        end
    case 2
        switch val_pop1
            case 1
                x1_mod=Modulation_2ASK(x1_LPF,w1,Fs);
                x2_mod=Modulation_2ASK(x2_LPF,w2,Fs);
                x3_mod=Modulation_2ASK(x3_LPF,w3,Fs);
            case 2
                x1_mod=Modulation_2FSK(x1_LPF,w1-2*pi*4200,w1+2*pi*4200,Fs);
                x2_mod=Modulation_2FSK(x2_LPF,w2-2*pi*4200,w2+2*pi*4200,Fs);
                x3_mod=Modulation_2FSK(x3_LPF,w3-2*pi*4200,w3+2*pi*4200,Fs);
            end
end
        
handles.x1_mod=x1_mod;
handles.x2_mod=x2_mod;
handles.x3_mod=x3_mod;
handles.f1=f1;
handles.f2=f2;
handles.f3=f3;
switch val_pop3
    case 1
        t=0:1/Fs:(length(x1_LPF)/Fs-1/Fs);
        X1_mod=fft(x1_mod);
        plot(handles.axes1,t,x1_mod);
        title(handles.axes1,'Modulation signal');xlabel(handles.axes1,'Time(S)');       
        plot(handles.axes2,f,abs(X1_mod(1:fix(length(X1_mod)/2)+1)));
        axis(handles.axes2,[0 Fs/2 0 300]);
        title(handles.axes2,'Modulation signal 1 frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
    case 2
        t=handles.t;
        X1_mod=PSD(x1_mod);
        plot(handles.axes1,t,x1_mod);
        title(handles.axes1,'Modulation signal');xlabel(handles.axes1,'Time(S)');
        plot(handles.axes2,abs(X1_mod(1:fix(length(X1_mod)/2)+1)));
        title(handles.axes2,'Modulation signal 1 PSD');xlabel(handles.axes2,'');
end
guidata(hObject,handles);

% --- 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)
val_pop3=get(handles.popupmenu3,'Value'); 
f=handles.f;
Fs=handles.Fs;

x1_mod_BPF=handles.x1_mod_BPF;
x2_mod_BPF=handles.x2_mod_BPF;
x3_mod_BPF=handles.x3_mod_BPF;
%X1_mod_BPF=handles.X1_mod_BPF;
%X2_mod_BPF=handles.X2_mod_BPF;
%X3_mod_BPF=handles.X3_mod_BPF;

y=x1_mod_BPF+x2_mod_BPF+x3_mod_BPF;
SNR=str2num(get(handles.edit5,'String'));
%y=y+0.005*randn(length(y),1);
%y=awgn(y,ni);
%noise=wgn(length(y),1,ni,'dBw');
y_power=sum(abs(y(:)).^2);
noisePower=sqrt(y_power/(10^(SNR/10)));
y=y+noisePower*randn(length(y),1);
t=0:1/Fs:(length(y)/Fs-1/Fs);
plot(handles.axes1,t,y);
title(handles.axes1,'channel signal');xlabel(handles.axes1,'Time(S)');

switch val_pop3
    case 1
        Y=fft(y);
        plot(handles.axes2,f,abs(Y(1:fix(length(Y)/2)+1)));
        axis(handles.axes2,[0 Fs/2 0 300]);
        title(handles.axes2,'channel signal frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
    case 2
        Y=PSD(y);
        plot(handles.axes2,abs(Y(1:fix(length(Y)/2)+1)));
        title(handles.axes2,'channel signal PSD');xlabel(handles.axes2,'');
end
title(handles.axes3,'');xlabel(handles.axes3,'');
handles.y=y;
handles.noisePower=noisePower;
cla(handles.axes3);

guidata(hObject,handles);
% --- 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)
val_pop3=get(handles.popupmenu3,'Value'); 
val_pop1=get(handles.popupmenu1,'Value'); 
switch val_pop3
    case 1
        y1_Dem_BPF=handles.y1_Dem_BPF;
        y2_Dem_BPF=handles.y2_Dem_BPF;
        y3_Dem_BPF=handles.y3_Dem_BPF;
    case 2
        switch val_pop1
            case 1
                y1_Dem_BPF=handles.y1_Dem_BPF;
                y2_Dem_BPF=handles.y2_Dem_BPF;
                y3_Dem_BPF=handles.y3_Dem_BPF;
            case 2
                y11_Dem_BPF=handles.y11_Dem_BPF;
                y21_Dem_BPF=handles.y21_Dem_BPF;
                y31_Dem_BPF=handles.y31_Dem_BPF; 
                y12_Dem_BPF=handles.y12_Dem_BPF;
                y22_Dem_BPF=handles.y22_Dem_BPF;
                y32_Dem_BPF=handles.y32_Dem_BPF; 
        end
end
Fs=handles.Fs;
f1=handles.f1;
f2=handles.f2;
f3=handles.f3;
f=handles.f;

w1=2*pi*f1;w2=2*pi*f2;w3=2*pi*f3;
switch val_pop3
    case 1
        switch val_pop1
            case 1
                 y1_Dem=Demodulation_C_AM(y1_Dem_BPF,w1,Fs,0.5);
                 y2_Dem=Demodulation_C_AM(y2_Dem_BPF,w2,Fs,0.5);
                 y3_Dem=Demodulation_C_AM(y3_Dem_BPF,w3,Fs,0.5);
            case 2
                 y1_Dem=Demodulation_FM(y1_Dem_BPF,w1,Fs);
                 y2_Dem=Demodulation_FM(y2_Dem_BPF,w2,Fs);
                 y3_Dem=Demodulation_FM(y3_Dem_BPF,w3,Fs);
        end
    case 2
        switch val_pop1
            case 1
                 y1_Dem=Demodulation_2ASK(y1_Dem_BPF,w1,Fs);
                 y2_Dem=Demodulation_2ASK(y2_Dem_BPF,w2,Fs);
                 y3_Dem=Demodulation_2ASK(y3_Dem_BPF,w3,Fs);
            case 2
                 y11_Dem=Demodulation_2FSK(y11_Dem_BPF,Fs);
                 y12_Dem=Demodulation_2FSK(y12_Dem_BPF,Fs);
                 y1_Dem=y11_Dem+y12_Dem;
                 y21_Dem=Demodulation_2FSK(y21_Dem_BPF,Fs);
                 y22_Dem=Demodulation_2FSK(y22_Dem_BPF,Fs);
                 y2_Dem=y21_Dem+y22_Dem;
                 y31_Dem=Demodulation_2FSK(y31_Dem_BPF,Fs);
                 y32_Dem=Demodulation_2FSK(y32_Dem_BPF,Fs);
                 y3_Dem=y31_Dem+y32_Dem;
        end
end

Y1_Dem=fft(y1_Dem);
Y2_Dem=fft(y2_Dem);
Y3_Dem=fft(y3_Dem);

switch val_pop3
    case 1
        switch val_pop1
            case 1
                plot(handles.axes1,f,abs(Y1_Dem(1:fix(length(Y1_Dem)/2)+1)));
                axis(handles.axes1,[0 Fs/2 0 300]);
                title(handles.axes1,'Demodulation signal 1 frequency spectrum');xlabel(handles.axes1,'frequency(Hz)');
                plot(handles.axes2,f,abs(Y2_Dem(1:fix(length(Y2_Dem)/2)+1)));
                axis(handles.axes2,[0 Fs/2 0 300]);
                title(handles.axes2,'Demodulation signal 2 frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
                plot(handles.axes3,abs(Y3_Dem));
                plot(handles.axes3,f,abs(Y3_Dem(1:fix(length(Y3_Dem)/2)+1)));
                axis(handles.axes3,[0 Fs/2 0 300]);
                title(handles.axes3,'Demodulation signal 3 frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');              
            case 2
                plot(handles.axes1,f,abs(Y1_Dem(1:fix(length(Y1_Dem)/2)+1)));
                axis(handles.axes1,[0 Fs/2 0 500]);
                title(handles.axes1,'Demodulation signal 1 frequency spectrum');xlabel(handles.axes1,'frequency(Hz)');
                plot(handles.axes2,f,abs(Y2_Dem(1:fix(length(Y2_Dem)/2)+1)));
                axis(handles.axes2,[0 Fs/2 0 500]);
                title(handles.axes2,'Demodulation signal 2 frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
                plot(handles.axes3,abs(Y3_Dem));
                plot(handles.axes3,f,abs(Y3_Dem(1:fix(length(Y3_Dem)/2)+1)));
                axis(handles.axes3,[0 Fs/2 0 500]);
                title(handles.axes3,'Demodulation signal 3 frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');         
        end
    case 2
        plot(handles.axes1,abs(Y1_Dem(1:fix(length(Y1_Dem)/2)+1)));
        %plot(handles.axes1,y1_Dem);
        title(handles.axes1,'Demodulation signal 1 PSD');xlabel(handles.axes1,'frequency(Hz)');
        plot(handles.axes2,abs(Y2_Dem(1:fix(length(Y2_Dem)/2)+1)));
        title(handles.axes2,'Demodulation signal 2 PSD');xlabel(handles.axes2,'frequency(Hz)');
        plot(handles.axes3,abs(Y3_Dem(1:fix(length(Y3_Dem)/2)+1)));    
        title(handles.axes3,'Demodulation signal 3 PSD');xlabel(handles.axes3,'frequency(Hz)');
end

handles.y1_Dem=y1_Dem;
handles.y2_Dem=y2_Dem;
handles.y3_Dem=y3_Dem;

guidata(hObject,handles);
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3
%enu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end

val_pop3=get(handles.popupmenu3,'Value'); 
switch val_pop3
    case 1
        set(handles.popupmenu1,'String',{'AM';'FM'});;
        set(handles.edit2,'String','4000');
        set(handles.edit3,'String','11000');
        set(handles.edit4,'String','18000');
    case 2
        set(handles.popupmenu1,'String',{'2ASK';'2FSK';'2PSK'});
        set(handles.edit1,'String','80');
        set(handles.edit2,'String','30000');
        set(handles.edit3,'String','60000');
        set(handles.edit4,'String','90000');
end
clear all;

% --- 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)
val_pop3=get(handles.popupmenu3,'Value'); 
x1=handles.x1;
x2=handles.x2;
x3=handles.x3;
Fs=handles.Fs;
n=length(x1);

switch val_pop3
    case 1
        X1=fft(x1);
        X2=fft(x2);
        X3=fft(x3);
        f=0:Fs/n:Fs/2;
        handles.f=f;
        plot(handles.axes1,f,abs(X1(1:fix(n/2)+1)));
        axis(handles.axes1,[0 Fs/2 0 300]);
        title(handles.axes1,'Original signal 1 frequency spectrum');xlabel(handles.axes1,'frequency(Hz)');
        plot(handles.axes2,f,abs(X2(1:fix(n/2)+1)));
        axis(handles.axes2,[0 Fs/2 0 300]);
        title(handles.axes1,'Original signal 2 frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
        plot(handles.axes3,f,abs(X3(1:fix(n/2)+1)));
        axis(handles.axes3,[0 Fs/2 0 300]);
        title(handles.axes3,'Original signal 3 frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');
        handles.f=f;
    case 2
        X1=PSD(x1);
        X2=PSD(x2);
        X3=PSD(x3);
        f=0:Fs/2048:Fs/2;
        
        plot(handles.axes1,f,X1(1:fix(length(X1)/2)+1));
        axis(handles.axes1,[0 20000 0 1500]);
        title(handles.axes1,'Original signal 1 PSD');xlabel(handles.axes1,'frequency(Hz)');
        plot(handles.axes2,f,X2(1:fix(length(X2)/2)+1));
        axis(handles.axes2,[0 20000 0 1500]);
        title(handles.axes2,'Original signal 2 PSD');xlabel(handles.axes2,'frequency(Hz)'); 
        plot(handles.axes3,f,X3(1:fix(length(X3)/2)+1));
        axis(handles.axes3,[0 20000 0 1500]);
        title(handles.axes3,'Original signal 3 PSD');xlabel(handles.axes3,'frequency(Hz)');
        handles.f=f;
end
guidata(hObject,handles);


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val_pop2=get(handles.popupmenu2,'Value');
val_pop3=get(handles.popupmenu3,'Value'); 
Fs=handles.Fs;
f=handles.f;
x1=handles.x1;
x2=handles.x2;
x3=handles.x3;
set(handles.text3,'String',num2str(Fs));
f1p_mod_LPF=3000;f1s_mod_LPF=3500;
rp=3;rs=30;
w1p_mod_LPF=2*f1p_mod_LPF/Fs;w1s_mod_LPF=2*f1s_mod_LPF/Fs;
switch val_pop2
    case 1
        N=str2num(get(handles.edit1,'String'));
        LPF_Modb1=fir1(N,w1s_mod_LPF);
        LPF_Moda1=1;
        [LPF_Modh1 fw]=freqz(LPF_Modb1,LPF_Moda1,256);
    case 2
        [N Wn]=buttord(w1p_mod_LPF,w1s_mod_LPF,rp,rs);
        [LPF_Modb1 LPF_Moda1]=butter(N,Wn);
        [LPF_Modh1 fw]=freqz(LPF_Modb1,LPF_Moda1,256);
end
fw=fw./pi;   
plot(handles.axes2,fw,abs(LPF_Modh1));
axis(handles.axes2,[0 1 0 1]);
title(handles.axes2,'LP filter');xlabel(handles.axes2,'');
x1_LPF=filter(LPF_Modb1,LPF_Moda1,x1);
x2_LPF=filter(LPF_Modb1,LPF_Moda1,x2);
x3_LPF=filter(LPF_Modb1,LPF_Moda1,x3);
switch val_pop3
    case 1
        X1_LPF=fft(x1_LPF);
        plot(handles.axes3,f,abs(X1_LPF(1:fix(length(X1_LPF)/2)+1)));
        title(handles.axes3,'filter Signel');xlabel(handles.axes3,'frequency(Hz)');
    case 2
        X1_LPF=PSD(x1_LPF);
        plot(handles.axes3,abs(X1_LPF(1:fix(length(X1_LPF)/2)+1)));
        title(handles.axes3,'filter Signel 1 PSD');xlabel(handles.axes3,'');
end
handles.x1_LPF=x1_LPF;
handles.x2_LPF=x2_LPF;
handles.x3_LPF=x3_LPF;

guidata(hObject,handles);


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val_pop2=get(handles.popupmenu2,'Value'); 
val_pop3=get(handles.popupmenu3,'Value'); 
val_pop1=get(handles.popupmenu1,'Value'); 
Fs=handles.Fs;
f=handles.f;
x1_mod=handles.x1_mod;
x2_mod=handles.x2_mod;
x3_mod=handles.x3_mod;
f1=handles.f1;
f2=handles.f2;
f3=handles.f3;

f1_mod_BPFp=[f1-3000 f1+3000];
f1_mod_BPFs=[f1-3500 f1+3500];
f2_mod_BPFp=[f2-3000 f2+3000];
f2_mod_BPFs=[f2-3500 f2+3500];
f3_mod_BPFp=[f3-3000 f3+3000];
f3_mod_BPFs=[f3-3500 f3+3500];

rp=3;rs=30;
w1_mod_BPFp=2*f1_mod_BPFp/Fs;
w1_mod_BPFs=2*f1_mod_BPFs/Fs;
w2_mod_BPFp=2*f2_mod_BPFp/Fs;
w2_mod_BPFs=2*f2_mod_BPFs/Fs;
w3_mod_BPFp=2*f3_mod_BPFp/Fs;
w3_mod_BPFs=2*f3_mod_BPFs/Fs;
N=str2num(get(handles.edit1,'String'));
switch val_pop3
    case 1
        switch val_pop2
            case 1               
                BPF_Modb1=fir1(N,w1_mod_BPFs);
                BPF_Modb2=fir1(N,w2_mod_BPFs);
                BPF_Modb3=fir1(N,w3_mod_BPFs);
                BPF_Moda1=1;BPF_Moda2=1;BPF_Moda3=1;
                [BPF_Modh1 fw]=freqz(BPF_Modb1,BPF_Moda1,256);
                [BPF_Modh2 fw]=freqz(BPF_Modb2,BPF_Moda2,256);
                [BPF_Modh3 fw]=freqz(BPF_Modb3,BPF_Moda3,256);
            case 2
                [N1,Wn1]=buttord(w1_mod_BPFp,w1_mod_BPFs,rp,rs);
                [BPF_Modb1 BPF_Moda1]=butter(N1,Wn);
                [BPF_Modh1 fw]=freqz(BPF_Modb1,BPF_Moda1,256);
                [N2,Wn2]=buttord(w2_mod_BPFp,w2_mod_BPFs,rp,rs);
                [BPF_Modb2 BPF_Moda2]=butter(N2,Wn);
                [BPF_Modh2 fw]=freqz(BPF_Modb2,BPF_Moda2,256);
                [N3,Wn3]=buttord(w3_mod_BPFp,w3_mod_BPFs,rp,rs);
                [BPF_Modb3 BPF_Moda3]=butter(N3,Wn);
                [BPF_Modh3 fw]=freqz(BPF_Modb3,BPF_Moda3,256);
        end
    case 2
        switch val_pop1
            case 1
                  switch val_pop2
                    case 1
                        BPF_Modb1=fir1(N,w1_mod_BPFs);
                        BPF_Modb2=fir1(N,w2_mod_BPFs);
                        BPF_Modb3=fir1(N,w3_mod_BPFs);
                        BPF_Moda1=1;BPF_Moda2=1;BPF_Moda3=1;
                        [BPF_Modh1 fw]=freqz(BPF_Modb1,BPF_Moda1,256);
                        [BPF_Modh2 fw]=freqz(BPF_Modb2,BPF_Moda2,256);
                        [BPF_Modh3 fw]=freqz(BPF_Modb3,BPF_Moda3,256);
                    case 2
                        [N1,Wn1]=buttord(w1_mod_BPFp,w1_mod_BPFs,rp,rs);
                        [BPF_Modb1 BPF_Moda1]=butter(N1,Wn1);
                        [BPF_Modh1 fw]=freqz(BPF_Modb1,BPF_Moda1,256);
                        [N2,Wn2]=buttord(w2_mod_BPFp,w2_mod_BPFs,rp,rs);
                        [BPF_Modb2 BPF_Moda2]=butter(N2,Wn2);
                        [BPF_Modh2 fw]=freqz(BPF_Modb2,BPF_Moda2,256);
                        [N3,Wn3]=buttord(w3_mod_BPFp,w3_mod_BPFs,rp,rs);
                        [BPF_Modb3 BPF_Moda3]=butter(N3,Wn3);
                        [BPF_Modh3 fw]=freqz(BPF_Modb3,BPF_Moda3,256);
                end
            case 2
                        BPF_Modb11=fir1(N,w1_mod_BPFs-2*pi*2300/Fs);
                        BPF_Modb12=fir1(N,w1_mod_BPFs+2*pi*2300/Fs);
                        BPF_Modb21=fir1(N,w2_mod_BPFs-2*pi*2300/Fs);
                        BPF_Modb22=fir1(N,w2_mod_BPFs+2*pi*2300/Fs);
                        BPF_Modb31=fir1(N,w3_mod_BPFs-2*pi*2300/Fs);
                        BPF_Modb32=fir1(N,w3_mod_BPFs+2*pi*2300/Fs);
                        BPF_Modb1=BPF_Modb11+BPF_Modb12;
                        BPF_Modb2=BPF_Modb21+BPF_Modb22;
                        BPF_Modb3=BPF_Modb31+BPF_Modb32;
                        BPF_Moda1=1;BPF_Moda2=1;BPF_Moda3=1;
                        [BPF_Modh1 fw]=freqz(BPF_Modb1,BPF_Moda1,256);
                        [BPF_Modh2 fw]=freqz(BPF_Modb2,BPF_Moda2,256);
                        [BPF_Modh3 fw]=freqz(BPF_Modb3,BPF_Moda3,256);
            case 3
                ;
        end
end
fw=fw./pi;
plot(handles.axes1,fw,abs(BPF_Modh1));
title(handles.axes1,'BP filter');xlabel(handles.axes1,'');

x1_mod_BPF=filter(BPF_Modb1,BPF_Moda1,x1_mod);
x2_mod_BPF=filter(BPF_Modb2,BPF_Moda2,x2_mod);
x3_mod_BPF=filter(BPF_Modb3,BPF_Moda3,x3_mod);
% x1_mod_BPF=x1_mod;
% x2_mod_BPF=x2_mod;
% x3_mod_BPF=x3_mod;
switch val_pop3
    case 1
        X1_mod_BPF=fft(x1_mod_BPF);
        X2_mod_BPF=fft(x2_mod_BPF);
        X3_mod_BPF=fft(x3_mod_BPF);
        plot(handles.axes2,f,abs(X1_mod_BPF(1:fix(length(X1_mod_BPF)/2)+1)));
        axis(handles.axes2,[0 Fs/2 0 400]);
        title(handles.axes2,'filter Signel 1 frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
        cla(handles.axes3);
        hold on
        plot(handles.axes3,f,abs(X1_mod_BPF(1:fix(length(X1_mod_BPF)/2)+1)),'r');
        plot(handles.axes3,f,abs(X2_mod_BPF(1:fix(length(X2_mod_BPF)/2)+1)),'g');
        plot(handles.axes3,f,abs(X3_mod_BPF(1:fix(length(X3_mod_BPF)/2)+1)),'b');
        axis(handles.axes3,[0 Fs/2 0 400]);
        title(handles.axes3,'filter Signel frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');
        hold off
    case 2
        X1_mod_BPF=PSD(x1_mod_BPF);
        X2_mod_BPF=PSD(x2_mod_BPF);
        X3_mod_BPF=PSD(x3_mod_BPF);
        plot(handles.axes2,abs(X1_mod_BPF(1:fix(length(X1_mod_BPF)/2)+1)));
        title(handles.axes2,'filter Signel 1 PSD');xlabel(handles.axes2,'');        
        cla(handles.axes3);
        hold on
        plot(handles.axes3,abs(X1_mod_BPF(1:fix(length(X1_mod_BPF)/2)+1)),'r');
        plot(handles.axes3,abs(X2_mod_BPF(1:fix(length(X2_mod_BPF)/2)+1)),'g');
        plot(handles.axes3,abs(X3_mod_BPF(1:fix(length(X3_mod_BPF)/2)+1)),'b');
        title(handles.axes3,'filter Signel PSD');xlabel(handles.axes3,'frequency(Hz)');
        hold off
end      

handles.x1_mod_BPF=x1_mod_BPF;
handles.x2_mod_BPF=x2_mod_BPF;
handles.x3_mod_BPF=x3_mod_BPF;

% handles.X1_mod_BPF=X1_mod_BPF;
% handles.X2_mod_BPF=X2_mod_BPF;
% handles.X3_mod_BPF=X3_mod_BPF;

guidata(hObject,handles);


% --- 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)
val_pop2=get(handles.popupmenu2,'Value'); 
val_pop3=get(handles.popupmenu3,'Value'); 
val_pop1=get(handles.popupmenu1,'Value'); 
Fs=handles.Fs;
f=handles.f;
y=handles.y;

f1=handles.f1;
f2=handles.f2;
f3=handles.f3;

f1_Dem_BPFp=[f1-3000 f1+3000];
f1_Dem_BPFs=[f1-3200 f1+3200];
f2_Dem_BPFp=[f2-3000 f2+3000];
f2_Dem_BPFs=[f2-3200 f2+3200];
f3_Dem_BPFp=[f3-3000 f3+3000];
f3_Dem_BPFs=[f3-3200 f3+3200];

rp=3;rs=30;
w1_Dem_BPFp=2*f1_Dem_BPFp/Fs;
w1_Dem_BPFs=2*f1_Dem_BPFs/Fs;
w2_Dem_BPFp=2*f2_Dem_BPFp/Fs;
w2_Dem_BPFs=2*f2_Dem_BPFs/Fs;
w3_Dem_BPFp=2*f3_Dem_BPFp/Fs;
w3_Dem_BPFs=2*f3_Dem_BPFs/Fs;
N=str2num(get(handles.edit1,'String'));
switch val_pop3
    case 1
        switch val_pop2
            case 1
                BPF_Demb1=fir1(N,w1_Dem_BPFs);
                BPF_Demb2=fir1(N,w2_Dem_BPFs);
                BPF_Demb3=fir1(N,w3_Dem_BPFs);
                BPF_Dema1=1;BPF_Dema2=1;BPF_Dema3=1;
                [BPF_Demh1 fw]=freqz(BPF_Demb1,BPF_Dema1,256);
                [BPF_Demh2 fw]=freqz(BPF_Demb2,BPF_Dema2,256);
                [BPF_Demh3 fw]=freqz(BPF_Demb3,BPF_Dema3,256);
            case 2
                [N1,Wn1]=buttord(w1_Dem_BPFp,w1_Dem_BPFs,rp,rs);
                [BPF_Demb1 BPF_Dema1]=butter(N1,Wn1);
                [BPF_Demh1 fw]=freqz(BPF_Demb1,BPF_Dema1,256);
                [N2,Wn2]=buttord(w2_Dem_BPFp,w2_Dem_BPFs,rp,rs);
                [BPF_Demb2 BPF_Dema2]=butter(N2,Wn2);
                [BPF_Demh2 fw]=freqz(BPF_Demb2,BPF_Dema2,256);
                [N3,Wn3]=buttord(w3_Dem_BPFp,w3_Dem_BPFs,rp,rs);
                [BPF_Demb3 BPF_Dema3]=butter(N3,Wn3);
                [BPF_Demh3 fw]=freqz(BPF_Demb3,BPF_Dema3,256);
        end
    case 2
        switch val_pop1
            case 1
                    switch val_pop2
                        case 1
                            BPF_Demb1=fir1(N,w1_Dem_BPFs);
                            BPF_Demb2=fir1(N,w2_Dem_BPFs);
                            BPF_Demb3=fir1(N,w3_Dem_BPFs);
                            BPF_Dema1=1;BPF_Dema2=1;BPF_Dema3=1;
                            [BPF_Demh1 fw]=freqz(BPF_Demb1,BPF_Dema1,256);
                            [BPF_Demh2 fw]=freqz(BPF_Demb2,BPF_Dema2,256);
                            [BPF_Demh3 fw]=freqz(BPF_Demb3,BPF_Dema3,256);
                        case 2
                            [N1,Wn1]=buttord(w1_Dem_BPFp,w1_Dem_BPFs,rp,rs);
                            [BPF_Demb1 BPF_Dema1]=butter(N1,Wn1);
                            [BPF_Demh1 fw]=freqz(BPF_Demb1,BPF_Dema1,256);
                            [N2,Wn2]=buttord(w2_Dem_BPFp,w2_Dem_BPFs,rp,rs);
                            [BPF_Demb2 BPF_Dema2]=butter(N2,Wn2);
                            [BPF_Demh2 fw]=freqz(BPF_Demb2,BPF_Dema2,256);
                            [N3,Wn3]=buttord(w3_Dem_BPFp,w3_Dem_BPFs,rp,rs);
                            [BPF_Demb3 BPF_Dema3]=butter(N3,Wn3);
                            [BPF_Demh3 fw]=freqz(BPF_Demb3,BPF_Dema3,256);
                    end
            case 2           
                  switch val_pop2
                        case 1
                            BPF_Demb11=fir1(N,w1_Dem_BPFs-2*pi*2300/Fs);
                            BPF_Demb12=fir1(N,w1_Dem_BPFs+2*pi*2300/Fs);
                            BPF_Demb21=fir1(N,w2_Dem_BPFs-2*pi*2300/Fs);
                            BPF_Demb22=fir1(N,w2_Dem_BPFs+2*pi*2300/Fs);
                            BPF_Demb31=fir1(N,w3_Dem_BPFs-2*pi*2300/Fs);
                            BPF_Demb32=fir1(N,w3_Dem_BPFs+2*pi*2300/Fs);
                            BPF_Dema11=1;BPF_Dema21=1;BPF_Dema31=1;
                            BPF_Dema12=1;BPF_Dema22=1;BPF_Dema32=1;
                            [BPF_Demh11 fw]=freqz(BPF_Demb11,BPF_Dema11,256);
                            [BPF_Demh12 fw]=freqz(BPF_Demb12,BPF_Dema12,256);
                            [BPF_Demh21 fw]=freqz(BPF_Demb21,BPF_Dema21,256);
                            [BPF_Demh22 fw]=freqz(BPF_Demb22,BPF_Dema22,256);
                            [BPF_Demh31 fw]=freqz(BPF_Demb31,BPF_Dema31,256);
                            [BPF_Demh32 fw]=freqz(BPF_Demb32,BPF_Dema32,256);
                        case 2
                            [N1,Wn1]=buttord(w1_Dem_BPFp,w1_Dem_BPFs,rp,rs);
                            [BPF_Demb1 BPF_Dema1]=butter(N1,Wn1);
                            [BPF_Demh1 fw]=freqz(BPF_Demb1,BPF_Dema1,256);
                            [N2,Wn2]=buttord(w2_Dem_BPFp,w2_Dem_BPFs,rp,rs);
                            [BPF_Demb2 BPF_Dema2]=butter(N2,Wn2);
                            [BPF_Demh2 fw]=freqz(BPF_Demb2,BPF_Dema2,256);
                            [N3,Wn3]=buttord(w3_Dem_BPFp,w3_Dem_BPFs,rp,rs);
                            [BPF_Demb3 BPF_Dema3]=butter(N3,Wn3);
                            [BPF_Demh3 fw]=freqz(BPF_Demb3,BPF_Dema3,256);
                  end
        end
end
        
fw=fw./pi;
switch val_pop3
    case 1
        cla(handles.axes1);
        axes(handles.axes1);
        hold on
        plot(handles.axes1,fw,abs(BPF_Demh1),'r');
        plot(handles.axes1,fw,abs(BPF_Demh2),'g');
        plot(handles.axes1,fw,abs(BPF_Demh3),'b');
        title(handles.axes1,'BP filter');xlabel(handles.axes1,'');
        hold off
        y1_Dem_BPF=filter(BPF_Demb1,BPF_Dema1,y);
        y2_Dem_BPF=filter(BPF_Demb2,BPF_Dema2,y);
        y3_Dem_BPF=filter(BPF_Demb3,BPF_Dema3,y);
    case 2
        switch val_pop1
            case 1
                cla(handles.axes1);
                axes(handles.axes1);
                hold on
                plot(handles.axes1,fw,abs(BPF_Demh1),'r');
                plot(handles.axes1,fw,abs(BPF_Demh2),'g');
                plot(handles.axes1,fw,abs(BPF_Demh3),'b');
                title(handles.axes1,'BP filter');xlabel(handles.axes1,'');
                hold off
                y1_Dem_BPF=filter(BPF_Demb1,BPF_Dema1,y);
                y2_Dem_BPF=filter(BPF_Demb2,BPF_Dema2,y);
                y3_Dem_BPF=filter(BPF_Demb3,BPF_Dema3,y);            
            case 2
                cla(handles.axes1);
                axes(handles.axes1);
                hold on
                plot(handles.axes1,fw,abs(BPF_Demh11),'r');
                plot(handles.axes1,fw,abs(BPF_Demh12),'r');
                plot(handles.axes1,fw,abs(BPF_Demh21),'g');
                plot(handles.axes1,fw,abs(BPF_Demh22),'g');
                plot(handles.axes1,fw,abs(BPF_Demh31),'b');
                plot(handles.axes1,fw,abs(BPF_Demh32),'b');
                title(handles.axes1,'BP filter');xlabel(handles.axes1,'');
                hold off
                y11_Dem_BPF=filter(BPF_Demb11,BPF_Dema11,y);
                y12_Dem_BPF=filter(BPF_Demb12,BPF_Dema12,y);                
                y21_Dem_BPF=filter(BPF_Demb21,BPF_Dema21,y);
                y22_Dem_BPF=filter(BPF_Demb22,BPF_Dema22,y);
                y31_Dem_BPF=filter(BPF_Demb31,BPF_Dema31,y);    
                y32_Dem_BPF=filter(BPF_Demb32,BPF_Dema32,y);  
        end
end

switch val_pop3
    case 1
        cla(handles.axes2);
        Y1_Dem_BPF=fft(y1_Dem_BPF);
        Y2_Dem_BPF=fft(y2_Dem_BPF);
        Y3_Dem_BPF=fft(y3_Dem_BPF);
        axes(handles.axes2);
        hold on
        plot(handles.axes2,f,abs(Y1_Dem_BPF(1:fix(length(Y1_Dem_BPF)/2)+1)),'r');
        plot(handles.axes2,f,abs(Y2_Dem_BPF(1:fix(length(Y2_Dem_BPF)/2)+1)),'g');
        plot(handles.axes2,f,abs(Y3_Dem_BPF(1:fix(length(Y3_Dem_BPF)/2)+1)),'b');
        axis(handles.axes2,[0 Fs/2 0 300]);
        title(handles.axes2,'filter Signel frequency spectrum');xlabel(handles.axes2,'frequency(Hz)');
        hold off
    case 2
        switch val_pop1
            case 1
                Y1_Dem_BPF=PSD(y1_Dem_BPF);
                Y2_Dem_BPF=PSD(y2_Dem_BPF);
                Y3_Dem_BPF=PSD(y3_Dem_BPF);
                cla(handles.axes2);
                axes(handles.axes2);
                hold on
                plot(handles.axes2,abs(Y1_Dem_BPF(1:fix(length(Y1_Dem_BPF)/2)+1)),'r');
                plot(handles.axes2,abs(Y2_Dem_BPF(1:fix(length(Y2_Dem_BPF)/2)+1)),'g');
                plot(handles.axes2,abs(Y3_Dem_BPF(1:fix(length(Y3_Dem_BPF)/2)+1)),'b');
                title(handles.axes2,'filter Signel PSD');xlabel(handles.axes2,'');
                hold off
            case 2
                Y11_Dem_BPF=PSD(y11_Dem_BPF);
                Y12_Dem_BPF=PSD(y12_Dem_BPF);
                Y21_Dem_BPF=PSD(y21_Dem_BPF);
                Y22_Dem_BPF=PSD(y22_Dem_BPF);
                Y31_Dem_BPF=PSD(y31_Dem_BPF);
                Y32_Dem_BPF=PSD(y32_Dem_BPF);
                cla(handles.axes2);
                axes(handles.axes2);
                hold on
                plot(handles.axes2,abs(Y11_Dem_BPF(1:fix(length(Y11_Dem_BPF)/2)+1)),'r');
                plot(handles.axes2,abs(Y12_Dem_BPF(1:fix(length(Y12_Dem_BPF)/2)+1)),'r');
                plot(handles.axes2,abs(Y21_Dem_BPF(1:fix(length(Y21_Dem_BPF)/2)+1)),'g');
                plot(handles.axes2,abs(Y22_Dem_BPF(1:fix(length(Y22_Dem_BPF)/2)+1)),'g');
                plot(handles.axes2,abs(Y31_Dem_BPF(1:fix(length(Y31_Dem_BPF)/2)+1)),'b');
                plot(handles.axes2,abs(Y32_Dem_BPF(1:fix(length(Y32_Dem_BPF)/2)+1)),'b');
                title(handles.axes2,'filter Signel PSD');xlabel(handles.axes2,'');
                hold off                
        end
end

switch val_pop3
    case 1
        plot(handles.axes3,f,abs(Y1_Dem_BPF(1:fix(length(Y1_Dem_BPF)/2)+1)),'r');
        axis(handles.axes3,[0 Fs/2 0 200]);
        title(handles.axes3,'filter Signel 1 frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');
    case 2
        switch val_pop1
            case 1
                t=handles.t;
                plot(handles.axes3,t,y1_Dem_BPF,'r');
                title(handles.axes3,'filter Signel 1');xlabel(handles.axes3,'Time(S)');
            case 2
                t=handles.t;
                plot(handles.axes3,t,(y11_Dem_BPF+y12_Dem_BPF),'r');
                title(handles.axes3,'filter Signel 1');xlabel(handles.axes3,'Time(S)');               
        end
end

switch val_pop3
    case 1
        handles.y1_Dem_BPF=y1_Dem_BPF;
        handles.y2_Dem_BPF=y2_Dem_BPF;
        handles.y3_Dem_BPF=y3_Dem_BPF;
    case 2
        switch val_pop1
            case 1
                 handles.y1_Dem_BPF=y1_Dem_BPF;
                 handles.y2_Dem_BPF=y2_Dem_BPF;
                 handles.y3_Dem_BPF=y3_Dem_BPF;
            case 2
                 handles.y11_Dem_BPF=y11_Dem_BPF;
                 handles.y21_Dem_BPF=y21_Dem_BPF;
                 handles.y31_Dem_BPF=y31_Dem_BPF;
                 handles.y12_Dem_BPF=y12_Dem_BPF;
                 handles.y22_Dem_BPF=y22_Dem_BPF;
                 handles.y32_Dem_BPF=y32_Dem_BPF;       
        end
end
guidata(hObject,handles);


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val_pop2=get(handles.popupmenu2,'Value');
val_pop3=get(handles.popupmenu3,'Value');
Fs=handles.Fs;
f=handles.f;
t=handles.t;
y1_Dem=handles.y1_Dem;
y2_Dem=handles.y2_Dem;
y3_Dem=handles.y3_Dem;

f1p_Dem_LPF=3000;f1s_Dem_LPF=3500;
rp=3;rs=60;
w1p_Dem_LPF=2*f1p_Dem_LPF/Fs;w1s_Dem_LPF=2*f1s_Dem_LPF/Fs;
N=str2num(get(handles.edit1,'String'));
switch val_pop2
    case 1
        LPF_Demb1=fir1(N,w1s_Dem_LPF);
        LPF_Dema1=1;
        [LPF_Demh1 fw]=freqz(LPF_Demb1,LPF_Dema1,256);
    case 2
        [N Wn]=buttord(w1p_Dem_LPF,w1s_Dem_LPF,rp,rs);
        [LPF_Demb1 LPF_Dema1]=butter(N,Wn);
        [LPF_Demh1 fw]=freqz(LPF_Demb1,LPF_Dema1,256);
end
fw=fw./pi;

plot(handles.axes1,t,y1_Dem);
title(handles.axes1,'Demodulation signal 1');xlabel(handles.axes1,'Time(S)');
plot(handles.axes2,fw,abs(LPF_Demh1));
title(handles.axes2,'filter Signel 1');xlabel(handles.axes2,'frequency(Hz)');
y1_LPF=filter(LPF_Demb1,LPF_Dema1,y1_Dem);
y2_LPF=filter(LPF_Demb1,LPF_Dema1,y2_Dem);
y3_LPF=filter(LPF_Demb1,LPF_Dema1,y3_Dem);
Y1_LPF=fft(y1_LPF);

switch val_pop3
    case 1
        plot(handles.axes3,f,abs(Y1_LPF(1:fix(length(Y1_LPF)/2)+1)));
        axis(handles.axes3,[0 Fs/2 0 300]);
        title(handles.axes3,'filter Signel 1 frequency spectrum');xlabel(handles.axes3,'frequency(Hz)');
    case 2
        plot(handles.axes3,abs(Y1_LPF(1:fix(length(Y1_LPF)/2)+1)));
        title(handles.axes3,'filter Signel 1 PSD');xlabel(handles.axes3,'');
end
handles.y1_LPF=y1_LPF;
handles.y2_LPF=y2_LPF;
handles.y3_LPF=y3_LPF;
guidata(hObject,handles);

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
val_pop3=get(handles.popupmenu3,'Value');
val_pop2=get(handles.popupmenu2,'Value');
val_pop1=get(handles.popupmenu1,'Value');
Fs=handles.Fs;
y1_LPF=handles.y1_LPF;
y2_LPF=handles.y2_LPF;
y3_LPF=handles.y3_LPF;
x1=handles.x1;
x2=handles.x2;
x3=handles.x3;
noisePower=handles.noisePower;
switch val_pop3
    case 1
        switch val_pop2
            case 1                
                y1_LPF=(y1_LPF-mean(y1_LPF)).*2;
                y1_power=sum(abs(y1_LPF(:)).^2);
                SNR=10*log10(y1_power/noisePower^2);
                y2_LPF=(y2_LPF-mean(y2_LPF)).*2;
                %y2_power=sum(abs(y2_LPF(:)).^2)/length(y2_LPF(:));
                y3_LPF=(y3_LPF-mean(y3_LPF)).*2;
                t=0:1/Fs:(length(y1_LPF)/Fs-1/Fs);
                %set(handles.edit7,'String',num2str(SNR));
            case 2
                ;
        end
        cla(handles.axes1);
        axes(handles.axes1);
        hold on
        plot(handles.axes1,t,x1,'r');
        plot(handles.axes1,t,y1_LPF,'g');
        axis(handles.axes1,[0 1 -1 1]);
        title(handles.axes1,'Received signal 1');xlabel(handles.axes1,'Time(S)');
        hold off

        cla(handles.axes2);
        axes(handles.axes2);
        hold on
        plot(handles.axes2,t,x2,'r');
        plot(handles.axes2,t,y2_LPF,'g');
        axis(handles.axes2,[0 1 -1 1]);
        title(handles.axes2,'Received signal 1');xlabel(handles.axes2,'Time(S)');
        hold off

        cla(handles.axes3);
        axes(handles.axes3);
        hold on
        plot(handles.axes3,t,x3,'r');
        plot(handles.axes3,t,y3_LPF,'g');
        axis(handles.axes3,[0 1 -1 1]);
        title(handles.axes3,'Received signal 3');xlabel(handles.axes3,'Time(S)');
        hold off
    case 2
        switch val_pop1
            case 1
                t=handles.t;
                Ts=1/Fs;
                cla(handles.axes1);
                axes(handles.axes1);
                hold on
                plot(handles.axes1,t,x1,'r');
                plot(handles.axes1,t,y1_LPF,'g');
                axis(handles.axes1,[-Ts 2*Ts -0.5 1.5]);
                title(handles.axes1,'Received signal 1');xlabel(handles.axes1,'Time(S)');
                hold off

                cla(handles.axes2);
                axes(handles.axes2);
                hold on
                plot(handles.axes2,t,x2,'r');
                plot(handles.axes2,t,y2_LPF,'g');
                axis(handles.axes2,[-Ts 2*Ts -0.5 1.5]);
                title(handles.axes2,'Received signal 2');xlabel(handles.axes2,'Time(S)');
                hold off

                cla(handles.axes3);
                axes(handles.axes3);
                hold on
                plot(handles.axes3,t,x3,'r');
                plot(handles.axes3,t,y3_LPF,'g');
                axis(handles.axes3,[-Ts 2*Ts -0.5 1.5]);
                title(handles.axes3,'Received signal 3');xlabel(handles.axes3,'Time(S)');
                hold off
            case 2
                t=handles.t;
                Ts=1/Fs;
                cla(handles.axes1);
                axes(handles.axes1);
                hold on
                plot(handles.axes1,t,x1,'r');
                plot(handles.axes1,t,y1_LPF+1,'g');
                axis(handles.axes1,[-Ts 2*Ts -2.5 1.5]);
                title(handles.axes1,'Received signal 1');xlabel(handles.axes1,'Time(S)');
                hold off

                cla(handles.axes2);
                axes(handles.axes2);
                hold on
                plot(handles.axes2,t,x2,'r');
                plot(handles.axes2,t,y2_LPF+2,'g');
                axis(handles.axes2,[-Ts 2*Ts -2.5 1.5]);
                title(handles.axes2,'Received signal 2');xlabel(handles.axes2,'Time(S)');
                hold off

                cla(handles.axes3);
                axes(handles.axes3);
                hold on
                plot(handles.axes3,t,x3,'r');
                plot(handles.axes3,t,y3_LPF+3,'g');
                axis(handles.axes3,[-Ts 2*Ts -2.5 1.5]);
                title(handles.axes3,'Received signal 3');xlabel(handles.axes3,'Time(S)');
                hold off               
        end
end

function 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 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'));
end




% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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'));
end





function 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 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'));
end



function 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 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'));
end



function 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 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'));
end





function 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 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'));
end



function 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 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'));
end