📄 modsig.m
字号:
function [xm,xf,xp]=modsig(ty,x,c,k)
% MODSIG Generate AM, FM and PM signals.
%
% [XM,XP,XF] = MODSIG(TY,X,C,K) returns the modulated signal in XM
% FOR 'pm' and 'fm' ONLY: XP = phase, XF = instantaneous frequency
% TY is 'am', 'fm', or 'pm', X is an array of the message signal
% C is [F,TS]= [carrier frequency, sampling interval] [Default: TS=1],
% K is beta (for AM) or kp(rad/unit) (for PM) or kf(Hz/unit) (for FM).
%
% Note: For 'am' if K is not given, XM is a DSBSC AM signal
%
% For DSBSC AM: xm = x.*cos(2*pi*f*t)
% For Standard AM: xm = (1+k*x).*cos(2*pi*f*t)
% For PM: xm = cos(2*pi*f*t+k*x)
% For FM: xm = cos(2*pi*f*t+2*pi*k*cumsum(x)*ts)
% RESULTS ARE PLOTTED IF NO OUTPUT ARGUMENTS GIVEN
%
% MODSIG (with no input arguments) invokes the following example:
%
% % An FM signal using a triangular message, F=2Hz, TS=0.01, kf=10
% >>t = 0:.01:2;
% >>y = tri(t-1);
% >>modsig('fm',y,[2 0.01],10);
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin==0,help modsig,disp('Strike a key to see results of the example')
pause,t=0:.01:2;y=tri(t-1);modsig('fm',y,[2 0.01],10);return,end
ty1=ty(1);f=c(1);if length(c)==2,ts=c(2);else,ts=1;end
l=length(x);t=(0:l-1)*ts;if nargin>3,kk=num2str(k);else,kk='';end
if ty1=='a',
ty=[ty ' signal '];if nargin<4,ty=['DSBSC ' ty];xm=x.*cos(2*pi*f*t);
else,ty=['Standard ' ty ' beta= ' kk];xm=(1+k*x).*cos(2*pi*f*t);end
elseif ty1=='p',
xp=2*pi*f*t+k*x;xm=cos(xp);xf=[f+diff(x)/2/pi/ts];xf(l)=xf(l-1);
elseif ty1=='f',
xf=f+k*x;xp=2*pi*f*t+2*pi*k*cumsum(x)*ts;xm=cos(xp);
else,error('Unidentified modulation type. Use am pm or fm'),return,end
if nargout>0,return,end
vx=matverch;
if vx < 4, eval('clg');else,eval('clf');end
if ty1=='a'
subplot(211),plot(t,x),title('Message signal')
subplot(212),plot(t,xm),title(ty)
else
subplot(221),plot(t,x),title('Message signal')
subplot(222),plot(t,xp),title([ty ' phase'])
subplot(223),plot(t,xf),title([ty ' instantaneous frequency'])
subplot(224),plot(t,xm),title([ty ' signal k = ' kk])
end,pause,subplot,hold off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -