Skip to content

Instantly share code, notes, and snippets.

@amrrashed
Created February 14, 2018 10:52
Show Gist options
  • Select an option

  • Save amrrashed/5320e6b7f63c2fe65433d0af065a3e89 to your computer and use it in GitHub Desktop.

Select an option

Save amrrashed/5320e6b7f63c2fe65433d0af065a3e89 to your computer and use it in GitHub Desktop.
clc;clear;close
%Fs >2*(Fc + BW), where BW is the bandwidth of the modulating signal, X
fs = 100;
t = (0:1/fs:100)';
%Set the carrier frequency to 10 Hz and input freq to 1 Hz.
fc = 10;
fm=1;
x = sin(2*pi*fm*t);%supressed carrier
%x = sin(2*pi*fm*t)+5;%large carrier
%Create a spectrum analyzer
sa0 = dsp.SpectrumAnalyzer('SampleRate',fs);
step(sa0,x)
%Modulate x using single- and double-sideband AM.
y = ammod(x,fc,fs);%double-sideband
%y1 = ssbmod(x,fc,fs,0);%modulate single-sideband lower side band
%y2 = ssbmod(x,fc,fs,0,'upper');%modulate single-sideband upper side band
%plot modulated signal
figure(1)
plot(t,y)
axis([-0 10 -6 6])
%Plot the spectrum of the double-sideband signal.
%sa = dsp.SpectrumAnalyzer('SampleRate',fs, ...'PlotAsTwoSidedSpectrum',false, ...'YLimits',[-60 40]);
%Create a spectrum analyzer
sa = dsp.SpectrumAnalyzer('SampleRate',fs);
step(sa,y)
%demodulation
[num,den] = butter(10,fc*2/fs);%low pass filter butterworth with cutoff freq=2fc
z = amdemod(y,fc,fs,0,0,num,den);%demodulate double-sideband
%s1 = ssbdemod(y1,Fc,Fs); % Demodulate lower sideband
%s2 = ssbdemod(y2,Fc,Fs); % Demodulate upper sideband
%Plot the original and demodulated signals.
figure(2)
plot(t,x,'c',t,z,'b--')
legend('Original Signal','Demodulated Signal')
xlabel('Time (s)')
ylabel('Amplitude')
%Create a spectrum analyzer.
sa2 = dsp.SpectrumAnalyzer('SampleRate',fs);
step(sa2,z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment