This performs Phase Modulation for any data and with slight modification it gives FM also.

PM.m

%This is a program to do Phase Modulation of a signal
% see also DSBAM, SSBAM
clear all
close all
clc
td = input('\nEnter the total Signal Duration\n\n ->');
ts = input('\nEnter the sampling time for this signal and it should be less than 1\n\n ->');
fc = input('\nEnter the carrier frequency\n\n ->');
k = input('\nEnter the Phase modulation constant\n\n ->');
t = 0:ts:td;
t2 = int64( (t/ts) +1 );
wc = 2*pi*fc;
m(t2) = input('\nEnter the msg signal as a function of time "t" \n\n ->');
n = input('\nEnter the SNR of the AWGN for no noise enter inf\n\n ->');
s = cos((2*pi*fc*t)+ k*m(t2));
subplot(2,1,1),plot(t,s);
title('Phase Modulated Signal');
xlabel('Time');
ylabel('Transmitted Signal at the Modulator');
sn = awgn(s,n);
subplot(2,1,2),plot(t,sn);
title('Phase Modulated Signal with AWGN');
xlabel('Time');
ylabel('Received Signal at the Demodulator');