自己写的模拟调制与解调 matlab gui程序

来源:互联网 发布:七秀成女捏脸数据网盘 编辑:程序博客网 时间:2024/05/08 12:19

 

 自己写的,里面是自己所学的MATLAB知识的集成

clear
echo off
h1 =figure( ...
    'menu','none',...
   'color',[0.925,0.914,0.847],...
   'position',[30 40.923 980.2 700],...
   'Name','广西工学院信息与计算科学系', ...
   'NumberTitle','off', 'HandleVisibility', 'on', ...
   'Visible','on', 'Resize', 'on',...
   'BusyAction','Queue','Interruptible','off',...
   'IntegerHandle', 'off', ...
   'Doublebuffer', 'on', ...
   'Colormap', gray(256));
h2 = uipanel(...
'Parent',h1,...
'Units','characters',...
'FontSize',10,...
'Title','选择参数模块',...
'TitlePosition','centertop',...
'Tag','uipanel1',...
'Clipping','on',...
'Position',[-0.2 0.0769230769230769 37.4 52.1538461538462]);

 

 

h6 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'Position',[4.4 20.3076923076923 26.2 6.30769230769231],...
'String',{  'AM'; 'DSB'; 'SSB' ;'DE-AM'; 'DE-DSB'; 'DE-SSB' },...
'Style','listbox',...
'Value',1,...
'Tag','listbox1');


h9 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',12,...
'Position',[10.2 6.92307692307687 13.4 1.92307692307692],...
'String','结束',...
'Tag','pushbutton2',...
'callback','close');


h10 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',10,...
'Position',[4.4 48.1538461538462 27.4 1.92307692307692],...
'String','幅度',...
'Style','text',...
'Tag','text1');

 

h11 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',10,...
'Position',[4.4 42.3846153846154 27.4 1.92307692307692],...
'String','频率',...
'Style','text',...
'Tag','text6' );


h12 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',10,...
'Position',[4.4 35.7692307692308 27.4 1.92307692307692],...
'String','载波频率',...
'Style','text',...
'Tag','text7' );


h13 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',10,...
'Position',[4.4 26.8461538461538 27.4 1.92307692307692],...
'String','信号调制与解调',...
'Style','text',...
'Tag','text8');

 

 

h3 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'Position',[4.4 45.9230769230769 27.2 2.30769230769231],...
'String',{  '5' },...
'Style','edit',...
'Tag','edit2');
h15 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[0.9 0.9 0.9],...
'Position',[4.4 44.4615384615385 27.2 1.61538461538462],...
'Value',5, ...%初始化变量值
'min',1, ...%设置输出最小值
'max',10, ...%设置输出最大值
'String',{  'Slider' },...
'Style','slider',...
'Tag','slider1',...
 'callback',[...
   'ww=num2str(get(h15,''Value''));',...
   'set(h3,''string'',ww);']);


h4 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'Position',[4.4 40.2307692307692 27.2 2.30769230769231],...
'String',{  '35' },...
'Style','edit',...
'Tag','edit3');

h16 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[0.9 0.9 0.9],...
'Position',[4.4 38.6153846153846 27.2 1.61538461538462],...
'String',{  'Slider' },...
'Value',35, ...%初始化变量值
'min',0, ...%设置输出最小值
'max',300, ...%设置输出最大值
'Style','slider',...
'Tag','slider2',...
'callback',[...
   'ww1=num2str(get(h16,''Value''));',...
   'set(h4,''string'',ww1);']);

h5 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[1 1 1],...
'Position',[4.4 32.8461538461538 27.2 2.30769230769231],...
'String',{  '300' },...
'Style','edit',...
'Tag','edit4');


h17 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'BackgroundColor',[0.9 0.9 0.9],...
'Position',[4.4 31.3846153846154 27.2 1.61538461538462],...
'String',{  'Slider' },...
'Value',300, ...%初始化变量值
'min',1, ...%设置输出最小值
'max',500, ...%设置输出最大值
'Style','slider',...
'Tag','slider4',...
'callback',[...
    'ww3=num2str(get(h17,''Value''));',...
   'set(h5,''string'',ww3);']);

 

h18 = uipanel(...
'Parent',h1,...
'Units','characters',...
'FontSize',10,...
'Title','显示界面',...
'Tag','uipanel2',...
'Clipping','on',...
'Position',[39.8 0.384615384615385 100 51.8461538461538]);
h19 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[3 43.7692307692308 93 8],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes1' );
h24 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[3 33.3076923076923 93 8.07692307692308],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes4' );
h29 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[3 22.1538461538462 93 8.76923076923077],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes6' );

h34 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[3 13 93 6.76923076923077],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes7' );

h431 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[3 3 93 8.15384615384616],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'Tag','axes8');

 

h39 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[35.6 51.0769230769231 59.6 1.461],...
'HorizontalAlignment','left',...
'String','调制信号波形',...
'Style','text',...
'Tag','text11' );

h40 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[35.4 41.4615384615385 40 1.53846153846154],...
'HorizontalAlignment','left',...
'String','载波信号波形',...
'Style','text',...
'Tag','text12');

 

h41 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[35.4 31.4615384615385 59 1.53846153846154],...
'HorizontalAlignment','left',...
'String','已调信号波形',...
'Style','text',...
'Tag','text13');

 

h42 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[35.6 20.2307692307692 59.6 1.46153846153846],...
'HorizontalAlignment','left',...
'String','原始载波频谱',...
'Style','text',...
'Tag','text14' );
h521 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[5.6 20.2307692307692 39.6 1.46],...
'HorizontalAlignment','left',...
'String','Lowpass Filter Characteristics',...
'visible','off',...
'Style','text',...
'Tag','text141' );

h522 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[5.6 11.5 39.6 1.46],...
'HorizontalAlignment','left',...
'String','Spectrum of the Demodulator output',...
'visible','off',...
'Style','text',...
'Tag','text142' );

h523 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[62.6 20.2307692307692 28.6 1.46],...
'HorizontalAlignment','left',...
'String','The Message Signal',...
'visible','off',...
'Style','text',...
'Tag','text143' );

h524 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[63.6 11.5 28.6 1.46],...
'HorizontalAlignment','center',...
'String','The Demodulator Output',...
'visible','off',...
'Style','text',...
'Tag','text144' );

h481 = uicontrol(...
'Parent',h18,...
'Units','characters',...
'FontSize',10,...
'Position',[37.4 11.5 59 1.2],...
'HorizontalAlignment','left',...
'String','已调信号频谱',...
'Style','text',...
'Tag','text15');


h43 = uipanel(...
'Parent',h1,...
'Units','characters',...
'FontSize',10,...
'Title','基础知识',...
'Tag','uipanel3',...
'Clipping','on',...
'Position',[139.8 2.15384615384615 50 43.6153846153846]);

 

h44 = uicontrol(...
'Parent',h43,...
'Units','characters',...
'FontSize',16,...
'BackgroundColor',[1 1 1],...
'Position',[1.2 1.07692307692307 46.8 41.2307692307692],...
'String',{  '请在这里改写你对实验的知识点的说明在在在这在这里改写你对实验的知识点的说明里改写你对实验的知识点的说明这里改写你对实验的知识点的说明这里改写你对实验的知识点的说明' },...
'Style','edit',...
'max',2,...
'Tag','edit1');


h45 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'CData',[],...
'FontSize',10,...
'Position',[169.8 47.1538461538462 17.4 2.38461538461538],...
'String','频域',...
'Style','radiobutton',...
'Tag','radiobutton3',...
'UserData',[],...
'callback',[...
'set(h46,''value'',0);']);

 

h46 = uicontrol(...
'Parent',h1,...
'Units','characters',...
'CData',[],...
'FontSize',10,...
'Position',[146.6 47.0769230769231 17.4 2.38461538461538],...
'String','时域',...
'Style','radiobutton',...
'Tag','radiobutton1',...
'UserData',[],...
'callback',[...
'set(h45,''value'',0);']);
set(h46,'value',1);
h432 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[55 13 50 6.7],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'visible','off',...
'Tag','axes8');
h433 = axes(...
'Parent',h18,...
'Units','characters',...
'Position',[55 3 50 8.15],...
'CameraPosition',[0.5 0.5 9.16025403784439],...
'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...
'Color',get(0,'defaultaxesColor'),...
'ColorOrder',get(0,'defaultaxesColorOrder'),...
'LooseInset',[11.986 4.52692307692308 8.759 3.08653846153846],...
'XColor',get(0,'defaultaxesXColor'),...
'YColor',get(0,'defaultaxesYColor'),...
'ZColor',get(0,'defaultaxesZColor'),...
'visible','off',...
'Tag','axes8');


h8 = uicontrol(...
'Parent',h2,...
'Units','characters',...
'FontSize',22,...
'Position',[6.8 10.7692307692307 23 3.23076923076923],...
'String','仿真',...
'Tag','pushbutton1',...
'callback',[...
   't0=0.15; ',...            %定义信号持续时间
   'ts=0.001;',...          %定义仿真时的信号采样率
    'fs=get(h16,''value'');',...%调制信号频率
   'df = 0.15;',... %频谱分辩率
   'fc=get(h17,''value'');',...             %载波信号频率
   'A=get(h15,''Value'');',...               %调制信号幅度
   't=[0:ts:t0]; ',...        %定义时间矢量
'm=A*sin(2*pi*fs.*t);',...      % 传输的信号
'c=cos(2*pi*fc.*t);',...   %载波信号
'u=(A+m).*c;' ,...     %调制信号
'[M,m,df1]=fftseq(m,ts,df);',...  %对调制信号m(t)求傅里叶变换
'M=M/fs;',...                %缩放,便于在频谱图上整体观察 
'[U,u,df1]=fftseq(u,ts,df);',...
'U=U/fs;',...
'f_cutoff=150;',...   %滤波器的截止频率                                
'n_cutoff=floor(150/df1);',... % 设计的滤波器的带宽
'f=[0:df1:df1*(length(m)-1)]-fs/2;',... %频率分量
'H=zeros(size(f));',... %构建滤波器的步骤之一
'H(1:n_cutoff)=2*ones(1,n_cutoff);',... %构建滤波器的步骤之一
'H(length(f)-n_cutoff+1:length(f))=2*ones(1,n_cutoff);',...%滤波器的频带函数
 'a=get(h6,''value'');',...%定制调制方式
  'rv1=get(h46,''value'');',...%选择的是时域调制
  'rv2=get(h45,''value'');',...%选择的是频域调制
 'if (a==1)&(rv1==1),',...%                                    am调制
       'set(h39,''string'',''原始信号'');',...
      'set(h40,''string'',''载波信号'');',...
      'set(h41,''string'',''调制信号'');',...
      'set(h42,''string'',''原始频谱'');',...
      'set(h481,''string'',''已调频谱'');',...
         'set(h431,''Position'',[3 3 93 8.15384615384616]);',...
        'set(h34,''Position'',[3 13 93 6.76923076923077]);',...
           'set(h432,''visible'',''off'');',...
         'set(h433,''visible'',''off'');',...
           'set(h42,''visible'',''on'');',...
          'set(h481,''visible'',''on'');',...
           'set(h521,''visible'',''off'');',...
          'set(h522,''visible'',''off'');',...
          'set(h523,''visible'',''off'');',...
          'set(h524,''visible'',''off'');',...
   'axes(h19);',...%1
   'plot(t,m(1:length(t)));',...
    'axis([0 0.15 -12 12]);',...
     'axes(h24);',...%2
   'plot(t,c(1:length(t)));',...
    'axis([0 0.15 -3 3]);',...
     'axes(h29);',...%3
   'plot(t,u(1:length(t)));',...
    'axis([0 0.15 -10 10]);',...
     'axes(h34);',...%4
     'plot(f,fftshift(abs(M)));',...
      'axes(h431);',...%5
     'plot(f,fftshift(abs(U)));',...
'elseif (a==2)&(rv1==1),',...                                      %dsb调制
      'set(h39,''string'',''The message signal'');',...
      'set(h40,''string'',''The carrier signal '');',...
      'set(h41,''string'',''The modulated signal'');',...
      'set(h42,''string'',''Spectrum of message '');',...
      'set(h481,''string'',''Spectrum of modulated signal'');',...
        'set(h431,''Position'',[3 3 93 8.15384615384616]);',...
        'set(h34,''Position'',[3 13 93 6.76923076923077]);',...
           'set(h432,''visible'',''off'');',...
         'set(h433,''visible'',''off'');',...
          'set(h42,''visible'',''on'');',...
          'set(h481,''visible'',''on'');',...
           'set(h521,''visible'',''off'');',...
          'set(h522,''visible'',''off'');',...
          'set(h523,''visible'',''off'');',...
          'set(h524,''visible'',''off'');',...
't0=.15;',...                              % signal duration
'ts=0.001;',...                             % sampling interval
'fc=get(h17,''value'');',...                % carrier frequency
'snr=20; ',...                              % SNR in dB (logarithmic)
'fs=get(h16,''value'');',...%调制信号频率
'df=0.3;',...                               % desired freq. resolution
't=[0:ts:t0];',...                          % time vector
'snr_lin=10^(snr/10);',...                  % linear SNR
'A=get(h15,''Value'');',...               %调制信号幅度
'm=(A/9)*[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];',...% message signal
'c=cos(2*pi*fc.*t);',...                    % carrier signal
'u=m.*c;  ',...                             % modulated signal
'[M,m,df1]=fftseq(m,ts,df);',...            % Fourier transform
'M=M/fs; ',...                              % scaling                  
'[U,u,df1]=fftseq(u,ts,df); ',...           % Fourier transform
'U=U/fs;',...                               % scaling
'[C,c,df1]=fftseq(c,ts,df); ',...           % Fourier transform
'f=[0:df1:df1*(length(m)-1)]-fs/2; ',...    % freq. vector
'signal_power=spower(u(1:length(t))); ',...   % power in modulated signal
'noise_power=signal_power/snr_lin;',...     % compute noise power
'noise_std=sqrt(noise_power); ',...         % compute noise standard deviation
'noise=noise_std*randn(1,length(u));',...   % generate noise
'r=u+noise;',...                            % add noise to the modulated signal
'[R,r,df1]=fftseq(r,ts,df);',...            % spectrum of the signal+noise
'R=R/fs; ',...                              % scaling
 'axes(h19);',...%1
 ' plot(t,m(1:length(t)));',...
    'axis([0 0.15 -3 3]);',...
 'axes(h24);',...%2
   'plot(t,c(1:length(t)));',...
   'axis([0 0.15 -3 3]);',...
'axes(h29);',...%3
   'plot(t,u(1:length(t)));',...
   'axis([0 0.15 -3 3]);',...
   'axes(h34);',...%4
     'plot(f,abs(fftshift(M)));',...
      'axes(h431);',...%5
     'plot(f,abs(fftshift(U)));',...
'elseif (a==3)&(rv1==1),',...                     %ssb调制
      'set(h39,''string'',''The message signal'');',...
      'set(h40,''string'',''The carrier signal'');',...
      'set(h41,''string'',''The LSSB modulated signal'');',...
      'set(h42,''string'',''Spectrum of the LSSB modulated signal '');',...
      'set(h481,''string'',''Spectrum of the message signal'');',...
        'set(h431,''Position'',[3 3 93 8.15384615384616]);',...
        'set(h34,''Position'',[3 13 93 6.76923076923077]);',...
           'set(h432,''visible'',''off'');',...
         'set(h433,''visible'',''off'');',...
          'set(h42,''visible'',''on'');',...
          'set(h481,''visible'',''on'');',...
           'set(h521,''visible'',''off'');',...
          'set(h522,''visible'',''off'');',...
          'set(h523,''visible'',''off'');',...
          'set(h524,''visible'',''off'');',...
 't0=.15;',...  %信号的持续时间
'ts=0.001;',...  %抽样间隔
 'fc=get(h17,''value'');',...             %载波信号频率
'snr=10;',...   %用DB表示的信噪比
'fs=get(h16,''value'');',...%调制信号频率
'df=0.25; ',...    %所需的频率分辨率
't=[0:ts:t0];',...  %时间向量
 'A=get(h15,''Value'');',...               %调制信号幅度
'snr_lin=10^(snr/10);',...   %线性信噪比
'm=A*[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];',...  %信息信号
'c=cos(2*pi*fc.*t);',...  %载波信号
'udsb=m.*c; ',...       %调制信号
'[UDSB,udssb,df1]=fftseq(udsb,ts,df);',...  %傅立叶变换
'UDSB=UDSB/fs; ',...  %缩放
'f=[0:df1:df1*(length(udssb)-1)]-fs/2;',...  %频率向量
'n2=ceil(fc/df1);',...%频率向量中载波的区域
'UDSB(n2:length(UDSB)-n2)=zeros(size(UDSB(n2:length(UDSB)-n2)));',...
'ULSSB=UDSB;',...%产生LSSB调制频谱
'[M,m,df1]=fftseq(m,ts,df);',...%傅立叶变换
'M=M/fs;',... %缩放
'u=real(ifft(ULSSB))*fs;',...%从频谱中产生LSSB信号
'x=udsb(1:length(t));',...
'signal_power=((norm(x)^2)/length(x))/2;',...   %计算信号的功率
'noise_power=signal_power/snr_lin; ',... %计算噪声功率
'noise_std=sqrt(noise_power);',...      %计算噪声标准偏差
'noise=noise_std*randn(1,length(u));',...    %产生噪声向量
'r=u+noise; ',...    %给调制信号加入噪声
'[R,r,df1]=fftseq(r,ts,df);',...  %信号加噪声的频谱
'R=R/fs;',...   %缩放
'axes(h19);',...%1
 'plot(t,m(1:length(t)));',...
  'axis([0 0.15 -10 10]);',...
 'axes(h24);',...%2
   'plot(t,c(1:length(t)));',...
   'axis([0 0.15 -3 3]);',...
'axes(h29);',...%3
   'plot([0:ts:ts*(length(u)-1)/8],u(1:length(u)/8));',...
   'axes(h34);',...%4
     'plot(f,abs(fftshift(M)));',...
      'axes(h431);',...%5
     'plot(f,abs(fftshift(ULSSB)));',...
     'elseif (a==4)&(rv1==1),',...                     %am解调
      'set(h39,''string'',''The message signal'');',...
      'set(h40,''string'',''The modulated signal'');',...
      'set(h41,''string'',''Envelope of the modulated signal'');',...
      'set(h42,''string'',''The demodulated signal '');',...
      'set(h481,''string'',''The demodulated signal in the presence of noise'');',...
        'set(h431,''Position'',[3 3 93 8.15384615384616]);',...
        'set(h34,''Position'',[3 13 93 6.76923076923077]);',...
         'set(h432,''visible'',''off'');',...
         'set(h433,''visible'',''off'');',...
         'set(h42,''visible'',''on'');',...
          'set(h481,''visible'',''on'');',...
           'set(h521,''visible'',''off'');',...
          'set(h522,''visible'',''off'');',...
          'set(h523,''visible'',''off'');',...
          'set(h524,''visible'',''off'');',...
    ' t0=.15;  ',...                             % signal duration
'ts=0.001; ',...                            % sampling interval
'fc=get(h17,''value'');',...                % carrier frequency
'a=(1/5)*get(h15,''Value'');',...                              % Modulation index
'fs=get(h16,''value'');',...%调制信号频率
't=[0:ts:t0];',...                          % time vector
'df=0.25; ',...                             % required frequency resolution
'm=[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];',...
'c=cos(2*pi*fc.*t);',...                    % carrier signal
'm_n=m/max(abs(m)); ',...                   % normalized message signal
'[M,m,df1]=fftseq(m,ts,df);',...            % Fourier transform
'f=[0:df1:df1*(length(m)-1)]-fs/2; ',...    % frequency vector
'u=(1+a*m_n).*c;',...                       % modulated signal
'[U,u,df1]=fftseq(u,ts,df);',...            % Fourier transform
'env=env_phas(u); ',...                     % find the envelope
'dem1=2*(env-1)/a; ',...                    % remove dc and rescale
'signal_power=spower(u(1:length(t)));',...   % power in modulated signal
'noise_power=signal_power/100;',...         % noise power
'noise_std=sqrt(noise_power);',...          % noise standard deviation
'noise=noise_std*randn(1,length(u));',...   % generate noise
'r=u+noise;' ,...                           % add noise to the modulated signal
'[R,r,df1]=fftseq(r,ts,df);',...            % Fourier transform
'env_r=env_phas(r); ',...                   % envelope, when noise is present
'dem2=2*(env_r-1)/a;',...
'axes(h19);',...%1
' plot(t,m(1:length(t)));',...
'axis([0 0.15 -2.1 2.1]);',...
 'axes(h24);',...%2
   'plot(t,u(1:length(t)));',...
'axis([0 0.15 -2.1 2.1]);',...
'axes(h29);',...%3
   'plot(t,env(1:length(t)));',...
   'axes(h34);',...%4
   ' plot(t,dem1(1:length(t)));',...
      'axes(h431);',...%5
    'plot(t,dem2(1:length(t)));',...
    'elseif (a==5)&(rv1==1),',...                      %dsb解调
      'set(h39,''string'',''Spectrum of the the Message Signal'');',...
      'set(h40,''string'',''Spectrum of the Modulated Signal'');',...
      'set(h41,''string'',''Spectrum of the Mixer Output'');',...
      'set(h42,''string'',''Lowpass Filter Characteristics '');',...
      'set(h481,''string'',''Spectrum of the Demodulator output'');',...
      'set(h431,''Position'',[3 3 45 8.15384615384616]);',...
       'set(h34,''Position'',[3 13 45 6.76923076923077]);',...
        'set(h432,''visible'',''on'');',...%坐标轴
         'set(h433,''visible'',''on'');',...%坐标轴
          'set(h42,''visible'',''off'');',...
           'set(h481,''visible'',''off'');',...
           'set(h521,''visible'',''on'');',...
          'set(h522,''visible'',''on'');',...
          'set(h523,''visible'',''on'');',...
          'set(h524,''visible'',''on'');',...
      't0=.15; ',...                              % signal duration
'ts=1/1500; ',...                           % sampling interval
'fc=get(h17,''value'');',...                % carrier frequency
'fs=get(h16,''value'');',...%调制信号频率
't=[0:ts:t0];',...                          % time vector
'df=0.3;  ',...                             % desired frequency resolution
'm=[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];',...
'c=cos(2*pi*fc.*t);',...                    % carrier signal
'u=m.*c;',...                               % modulated signal
'y=u.*c;',...                        % mixing
'[M,m,df1]=fftseq(m,ts,df);',...            % Fourier transform
'M=M/fs;',...                               % scaling
'[U,u,df1]=fftseq(u,ts,df);',...            % Fourier transform
'U=U/fs; ',...                              % scaling
'[Y,y,df1]=fftseq(y,ts,df);',...            % Fourier transform
'Y=Y/fs; ',...                              % scaling
'f_cutoff=150;',...                         % cutoff freq. of the filter
'n_cutoff=floor(150/df1);',...              % design the filter
'f=[0:df1:df1*(length(y)-1)]-fs/2;',...
'H=zeros(size(f));',...                   
'H(1:n_cutoff)=2*ones(1,n_cutoff);',...   
'H(length(f)-n_cutoff+1:length(f))=2*ones(1,n_cutoff);',...
'DEM=H.*Y;',...         % spectrum of the filter output
'dem=real(ifft(DEM))*fs;',...        % filter output
'axes(h19);',...%1
'plot(f,fftshift(abs(M)));',...
 'axes(h24);',...%2
   'plot(f,fftshift(abs(U)));',...
'axes(h29);',...%3
   'plot(f,fftshift(abs(Y)));',...
   'axes(h34);',...%4
   ' plot(f,fftshift(abs(H)));',...
      'axes(h431);',...%5
    'plot(f,fftshift(abs(DEM)));',...
     'axes(h432);',...%6
    'plot(t,m(1:length(t)));',...
    'axis([0 0.15 -2.1 2.1]);',...
     'axes(h433);',...%7
    'plot(t,dem(1:length(t)));',...
    'elseif (a==6)&(rv1==1),',...   %lssb解调
    'set(h39,''string'',''Spectrum of the the Message Signal'');',...
      'set(h40,''string'',''Spectrum of the Modulated Signal'');',...
      'set(h41,''string'',''Spectrum of the Mixer Output'');',...
      'set(h42,''string'',''Lowpass Filter Characteristics '');',...
      'set(h481,''string'',''Spectrum of the Demodulator output'');',...
      'set(h431,''Position'',[3 3 45 8.15384615384616]);',...
       'set(h34,''Position'',[3 13 45 6.76923076923077]);',...
        'set(h42,''visible'',''off'');',...
         'set(h481,''visible'',''off'');',...
        'set(h432,''visible'',''on'');',...
         'set(h433,''visible'',''on'');',...
          'set(h521,''visible'',''on'');',...
          'set(h522,''visible'',''on'');',...
          'set(h523,''visible'',''on'');',...
          'set(h524,''visible'',''on'');',...
    't0=.15;  ',...                             % signal duration
'ts=1/1500; ',...                           % sampling interval
'fc=get(h17,''value'');',...                % carrier frequency
'fs=get(h16,''value'');',...%调制信号频率
'df=0.25;',...                              % desired freq.resolution
't=[0:ts:t0];',...                          % time vectorr
'm=[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];',...
'c=cos(2*pi*fc.*t);',...                    % carrier vector
'udsb=m.*c; ',...                           % DSB modulated signal
'[UDSB,udsb,df1]=fftseq(udsb,ts,df); ',...  % Fourier transform
'UDSB=UDSB/fs;',...                         % scaling
'n2=ceil(fc/df1);',...                      % location of carrier in freq. vector
'UDSB(n2:length(UDSB)-n2)=zeros(size(UDSB(n2:length(UDSB)-n2)));',...
'ULSSB=UDSB;',...                           % generate LSSB-AM spectrum
'[M,m,df1]=fftseq(m,ts,df);',...            % spectrum of the message signal
'M=M/fs; ',...                              % scaling
'f=[0:df1:df1*(length(M)-1)]-fs/2;',...     % frequency vector
'u=real(ifft(ULSSB))*fs;',...               % generate LSSB signal from spectrum
'y=u.*cos(2*pi*fc*[0:ts:ts*(length(u)-1)]);',... 
'[Y,y,df1]=fftseq(y,ts,df);',...            % spectrum of the output of the mixer
'Y=Y/fs;  ',...                             % scaling
'f_cutoff=150;',...                         % choose the cutoff freq. of the filter
'n_cutoff=floor(150/df);',...               % design the filter
'H=zeros(size(f));',...                   
'H(1:n_cutoff)=4*ones(1,n_cutoff); ',...  
'H(length(f)-n_cutoff+1:length(f))=4*ones(1,n_cutoff);',...
'DEM=H.*Y;',...         % spectrum of the filter output
'dem=real(ifft(DEM))*fs; ',...              % filter output
'axes(h19);',...%1
'plot(f,fftshift(abs(M)));',...
 'axes(h24);',...%2
   'plot(f,fftshift(abs(ULSSB)));',...
'axes(h29);',...%3
   'plot(f,fftshift(abs(Y)));',...
   'axes(h34);',...%4
   ' plot(f,fftshift(abs(H)));',...
      'axes(h431);',...%5
    'plot(f,fftshift(abs(DEM)));',...
     'axes(h432);',...%6
    'plot(t,m(1:length(t)));',...
      'axis([0 0.15 -2.1 2.1]);',...
     'axes(h433);',...%7
    'plot(t,dem(1:length(t)));',...
         'end']);

原创粉丝点击