1.
Basic Signals and Signal Graphing: a) Unit Step, b) Rectangular,
c) standard triangle d) sinusoidal and e) Exponential signal.
% Initialization
clc;
clear all;
close all;
% Define time vector
t = -5:0.01:5; %
% a) Unit Step Signal
u = (t>=0);
subplot(3,2,1)
plot(t, u)
title('Unit Step Signal')
xlabel('Time')
ylabel('Amplitude')
% b) Rectangular Signal
rect = rectpuls(t, 2);
subplot(3,2,2)
plot(t, rect)
title('Rectangular Signal')
xlabel('Time')
ylabel('Amplitude')
% c) Standard Triangle Signal
tri = triang(length(t));
subplot(3,2,3)
plot(t, tri)
title('Standard Triangle Signal')
xlabel('Time')
ylabel('Amplitude')
% d) Sinusoidal Signal
A = 1;
f = 2;
sinusoidal = A * sin(2*pi*f*t);
subplot(3,2,4)
plot(t, sinusoidal)
title('Sinusoidal Signal')
xlabel('Time')
ylabel('Amplitude')
% e) Exponential Signal
alpha = 0.5;
exponential = exp(-alpha*t);
subplot(3,1,3)
plot(t, exponential)
title('Exponential Signal')
xlabel('Time')
ylabel('Amplitude')
% Plotting
figure;
subplot(3,2,1)
plot(t, u)
title('Unit Step Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,2,2)
plot(t, rect)
title('Rectangular Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,2,3)
plot(t, tri)
title('Standard Triangle Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,2,4)
plot(t, sinusoidal )
title('Sinusoidal Signal')
xlabel('Time')
ylabel('Amplitude')
subplot(3,2,5)
plot(t, exponential)
title('Exponential Signal')
xlabel('Time')
ylabel('Amplitude')
2. Illustration of signal representation in time and frequency
domains for a rectangular pulse
% Initialization
clc;
clear all;
close all;
% Parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period
duration = 1; % Duration of signal (seconds)
pulse_width = 0.1; % Width of rectangular pulse (seconds)
A = 1; % Amplitude
% Time vector
t = 0:T:duration-T;
% Generate rectangular pulse
x_rect = zeros(size(t));
x_rect(t < pulse_width) = A;
% Compute Fourier Transform
X_rect = fft(x_rect);
f = linspace(0, Fs, length(X_rect));
% Plot the rectangular pulse in time domain
subplot(2, 1, 1);
plot(t, x_rect, 'b', 'LineWidth', 2);
title('Rectangular Pulse in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot the magnitude of the Fourier Transform in frequency domain
subplot(2, 1, 2);
stem(frequencies, abs(X_rect), 'r', 'LineWidth', 2);
title('Magnitude of Fourier Transform in Frequency Domain');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0, Fs/2]); % Adjust plot grid on;
3. Amplitude Modulation and demodulation: Generation and display
the relevant signals and its spectrums
% Initialization
clc;
clear all;
close all;
% Define parameters
Fs = 1000;
T = 1/Fs;
t = 0:T:1;
% Message signal
Am = 1;
fm = 10;
messagesignal = Am * sin(2*pi*fm*t);
% Carrier signal
Ac = 2;
fc = 100;
carriersignal = Ac * cos(2*pi*fc*t);
% Amplitude Modulation
modulatedsignal = (1 + messagesignal) .* carriersignal;
% Demodulation: Envelope Detection
envelope = abs(hilbert(modulatedsignal));
% Compute Fourier Transforms
fft_modulated = fft(modulatedsignal);
fft_envelope = fft(envelope);
% Frequency vectors
f = Fs*(0:(length(t)-1))/length(t);
% Plotting
figure;
% Time-domain plots
subplot(3,2,1);
plot(t, messagesignal);
title('Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,2,2);
plot(t, carriersignal);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,2,3);
plot(t, modulatedsignal);
title('AM Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,2,4);
plot(t, envelope);
title('Demodulated Signal (Envelope)');
xlabel('Time (s)');
ylabel('Amplitude');
% Frequency-domain plots
subplot(3,2,5);
plot(f, abs(fft_modulated));
title('Frequency Spectrum of Modulated Signal');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(3,2,6);
plot(f, abs(fft_envelope));
title('Frequency Spectrum of Demodulated Signal (Envelope)');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
sgtitle('Amplitude Modulation and Demodulation');
4. Frequency Modulation and demodulation: Generation and
display the relevant signals and its spectrums
% Initialization
clc;
clear all;
close all;
% Define parameters
fs=10000;
Ac=1;
Am=1;
fm=35;
fc=500;
B=10; t=(0:.1*fs)/fs;
wc=2*pi*fc;
wm=2*pi*fm;
% Message signal
mt=Am*cos(wm*t);
subplot(5,1,1);
plot(t,m_t);
xlabel(‘Time’)
ylabel(‘Amplitude’)
title(‘Message signal');
% Carrier signal
ct=Ac*cos(wc*t);
subplot(5,1,2);
plot(t,c_t);
xlabel(‘Time’)
ylabel(‘Amplitude’)
title('Carrier signal');
% Frequency Modulation
st=Ac*cos((wc*t)+B*sin(wm*t));
subplot(5,1,3);
plot(t,s_t);
xlabel(‘Time’)
ylabel(‘Amplitude’)
title('Frequency Modulated signal');
% Demodulation: Frequency Discriminator
d=demod(s_t,fc,fs,'fm');
subplot(5,1,4);
plot(t,d);
xlabel(‘Frequency’)
ylabel(‘Amplitude’)
title('demodulated signal');
% compute DFT of noisy signal using FFT function
fspec=fft(st);
%shift the spectrum
n=length(t);
fshift=(-n/2:n/2-1)*(1000/n);
yshift=fftshift(fspec);
%plot magnitude of computed FFT values
subplot(5,1,5);
plot(fshift,abs(yshift));
xlabel('frequency');
ylabel('Magnitude');
title('magnitude of FFT');
5. Sampling and reconstruction of low pass signals. Display the
signals and its spectrum
% Initialization
clc;
clear all;
close all;
% Define parameters
A=1;
F=2;
t=0: 0.001:1;
% Analog Input signal
x_a=A*sin(2*pi*F*t);
subplot(3,1,1);
plot(t,x_a);
xlabel('time (sec)');
ylabel('x_a');
title('Analog input signal','Linewidth',5);
% Discrete time signal
F_s=6*F;
T_s=1/F_s;
n=F_s;
n_1=0:T_s:n*T_s;
x_s=A*sin(2*pi*F*n_1);
subplot(3,1,2);
stem(n_1,x_s);
xlabel('samples (n)');
ylabel('x_s');
title('Discrete time signal','Linewidth',5);
% Reconstructed signal
t_1=linspace(0,max(n_1),(max(n_1)/dt));
x_r=interp1(n_1,x_s,t_1,'spline');
subplot(3,1,3);
plot(t_1,x_r);
xlabel('time (sec)');
ylabel('x_r');
title('Reconstructed signal','Linewidth',5);
6. Time Division Multiplexing and Demultiplexing.
% Number of signals to multiplex
numSignals = 3
% Number of time slots
numSlots = 10
% Generate random data for each signal
data = cell(1, numSignals);
for i = 1:numSignals
data{i} = randi([0, 100], 1, numSlots) % Generate random data for each signal
end
% Multiplexing (combining signals into one)
TDM_signal = zeros(1, numSlots*numSignals)
for i = 1:numSignals
TDM_signal((i-1)*numSlots+1:i*numSlots) = data{i}
end
% Display multiplexed signal
disp('Multiplexed Signal (TDM):');
disp(TDM_signal);
% Demultiplexing (separating signals)
demux_data = cell(1, numSignals);
for i = 1:numSignals
demux_data{i} = TDM_signal(i:numSignals:end);
end
% Display demultiplexed signals
for i = 1:numSignals
fprintf('Demultiplexed Signal %d:\n', i);
disp(demux_data{i});
end
7. PCM Illustration: Sampling, Quantization and Encoding
% Initialisation
clc;
clear all;
close all;
% Parameters
Fs = 1000;
% Sampling period
T = 1/Fs;
% Time vector for one second
t = 0: T:1-T;
% Analog signal (example: sine wave)
Analog_signal = sin(2*pi*5*t);
% Plot analog signal
subplot (3,1,1);
plot (t, Analog_signal);
title ('Analog Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Sampling
nSamples = 10;
% Number of samples
sampled_signal = Analog_signal(1: nSamples);
% Plot sampled signal
stem((0:(nSamples-1))*T, sampled_signal);
title ('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Quantization
nBits = 4;
% Number of bits for quantization
quantized_signal = round(sampled_signal * (2^(nBits-1) - 1));
% Plot quantized signal
subplot (3,1,3);
stem((0:nSamples-1)*T, quantized_signal);
title ('Quantized Signal');
xlabel('Time (s)');
ylabel('Quantization Levels');
% Encoding (converting to binary)
binary_signal = de2bi(quantized_signal, nBits, 'left-msb');
% Display encoded signal
disp('Encoded Signal (Binary):');
disp(binary_signal);
8. Generate a) NRZ, RZ and Raised cosine pulse, b) Generate and
plot eye diagram
a) NRZ
% Initialization
clc;
clear all;
close all;
% Define parameters
n=[1 0 1 0 1 0 1 0];
for m=1:length(n)
if n(m)==1
nn(m)=1;
else
nn(m)=-1;
end
end
i=1;
t=0:.01:length(n);
for j=1:length(t)
if( t(j)<=i);
y(j)=nn(i);
else y(j)=nn(i);
i=i+1;
end
end
% Plotting
plot(t,y,'g');
axis([0 length(n) -2 2]);
title('NRZ polar waveform');
xlabel('time-->');
ylabel('amplitude-->');
b) RZ
% Initialization
clc;
clear all;
close all;
% Define parameters
n=[1 0 1 0 1 0 0 1];
for m=1:length(n)
if n(m)==1
nn(m)=1;
else nn(m)=-1;
end
end i=1;
a=0;
b=0.5;
t=0:0.01:length(n);
for j=1:length(t)
if( t(j)>=a && t(j)<=b)
y(j)=nn(i);
elseif(t(j)>b && t(j)<=i)
y(j)=0;
else i=i+1;
a=a+1;
b=b+1;
end
end
% Plotting
plot(t,y,'g');
axis([0 length(n) -2 2]);
title('RZ bipolar waveform');
xlabel('time-->');
ylabel('amplitude-->');
c) RaisedCosine pulse
B=0.5; % Value
Ts=0.01; % Sampling interval
N=2000; % Number of Samples
t=-20:Ts:(N-1)*Ts;
% formula
Pt_RootRasiedCosine=((sin(pi*t.*(1-B))+4*B*t.*cos(pi*t*(1+B)))./(pi*t.*(1-(4*B*t).^2)));
plot(Pt_RootRasiedCosine);
d) Generate and plot eye diagrams
% Generate a random binary signal
data_length = 1000;
data = randi([0, 1], 1, data_length);
% Reshape the data into a matrix with desired number of samples per symbol
samples_per_symbol = 10;
num_symbols = data_length / samples_per_symbol;
eye_data = reshape(data, samples_per_symbol, num_symbols);
% Plot the eye diagram
figure;
plot(eye_data);
title('Eye Diagram');
xlabel('Sample');
ylabel('Amplitude');
grid on;
9. Generate the Probability density function of Gaussian
distribution function
% Initialization
clc;
clear all;
close all;
% Parameters
mu = 0; % Mean of the Gaussian distribution
sigma = 1; % Standard deviation of the Gaussian distribution
% Define range for x-axis
x = -5:0.1:5;
% Compute PDF
pdf = (1 / (sigma * sqrt(2 * pi))) * exp(-(x - mu).^2 / (2 * sigma^2));
% Plot PDF
figure;
subplot(1,1,1)
plot(x, pdf, 'b', 'LineWidth', 2);
title('Probability Density Function of Gaussian Distribution');
xlabel('x');
ylabel('PDF');
grid on;
10. Display the signal and its spectrum of an audio signal.
Matlab Code:
% Initialisation
Clc,
Clear all;
Close all;
% Define Parameters
Fs =4000;
channels=1;
bits=16;
r=audiorecorder(Fs,bits,channels);
duration=5;
disp('Recording started');
recordblocking (r,duration);
disp('Recording stopped');
X=getaudiodata(r);
sound(X,Fs,bits);
% Time Vector
t=0:1/Fs:(length(X)-1)/Fs;
% Plotting of Time domain signal.
figure;
subplot(2,1,1);
plot(t,X,'Linewidth',1.5);
xlabel('time(sec)');
ylabel('Ampitude');
title('Time Domin Plot of the Recorded Signal');
% Frequency Spectrum
F=0:(n-1)*Fs/n;
Y=fft(X,n);
F_0=(-n/2:n/2-1).*(Fs/n);
Y_0=fftshift(Y);
AY_0=abs(Y_0);
% Plotting of Frequency Spectrum
subplot(2,1,2);
plot(F_0,AY_0,'Linewidth',1.5');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Frequency Domain plot of Audio Signal');
filename='[Link]';