% script for experimenting with FM synthesis % you can comment various lines in and out and change % parameters to play with different effects % Aaron Lanterman, 3/5/08 fs = 44100; tt = 0:(1/fs):0.5; wc = 240*2*pi; wm = 240*2*pi; %wm = linspace(110*2*pi,2200*2*pi,length(tt)); %wc = linspace(2200*2*pi,110*2*pi,length(tt)); %index = linspace(15,0,length(tt)); %index = linspace(0,10,length(tt)); index = 11; % yes, it turns out the phase relationship between the % carrier and the modulator does matter! %theta = linspace(0,2*pi,length(tt)); theta = 0; xx = cos(wc .* tt + index .* sin(wm .* tt + theta)); %xx = cos(wc .* tt + index .* cos(wm .* tt)); %xx = cos(wc .* tt); soundsc(xx,fs); % The FFT will only be clear if you keep the parameters % constant over time % By multiplying by 2, I'm plotting a cosine style spectrum % instead of an complex exponential style spectrum fftxx = 2 * abs(fft(xx)) / length(xx); lenx = length(xx); ff = linspace(0,fs*(lenx-1)/lenx,length(fftxx)); % change the end values of the subsets to plot more or less % of the FFT plot(ff(1:4000),fftxx(1:4000)); % The sampling rate 44.1 kHz is too high to see details in % the spectrogram since all the lines are squished down at % the lower frequestion, so let's downsample the signal % taking the spectrogram % xxres = resample(xx,1,4); % specgram(xxres,1024,fs)