In: Electrical Engineering
I need a matlab code for my presentation. Code should include Single Sideband Amplitude Modulation and Demodulation. It should figure 3 things:
-time domain of given message signal in Amplitude Modulation and Single Sideband Amplitude Modulation
-frequency domain of given signal in Amplitude Modulation and Single Sideband Amplitude Modulation
-And it should demodulate and show message signal.
Matlab code:
fs=10000;%sampling frequency
Ts=1/fs;%sampling period
N=1000;%number of samples
t=[0:Ts:N*Ts-Ts];%time axis
f=[-fs/2:fs/N:fs/2-fs/N];%frequency axis
fc=2000;%carrier frequency
fm=300;%modulation frequency
A=5;
m=0.5;%modulation index
Sc=A*cos(2*pi*fc*t);
Sm=A*sin(2*pi*fm*t);
%Amplitude modulation
St=(A+m*Sm).*sin(2*pi*fc*t);
Yt=fft(St);%modulated signal DFT
figure(1)
subplot(3,1,1);plot(t,Sm);
subplot(3,1,2);plot(t,Sc);
subplot(3,1,3);plot(t,St);title('AM Signal');xlabel('Time
axis');ylabel('Amplitude');
figure(2)
stem(f,fftshift(abs(Yt))) ;title('AM Signal
Spectrum');xlabel('Frequency axis');ylabel('Amplitude');
%%%%%%% ssb modulation%%%%%%%%%%%%%%%%
fm1 = 200;
fm2 = 100;
Em1 = 2;
Em2 = 2;
m = Em1*cos(2*pi*fm1*t)+Em2*cos(2*pi*fm2*t); %Message
mh = imag(hilbert(m)); %Hilbert transform of the message signal
sbu = m.*2.*cos(2*pi*fc*t) - mh.*2.*sin(2*pi*fc*t); %Expression
for USB SSB
sbl = m.*2.*cos(2*pi*fc*t) + mh.*2.*sin(2*pi*fc*t); %Expression for
LSB SSB
SBU = 2/N*abs(fft(sbu));
SBL = 2/N*abs(fft(sbl));
freq = fs * (0 : N/2) / N;
display('Single SideBand Modulation');
sprintf('Carrier frequency: %d Hz',fc)
sprintf('Message frequency: %d Hz and %d Hz',fm1,fm2)
sprintf('USB spectra at: %d Hz and %d Hz',fc+fm1,fc+fm2)
sprintf('LSB spectra at: %d Hz and %d Hz',fc-fm1,fc-fm2)
figure(3)
subplot(211);
plot(10*t(1:200),sbu(1:200),'b'); %Time Domain Plot
title('SSB Time Domain Representation');
xlabel('Time'); ylabel('Modulated Signal');
subplot(212);
plot(freq,SBU(1:N/2+1),freq,SBL(1:N/2+1)); %Frequency domain
plot
title('SSB Frequency Domain Representation');
xlabel('Frequency(Hz)'); ylabel('Spectral Magnitude');
legend('USB','LSB');
%
% %%% Demodulation %%%%
% figure()
% z1=ssbdemod(sbu,fc,fs);
% z2=ssbdemod(sbl,fc,fs);
% plot(t,z1,'k',t,z2,'g-.',t,Sm,'r');
%
% figure()
% z3=amdemod(St,fc,fs);
% plot(t,z3);
xc=Sc;
xm=Sm;
figure(4)
subplot(2,1,1),plot(t,xc);
title('carrier signal ');
xlabel('time (sec)');
ylabel('amplitude');
subplot(2,1,2),plot(t,xm);
title('message signal ');
xlabel('time (sec)');
ylabel('amplitude');
% DSB--SC MODULATION
z= xm.*xc;
figure(5)
subplot(2,1,1),plot(t,z);
title('DSB-SC MODULATION IN TIME DAOMAIN');
xlabel('time (sec)');
ylabel('amplitude');
l1=length(z);
f=linspace(-fs/2,fs/2,l1);
Z=fftshift(fft(z,l1)/l1);
subplot(2,1,2),plot(f,abs(Z));
title('DSB SC MODULATION IN FREQUENCY DOMAIN');
xlabel('frequency(hz)');
ylabel('amplitude');
% demodulation
s=z.*xc;
S=fftshift(fft(s,length(s))/length(s));
figure(6)
plot(f,abs(S));
title(' demodulated signal IN FREQUENCY DOMAIN before
filtring');
xlabel('frequency(hz)');
ylabel('amplitude');
hold on
rlp=1./sqrt(1+(f./fc).^(2*100));
plot(f,rlp,'g');
title(' frequency response of low pass filter');
xlabel('frequency(hz)');
ylabel('amplitude');
E=rlp.*S;
figure(7)
subplot(2,1,1),plot(f,E);
title(' Recover signal IN FREQUENCY DOMAIN after filtring');
xlabel('frequency(hz)');
ylabel('amplitude');
e=ifft(ifftshift(E))*length(E);
subplot(2,1,2),plot(t,(1/0.5)*e);
title(' Recover signal IN Time DOMAIN after filtring');
xlabel('time(sec)');
ylabel('amplitude');