0% found this document useful (0 votes)
67 views9 pages

PCS Programs

The document discusses various signal types including unit step, rectangular, triangle, sinusoidal, and exponential signals. It also covers topics like amplitude and frequency modulation, sampling of low-pass signals, time division multiplexing, and an illustration of PCM including sampling and quantization.

Uploaded by

shilpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views9 pages

PCS Programs

The document discusses various signal types including unit step, rectangular, triangle, sinusoidal, and exponential signals. It also covers topics like amplitude and frequency modulation, sampling of low-pass signals, time division multiplexing, and an illustration of PCM including sampling and quantization.

Uploaded by

shilpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Basic Signals and Signal Graphing: a) unit Step, b) Rectangular, c) standard triangle d) sinusoidal and e)
Exponential signal.

a) unit Step signal

n=0:9;
y=ones(1,10);
stem(n,y);
xlabel('Samples');
ylabel('Amplitude');
title('Unit step function');

b) Rectangular signal

T = 5; % Period of the rectangular signal


A = 1; % Amplitude of the rectangular signal
t = 0:0.01:10; % Time range for plotting
y= A * square(2*pi/T*t,30);
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('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.

pulse_amplitude = 1; % Amplitude of the pulse


pulse_width = 1; % Duration of the pulse (in seconds)

t = -2*pulse_width:0.01:2*pulse_width % Time range with sufficient resolution

pulse = pulse_amplitude * (abs(t) <= pulse_width/2)

% Plot pulse in time domain


figure(1);
plot(t, pulse);
xlabel('Time (s)');
ylabel('Amplitude');
title('Rectangular Pulse in Time Domain');

% Perform Fast Fourier Transform (FFT)


freq_domain = fftshift(fft(pulse)); % Apply fftshift for proper centering

% Calculate absolute value (magnitude) of the spectrum


magnitude_spectrum = abs(freq_domain);

% Define frequency vector based on sampling rate


fs = 1/0.01; % Sampling rate (inverse of time resolution)
f = linspace(-fs/2, fs/2, length(freq_domain)); % Frequency range

% Plot magnitude spectrum in frequency domain


figure(2);
plot(f, magnitude_spectrum);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum of 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

m_t = Am*sin(2*pi*fm*t); % Generate message signal


c_t = Ac*sin(2*pi*fc*t); % Generate carrier signal

s_t = (1 + m_t).*c_t; % Modulated signal

% Plotting the signals


figure;
subplot(3,1,1);
plot(t, m_t);
title('Message Signal');
xlabel('Time (s)');
ylabel('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');

% Spectra of the signals


M_f = fftshift(fft(m_t))/length(m_t);
C_f = fftshift(fft(c_t))/length(c_t);
S_f = fftshift(fft(s_t))/length(s_t);
f = linspace(-Fs/2,Fs/2,length(t));

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;

% Plotting the demodulated signal


figure;
plot(t, demodulated_signal);
title('Demodulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');

4. Frequency 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
kf = 10; % Modulation index

m_t = Am*sin(2*pi*fm*t); % Generate message signal


c_t = Ac*sin(2*pi*fc*t); % Generate carrier signal

% 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);

% Plotting the signals


figure;
subplot(3,1,1);
plot(t, m_t);
title('Message Signal');
xlabel('Time (s)');
ylabel('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('Frequency Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Spectra of the signals


M_f = fftshift(fft(m_t))/length(m_t);
C_f = fftshift(fft(c_t))/length(c_t);
S_f = fftshift(fft(s_t))/length(s_t);
f = linspace(-Fs/2,Fs/2,length(t));

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);

% Plotting the demodulated signal


figure;
plot(t, demodulated_signal);
title('Demodulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');

5. Sampling and reconstruction of low pass signals. Display the signals and its spectrum.

Fs = 1000; % Sampling frequency


T = 1/Fs; % Sampling period
t = 0:T:1; % Time vector
fc = 50; % Cutoff frequency of low-pass filter
fm = 5; % Frequency of the input signal

% Generate low-pass signal


low_pass_signal = sin(2*pi*fm*t);

% Plot original signal and its spectrum


figure;
subplot(4,1,1);
plot(t, low_pass_signal);
title('Original Low Pass Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Spectrum of original signal


low_pass_signal_spectrum =
fftshift(fft(low_pass_signal))/length(low_pass_signal);
f=linspace(-Fs/2,Fs/2,length(t));
subplot(4,1,2);
plot(f, abs(low_pass_signal_spectrum));
title('Spectrum of Original Low Pass Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([-100, 100]); % adjust based on the frequency content of the signal

% 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');

% Spectrum of sampled signal


sampled_signal_spectrum =
fftshift(fft(sampled_signal))/length(sampled_signal);
f_new=linspace(-Fs_new/2,Fs_new/2,length(t_new));

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

% Reconstruction using zero-order hold


reconstructed_signal = zeros(size(t));
for i = 1:length(t_new)
index = round(t_new(i) / T) + 1;
reconstructed_signal(index) = sampled_signal(i);
end

% Plot reconstructed signal


figure;
plot(t, reconstructed_signal);
title('Reconstructed Signal (Zero-Order Hold)');
xlabel('Time (s)');
ylabel('Amplitude');

% Spectrum of reconstructed signal


reconstructed_signal_spectrum = fftshift(fft(reconstructed_signal));
figure;
plot(f, abs(reconstructed_signal_spectrum));
title('Spectrum of Reconstructed Signal (Zero-Order Hold)');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([-100, 100]); % adjust based on the frequency content of the signal

6. Time Division Multiplexing (TDM) and Demultiplexing


Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
t = 0:T:1; % Time vector
N = 4; % Number of channels
frequencies = [10, 20, 30, 40]; % Frequencies of the channels

% Generate example signals for each channel


channels = zeros(N, length(t));
for i = 1:N
channels(i, :) = sin(2*pi*frequencies(i)*t);
end

% Time Division Multiplexing


multiplexed_signal = sum(channels);

% Plot multiplexed signal


figure;
plot(t, multiplexed_signal);
title('Multiplexed Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Demultiplexing
demultiplexed_signals = zeros(N, length(t));
for i = 1:N
demultiplexed_signals(i, :) = multiplexed_signal .* channels(i, :);
end

% Plot demultiplexed signals


figure;
for i = 1:N
subplot(N, 1, i);
plot(t, demultiplexed_signals(i, :));
title(['Demultiplexed Channel ', num2str(i)]);
xlabel('Time (s)');
ylabel('Amplitude');
end

7. PCM Illustration: Sampling, Quantization and Encoding


clc
close all
fs = 1000; % Sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
t = 0:1/fs:T; % Time vector

% Generate a test signal (e.g., a sine wave)


f_signal = 5; % Frequency of the sine wave (Hz)
x = sin(2*pi*f_signal*t);

% Plot the original signal


subplot(3,1,1);
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Signal');

% 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)

% Plot the sampled signal


subplot(3,1,2);
stem(t_new,x_sampled);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled Signal');

% 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]

% Plot the quantized signal


subplot(3,1,3);
stem(t_new,x_quantized);
xlabel('Time (s)');
ylabel('Amplitude');
title('Quantized Signal');

% Encoding (converting quantized signal to binary)


x_quantized_integer = (x_quantized + 1) * (levels - 1) / 2; % Scale to integer
values
x_quantized_integer = max(min(round(x_quantized_integer), levels - 1), 0); %
Ensure values are within [0, levels-1]
x_encoded = de2bi(x_quantized_integer, bits, 'left-msb');

% Display the encoding result


disp('Encoding result (binary representation):');
disp(x_encoded);

You might also like