
%The example below compares DSBSC and SSBSC amplitude modulation.
% Sample the signal 100 times per second, for 2 seconds. 
% By P Malindi

Fs = 100;           % Sampling Frequency           
t = [0:2*Fs+1]'/Fs; % Setting time axis
Fc = 20;            % Carrier frequency
fm = 10;
x1 = sin(2*pi*fm*t);   % Sinusoidal signal
x2 = cos(2*pi*fm*t);     %shifting modulating signal by 90 degrees

% Modulate x using single- and double-sideband AM.
ydouble1 = ammod(x1,Fc,Fs);
ydouble2 = ammod(x2,Fc,Fs,pi/2);
ysingle = ydouble1 + ydouble2;
ydouble = ydouble1;

% Compute spectra of both modulated signals.
zdouble = fft(ydouble);
zdouble = abs(zdouble(1:length(zdouble)/2+1));
frqdouble = [0:length(zdouble)-1]*Fs/length(zdouble)/2;
zsingle = fft(ysingle);
zsingle = abs(zsingle(1:length(zsingle)/2+1));
frqsingle = [0:length(zsingle)-1]*Fs/length(zsingle)/2;

% Plot spectra of both modulated signals.
figure;
subplot(2,1,1); plot(frqdouble,zdouble); xlabel('Frequency in Hz')
title('Spectrum of double-sideband suppressed carrier signal');
subplot(2,1,2); plot(frqsingle,zsingle); xlabel('Frequency in Hz')
title('Spectrum of single-sideband suppressed carrier signal (LSB)');