PCS Programs
PCS Programs
Basic Signals and Signal Graphing: a) unit Step, b) Rectangular, c) standard triangle d) sinusoidal and e)
Exponential signal.
n=0:9;
y=ones(1,10);
stem(n,y);
xlabel('Samples');
ylabel('Amplitude');
title('Unit step function');
b) Rectangular signal
c) standard triangle
T = 4; % Period of the triangle signal
A = 1; % Amplitude of the triangle signal
t = 0:0.01:10; % Time range for plotting
y = A * sawtooth(2*pi/T * t, 0.5);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('Triangle Signal');
d) sinusoidal signal
n=0:.01:1;
f=2;
y=sin(2*pi*f*n);
stem(n,y);
xlabel('Samples');
ylabel('Amplitude');
title('Discrete sine wave');
e) Exponential signal
n=0:10;
a=0.5;
y=exp(a*n);
stem(n,y);
xlabel('Samples');
ylabel('Amplitude');
title('exponential sequence');
2. Illustration of signal representation in time and frequency domains for a rectangular pulse.
3. Amplitude Modulation and demodulation: Generation and display the relevant signals and its spectrums.
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1; % Time vector
fc = 50; % Carrier frequency
fm = 5; % Message signal frequency
Ac = 1; % Carrier signal amplitude
Am = 0.5; % Message signal amplitude
subplot(3,1,2);
plot(t, c_t);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, s_t);
title('Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
figure;
subplot(3,1,1);
plot(f, abs(M_f));
title('Message Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(3,1,2);
plot(f, abs(C_f));
title('Carrier Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(3,1,3);
plot(f, abs(S_f));
title('Modulated Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
% Demodulation
% Demodulate using envelope detection
s_env = abs(hilbert(s_t));
demodulated_signal = s_env - Ac;
% Frequency modulation
%s_t = Ac*sin(2*pi*fc*t + 2*pi*kf*cumsum(m_t)/Fs);
s_t =fmmod(m_t, fc, Fs, kf*Am);
subplot(3,1,2);
plot(t, c_t);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, s_t);
title('Frequency Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
figure;
subplot(3,1,1);
plot(f, abs(M_f));
title('Message Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(3,1,2);
plot(f, abs(C_f));
title('Carrier Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
subplot(3,1,3);
plot(f, abs(S_f));
title('Frequency Modulated Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
% Demodulation
% Demodulate using frequency discriminator
%demodulated_signal = diff(unwrap(angle(s_t)));
demodulated_signal =fmdemod(s_t, fc, Fs, kf*Am);
5. Sampling and reconstruction of low pass signals. Display the signals and its spectrum.
% Sampling
Fs_new = 200; % New sampling frequency
T_new = 1/Fs_new; % New sampling period
t_new = 0:T_new:1; % New time vector
sampled_signal = sin(2*pi*fm*t_new);
% Plot sampled signal
subplot(4,1,3);
stem(t_new, sampled_signal);
title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1,4);
plot(f_new, abs(sampled_signal_spectrum));
title('Spectrum of Sampled Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([-100, 100]); % adjust based on the frequency content of the signal
% Demultiplexing
demultiplexed_signals = zeros(N, length(t));
for i = 1:N
demultiplexed_signals(i, :) = multiplexed_signal .* channels(i, :);
end
% Sampling
fs_new = 50; % New sampling frequency (Hz)
t_new = 0:1/fs_new:T; % New time vector
x_sampled = sin(2*pi*f_signal*t_new)
% Quantization
bits = 4; % Number of quantization bits
levels = 2^bits; % Number of quantization levels
x_quantized = round((x_sampled + 1) * (levels - 1) / 2) / ((levels - 1) / 2) -
1
x_quantized = max(min(x_quantized, 1), -1) % Limit values to [-1, 1]