www.pudn.com > fskdet.rar > fskdet.m


function[xn, x] = fskdet(y, fs, fb, fc1, fc2); 
% 
% Usage: FSK解调(相干解调方式) 
% chc 05-3-19(Example from book p291) 
% ----------------------------------------------------% 
% y: FSK wave;                                        % 
% (fs:sampling fre; fb:bit rate; fc:carrier fre)      % 
% x: 解调输出码流; xn: 解调输出脉冲信号波形          % 
%-----------------------------------------------------% 
if nargin<5; fc2 = 2.5;     end; 
if nargin<4; fc1 = 2.0;      end; 
if nargin<3; fb = 1;        end; 
if nargin<2; fs = 32;       end; 
if nargin<1;  
    y=fsk(str2cod('CHC')); end; 
% ------------------------------------- % 
dt=1/fs; n=length(y); t=(0: n-1)*dt; 
[b, a]=butter(4, 2*fb/fs);   
[b1, a1]=cheby1(3, .5, 2*fc1/fs, 'high');  
y1 =filtfilt(b1, a1, y).*sin(2*pi*fc1*t);  
y1 =filtfilt(b, a, y1);  
[b2, a2]=cheby1(3, .5, 2.5*fc1/fs, 'high');  
y2 =filtfilt(b2, a2, y).*sin(2*pi*fc2*t);  
y2 =filtfilt(b, a, y2);  
% ---------------判决--------------- % 
m=fs/fb; N=n/m; n=(.75:1:N)*m;         % N--码元数;m--每个码元的采样点数 
x =y1-y2; xn=(sign(x(n))+1)/2;        
 
%---------------------figure---------------------------% 
if nargout<1; 
    
% ---------Input FSK------------------- %     
    subplot(211); plot(t, y); title('Input');     
% ---------解调后脉冲波形------------------- %       
    subplot(212); plot(t, x, t, sign(x)*.3 );  
     
    c='bbbbbbbbrrrrrrrr'; 
    set(gca,'ygrid', 'on'); v=axis; 
    for i=1:N;                                    % 码符号(1/0) 
        ci=rem(i,16); ci=ci+(ci==0)*16; ci=c(ci); 
        text((2*i-1)*m*dt/2, v(4)*.8, int2str(xn(i)),... 
             'color',ci, 'hor', 'center'); 
     end; 
     title('Output'); 
      
     set (gcf, 'num', 'off', 'name', ['Coherent Dectection of FSK'... 
          blanks(10)]); 
end; 
zoom xon;