Pcs 2
Pcs 2
2) DSBSC
fs = 100000; % Higher sampling frequency for better resolution
t = 0:1/fs:0.05; % Shorter time window to see detail
fm = 100; % Message frequency (Hz)
fc = 2000; % Carrier frequency (Hz)
Am = 1; % Message amplitude
Ac = 1; % Carrier amplitude
% Message Signal
m = Am * sin(2*pi*fm*t);
% Carrier Signal
c = Ac * cos(2*pi*fc*t);
% DSB-SC Modulation
dsbsc = m .* c;
% Coherent Demodulation
demod = dsbsc .* c;
% Plotting
figure;
subplot(4,1,1);
plot(t, m);
title('Original Message Signal');
xlabel('Time (s)'); ylabel('Amplitude');
subplot(4,1,2);
plot(t, dsbsc);
title('DSB-SC Modulated Signal');
xlabel('Time (s)'); ylabel('Amplitude');
subplot(4,1,3);
plot(t, demod);
title('Demodulated Signal (Before LPF)');
xlabel('Time (s)'); ylabel('Amplitude');
subplot(4,1,4);
plot(t, recovered);
title('Recovered Signal (After LPF, Amplitude Normalized)');
xlabel('Time (s)'); ylabel('Amplitude');
2)SSB
% Parameters
fs = 100000; % High sampling frequency
t = 0:1/fs:0.05; % Short time window for clarity
fm = 100; % Message frequency (Hz)
fc = 2000; % Carrier frequency (Hz)
Am = 1; % Message amplitude
Ac = 1; % Carrier amplitude
% Message Signal
m = Am * sin(2*pi*fm*t);
% Coherent Demodulation
carrier = cos(2*pi*fc*t); % Coherent carrier
demod = ssb .* 2 .* carrier; % Multiply by 2*cos(2*pi*fc*t)
% Low-pass filter
cutoff = 2 * fm / fs; % Normalized cutoff frequency
[b, a] = butter(6, cutoff); % 6th-order Butterworth filter
recovered = filter(b, a, demod);
% Normalize recovered signal to match amplitude
recovered = recovered * (Am / max(abs(recovered)));
% Plotting
figure;
subplot(4,1,1);
plot(t, m, 'b');
title('Original Message Signal');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
subplot(4,1,2);
plot(t, ssb, 'r');
title('SSB Modulated Signal (Upper Sideband)');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
subplot(4,1,3);
plot(t, demod, 'g');
title('Demodulated Signal (Before LPF)');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
subplot(4,1,4);
plot(t, recovered, 'k');
title('Recovered Signal (After LPF, Amplitude Normalized)');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
3)VSB
% VSB Modulation and Demodulation Example
subplot(4,1,1);
plot(t, m, 'b');
title('Original Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4,1,2);
plot(t, dsb_sc, 'k');
title('DSB-SC Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4,1,3);
plot(t, vsb_signal, 'r');
title('VSB Modulated Signal (Filtered DSB-SC)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4,1,4);
plot(t, recovered, 'g');
title('Recovered Message Signal (After Demodulation & LPF)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
4)FM
% Narrowband FM Spectrum
narrow_fm_fft = abs(fft(narrow_fm_signal));
% Wideband FM Spectrum
wide_fm_fft = abs(fft(wide_fm_signal));
% Plotting the spectra
figure;
subplot(2,1,1);
title('Narrowband FM Spectrum');
xlim([0 Fs/2]);
subplot(2,1,2);
title('Wideband FM Spectrum');
xlim([0 Fs/2]);
5) PM
% PM with Demodulation in MATLAB
% Parameters
Fs = 10000; % Sampling frequency (Hz)
t = 0:1/Fs:0.1; % Time vector (0 to 0.1s)
fc = 1000; % Carrier frequency (Hz)
kf = pi; % Phase sensitivity
% Phase Modulation
pm = cos(2*pi*fc*t + kf * m); % PM signal
% Plot results
figure;
6) ADC
clc; clear;
% Signal and Sampling
fs = 1000; % Sampling frequency
t = 0:1/fs:0.02; % Time vector
x = 2 * sin(2*pi*50*t); % Original analog signal
% Quantization setup
n_bits = 3; % Number of bits
L = 2^n_bits; % Levels
xmax = max(abs(x)); % Max amplitude
delta = 2 * xmax / L; % Step size
% ---- Normalize the Demodulated Signal to Match the Original Signal ----
demod_midtread = (demod_midtread / max(abs(demod_midtread))) * max(abs(x)); %
Normalize to original amplitude
demod_midrise = (demod_midrise / max(abs(demod_midrise))) * max(abs(x)); %
Normalize to original amplitude
7) line code
clc; clear;
bit_duration = 1;
t = 0:1/fs:bit_duration - 1/fs;
total_time = [];
for i = 1:length(data)
end
% Initialize signals
unipolar_nrz = [];
bipolar_nrz = [];
bipolar_rz = [];
manchester = [];
on_off = [];
last_polarity = -1;
for i = 1:length(data)
bit = data(i);
% Unipolar NRZ
% Bipolar NRZ
if bit == 1
last_polarity = -last_polarity;
else
end
% Bipolar RZ
if bit == 1
last_polarity = +last_polarity;
else
end
% Manchester
if bit == 1
else
end
% On-Off Keying
end
subplot(5,1,1);
subplot(5,1,2);
subplot(5,1,3);
subplot(5,1,4);
xlabel('Time');
8) audio signal
clc;
clear;
figure;
subplot(2,1,1);
specgram(audio_device, n_fft, fs, hamming(window_size), overlap);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
subplot(2,1,2);
hold on;
xlabel('Time (s)');
ylabel('Amplitude');
for i = 1:n_frames
% Capture audio frame (here you can replace this with live microphone input)
subplot(2,1,1);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(2,1,2);
end
9)Sinc
% Repeating Sinc Function in MATLAB
% Parameters
T = 5; % Period of repetition
numPeriods = 4; % Number of periods
t_single = linspace(-2.5, 2.5, 250); % Time for one sinc pulse