2ASK (binary amplitude shift keying) also known as Ook
function Askdigital (s,f)% implementation of the ask modulation% s--input binary sequence; the frequency of the f--carrier, i.e.: a code element period including F carrier period% Call Example: Askdigital ([1 0 1 1 0], 2) t=0:2*pi/99:2* Pi; % initialization definition, 1*100 matrix cp=[];mod=[];bit=[];for n=1:length (s); % modulation process if s (n) ==0; Bit1=zeros (1,100); % 100 is the code element period else % s (n) ==1; Bit1=ones (1,100); End C=sin (f*t); Mod=[mod c]; Bit=[bit Bit1];endask=bit.*mod;subplot (2,1,1);p lot (bit, ' k ', ' linewidth ', 1); Ylabel (' Binary Signal '), axis ([0 100*length (s) -2.5 2.5]), subplot (2,1,2);p lot (ask, ' k ', ' linewidth ', 1); Grid On;ylabel ( ' ASK modulation '); axis ([0 100*length (s)-2.5 2.5]);
2FSK: ' 1 ' corresponds to the carrier frequency of $\omega_1$, ' 0 ' corresponds to the carrier frequency of $\omega_2$.
function Fskdigital (S,F0,F1)% implementation FSK modulation% s--input binary sequence f0,f1--two different frequency carrier% call Example (F0 F1 must be an integer): fskdigital ([1 0 1 1 0], (T=0:2*PI/99:2*PI); % Initialization Definition Cp=[];mod=[];bit=[];for n=1:length (s); % modulation process if s (n) ==0; Cp1=ones (1,100); C=sin (f0*t); Bit1=zeros (1,100); else%s (n) ==1; Cp1=ones (1,100); C=sin (f1*t); Bit1=ones (1,100); End CP=[CP CP1]; Mod=[mod c]; Bit=[bit bit1];endfsk=cp.*mod;% FSK = Mod;subplot (2,1,1); Plot (bit, ' k ', ' linewidth ', 1), Grid On;ylabel (' Binary Signal '), axis ([0 100*length (s) -2.5 2.5]), subplot (2,1,2);p lot ( FSK, ' K ', ' linewidth ', 1), Grid On;ylabel (' FSK modulation '), axis ([0 100*length (s)-2.5 2.5]);
Or a function provided with Matlab fskmod
y= Fskmod (X,m,freq_sep,nsamp);
Y=fskmod (X,M,FREQ_SEP,NSAMP,FS);
X: Message Signal
M: Indicates the number of symbols for the message, must be an integer power of 2, M-input signal (0~M-1)
FREQ_SEP: Frequency interval between two carriers, unit Hz
Nsamp: The number of samples for the output signal must be a positive integer greater than 1
FS: According to the Nyquist sampling theorem, (M-1) *freq_seq <= Fs
m=2;freqsep=8;nsamp=8; Fs=32;x=randi ([0,m-1],1000,1); Y=fskmod (x,m,freqsep,nsamp,fs); ly = length (y);% draw 2FSK signal Spectrum freq=-fs/2:fs/ly:fs/2-fs/ Ly SYY = Fftshift (ABS (FFT (y)));p lot (FREQ,SYY)
Digital modulation (ASK, FSK)