% EE133 Prelab 2 Matlab File
% Will output the frequency spectrum of a FM Signal
% given as [P_mod] = fm (fs,fc,Vc,m)
% NOTE: You do not need to modify this file!

function [P_mod] = get_fm_spect(fs,fc,Vc,m)
smpl_freq = 1e6;
t = [0:(1/smpl_freq):(5/fs)]; % sample points up to 5 cycles
N = length(t);	% total number of sample points

ys = sin(2*pi*fs*t);
y_mod = Vc*cos(2*pi*fc*t + m*ys);
P_mod = abs(fft(y_mod))*2/N;	% normalize result for N length 
								% window
f = [0:(N-1)]/N * smpl_freq;
f1 = round(20e3*N/smpl_freq);
f2 = round(40e3*N/smpl_freq);
plot(f(f1:f2),P_mod(f1:f2));
grid;
title(['FM Waveform, m=', num2str(m)]);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
