Telekomödev
Telekomödev
Telekomödev
1
% (triplesinc.m)
% Baseband signal for AM
% Usage m = triplesinc(t, Ta)
function m = triplesinc(t, Ta)
% t is the length of the signal
% Ta is the parameter, equaling twice the delay
sig_1 = sinc(2 * t / Ta);
sig_2 = sinc(2 * t / Ta - 1);
sig_3 = sinc(2 * t / Ta + 1);
m = 2 * sig_1 + sig_2 + sig_3;
end
% (Main Script)
ts = 1.e-4; % Time step
t = -0.04:ts:0.04; % Time vector
Ta = 0.01; % Delay parameter
m_sig = triplesinc(t, Ta); % Generate the message signal
% Modulation
s_dsb = m_sig .* cos(2 * pi * 500 * t); % DSB-SC modulated signal
figure(1);
% Parameters
ts = 1.e-4;
t = -0.04:ts:0.04;
Ta = 0.01; % Delay parameter
fc = 300; % Carrier frequency
subplot(221);
plot(t, m_sig, 'LineWidth', 1.5);
axis(Trange);
xlabel('{\it t} (sec)');
ylabel('{\it m}({\it t})');
title('Message Signal');
subplot(222);
plot(t, s_dsb, 'LineWidth', 1.5);
axis(Trange);
xlabel('{\it t} (sec)');
ylabel('{\it s}_{\rm DSB}({\it t})');
title('DSB-SC Modulated Signal');
subplot(223);
plot(t, s_dem, 'LineWidth', 1.5);
axis(Trange);
xlabel('{\it t} (sec)');
ylabel('{\it e}({\it t})');
title('Demodulated Signal');
subplot(224);
plot(t, s_rec, 'LineWidth', 1.5);
axis(Trange);
xlabel('{\it t} (sec)');
ylabel('{\it m}_d({\it t})');
title('Recovered Signal');
% Parameters
ts = 1.e-4; % Time step
t = -0.04:ts:0.04; % Time vector
Ta = 0.01; % Delay parameter
fc = 300; % Carrier frequency
subplot(221);
plot(freqm, abs(M_fre), 'LineWidth', 1.5);
axis(Frange);
xlabel('{\it f} (Hz)');
ylabel('{\it M}({\it f})');
title('Message Spectrum');
subplot(222);
plot(freqs, abs(S_dsb), 'LineWidth', 1.5);
axis(Frange);
xlabel('{\it f} (Hz)');
ylabel('{\it S}_{rm DSB}({\it f})');
title('DSB-SC Spectrum');
subplot(223);
plot(freqs, abs(S_dem), 'LineWidth', 1.5);
axis(Frange);
xlabel('{\it f} (Hz)');
ylabel('{\it E}({\it f})');
title('Spectrum of {\it e}({\it t})');
subplot(224);
plot(freqs, abs(S_rec), 'LineWidth', 1.5);
axis(Frange);
xlabel('{\it f} (Hz)');
ylabel('{\it M}_d({\it f})');
title('Recovered Spectrum');
4.12.2
% ExampleAMdemfilt.m
% This program illustrates AM modulation and demodulation using a triangular
message signal
% Clear workspace
clear all; close all; clc;
% Parameters
ts = 1.e-4; % Sampling interval
t = -0.04:ts:0.04; % Time vector
Ta = 0.01; % Message signal period
fc = 500; % Carrier frequency
function y = triangl(t)
% Generates a triangular waveform
% t is the input time vector, y is the output triangular waveform
y = (1 - abs(t)) .* (abs(t) <= 1); % Generates a triangle wave between -1 and
1
end
% Message signal (triangular waveform using triangl.m function)
m_sig = triangl((t + 0.01) / 0.01) - triangl((t - 0.01) / 0.01);
Lm_sig = length(m_sig);
Lfft = length(t);
Lfft = 2^ceil(log2(Lfft)); % FFT length as a power of 2
M_fre = fftshift(fft(m_sig, Lfft)); % FFT of message signal
freqm = (-Lfft/2:Lfft/2-1) / (Lfft * ts); % Frequency vector for message signal
figure(2)
ts = 1.e-4;
t = -0.04:ts:0.04;
Ta = 0.01;
fc = 300;
Lm_sig = length(m_sig);
Lfft = length(t);
Lfft = 2^ceil(log2(Lfft));
M_fre = fftshift(fft(m_sig, Lfft));
freqm = (-Lfft/2:Lfft/2-1)/(Lfft*ts);
B_m = 150; % Bandwidth of the signal is B_m Hz.
h = fir1(40, [B_m * ts]);
% DSB modulation
s_dsb = m_sig .* cos(2 * pi * fc * t);
Lfft = length(t);
Lfft = 2^ceil(log2(Lfft) + 1);
S_dsb = fftshift(fft(s_dsb, Lfft));
L_lsb = floor(fc * ts * Lfft);
SSBfilt = ones(1, Lfft);
SSBfilt(Lfft/2 - L_lsb + 1:Lfft/2 + L_lsb) = zeros(1, 2 * L_lsb);
S_ssb = S_dsb .* SSBfilt;
freqs = (-Lfft/2:Lfft/2-1)/(Lfft*ts);
s_ssb = real(ifft(fftshift(S_ssb)));
s_ssb = s_ssb(1:Lm_sig);
% Demodulation
s_dem = s_ssb .* cos(2 * pi * fc * t) * 2;
S_dem = fftshift(fft(s_dem, Lfft));
4.12.4
function y = triangl(t)
% Triangular function
y = max(1 - abs(t), 0);
end
function y = triplesinc(t, Ta)
% Triple sinc function
y = sinc(t/Ta) .* sinc(t/Ta) .* sinc(t/Ta);
end
% (ExampleQAMdemfilt.m)
% This program uses triangl.m and triplesinc.m
% to illustrate QAM modulation and demodulation
% of two message signals
clear; clf;
ts = 1.e-4; % Sampling interval
t = -0.04:ts:0.04; % Time vector
Ta = 0.01; % Message signal period
fc = 300; % Carrier frequency
Lm_sig = length(m_sig1);
Lfft = length(t); Lfft = 2^ceil(log2(Lfft));
subplot(222);
td2 = plot(t, s_qam);
axis(Trange); set(td2, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it s}_{\rm DSB}({\it t})');
title('QAM modulated signal');
subplot(223);
td3 = plot(t, s_dem1);
axis(Trange2); set(td3, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it x}({\it t})');
title('First demodulator output');
subplot(224);
td4 = plot(t, s_rec1);
axis(Trange); set(td4, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m}_{d1}({\it t})');
title('Detected signal 1');
subplot(222);
td6 = plot(t, s_qam);
axis(Trange); set(td6, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it s}_{\rm DSB}({\it t})');
title('QAM modulated signal');
subplot(223);
td7 = plot(t, s_dem2);
axis(Trange2); set(td7, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it e}_1({\it t})');
title('Second demodulator output');
subplot(224);
td8 = plot(t, s_rec2);
axis(Trange); set(td8, 'LineWidth', 1.5);
xlabel('{\it t} (sec)'); ylabel('{\it m}_{d2}({\it t})');
title('Detected signal 2');
subplot(222);
fd2 = plot(freqs, abs(S_qam));
axis(Frange); set(fd2, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it S}_{rm AM}({\it f})');
title('QAM spectrum magnitude');
subplot(223);
fd3 = plot(freqs, abs(S_dem1));
axis(Frange); set(fd3, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it E}_1({\it f})');
title('First demodulator spectrum');
subplot(224);
fd4 = plot(freqs, abs(S_rec1));
axis(Frange); set(fd4, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it M}_{d1}({\it f})');
title('Recovered spectrum 1');
figure(4)
subplot(221);
fd1 = plot(freqm, abs(M2_fre));
axis(Frange); set(fd1, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it M}({\it f})');
title('Message 2 spectrum');
subplot(222);
fd2 = plot(freqs, abs(S_qam));
axis(Frange); set(fd2, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it S}_{rm AM}({\it f})');
title('QAM spectrum magnitude');
subplot(223);
fd7 = plot(freqs, abs(S_dem2));
axis(Frange); set(fd7, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it E}_2({\it f})');
title('Second demodulator spectrum');
subplot(224);
fd8 = plot(freqs, abs(S_rec2));
axis(Frange); set(fd8, 'LineWidth', 1.5);
xlabel('{\it f} (Hz)'); ylabel('{\it M}_{d2}({\it f})');
title('Recovered spectrum 2');