hARISH SIR LAB FINAL
hARISH SIR LAB FINAL
211211
ECE
WIRELESS AND CELLULAR COMMUNICATION LAB
HARSHIT 211211
ASK, PSK , FSK AND ITS FREQUENCY RESPONSE
ASK and ITS FFREQUENCY RESPONSE
% File: ask_modulation_frequency_response.m
% Parameters
1:Nb
1)*Fs*Tb+1:i*Fs*Tb);
else ask_signal((i-
1)*Fs*Tb+1:i*Fs*Tb) = 0; end
end
Data'); xlabel('Bit');
ylabel('Amplitude'); axis([0 Nb -0.5
ask_signal); title('ASK
Signal'); xlabel('Time
(s)');
ylabel('Amplitude');
grid on;
figure;
N = length(ask_signal); f = (-N/2:N/2-
% Parameters
= 2*data - 1;
ylabel('Amplitude'); axis([0
psk_signal); title('PSK
Signal'); xlabel('Time
(s)');
ylabel('Amplitude');
grid on;
figure;
N = length(psk_signal); f = (-N/2:N/2-
% File: fsk_modulation_frequency_response.m
% Parameters
fsk_signal((i-1)*Fs*Tb+1:i*Fs*Tb) = cos(2*pi*Fc1*t((i-1)*Fs*Tb+1:i*Fs*Tb));
else
fsk_signal((i-1)*Fs*Tb+1:i*Fs*Tb) = cos(2*pi*Fc2*t((i-1)*Fs*Tb+1:i*Fs*Tb));
end
end
Data'); xlabel('Bit');
ylabel('Amplitude');
on;
subplot(2, 1, 2); plot(t,
fsk_signal); title('FSK
Signal'); xlabel('Time
(s)');
ylabel('Amplitude');
grid on;
figure;
N = length(fsk_signal); f = (-N/2:N/2-
Rb_code = 20; % Bit rate for spreading code (higher rate for shorter bit duration)
spreading code
= [1 0 1 0];
% Prepare for XOR operation: extend spreading code to match the duration of input bits
% Ensure the extended spread code length matches the input data length extended_spread_code
= extended_spread_code(1:Nb*Nc);
% Perform XOR operation between each input bit and corresponding spreading code
X = zeros(1, N);
n = 0:N-1
end end
floor(N/2);
X_shifted(1:half_N) = X(half_N+1:end);
X_shifted(half_N+1:end) = X(1:half_N);
% Frequency vector f
= (-N/2:N/2-1)*(Fs/N);
end
= repelem(data, Fs*Tb_input);
= repelem(one_bit_code, Fs*Tb_code);
= repelem(spread_signal, Fs*Tb_code);
Domain)');
xlabel('Bit');
ylabel('Amplitude');
on;
abs(X_shifted_data)/length(user_data_rep)); title('Input
xlabel('Bit');
ylabel('Amplitude');
on;
subplot(2, 1, 2);
plot(f_code, abs(X_shifted_code)/length(spread_code_rep));
ylabel('Amplitude'); axis([0
abs(X_shifted_spread)/length(spread_signal_rep)); title('Spread
disp('XOR operation with different bit durations and frequency response analysis completed.');
HARSHIT KUMR GUPTA
211211
LAB 3
CDMA DEMODULATION
% File: cdma_modulation_demodulation_plots_corrected.m
% Parameters
signal
= [1 0 1 0];
= extended_spread_code(1:Nb*Nc);
% Perform XOR operation between each input bit and corresponding spreading code
= zeros(1, Nb*Nc);
demodulated_data(i) = 1;
else
demodulated_data(i) = 0;
end
end
repelem(spread_signal,
length(t_output)/length(spread_signal)); spread_signal_rep =
spread_signal_rep(1:length(t_output));
despread_signal_rep = despread_signal_rep(1:length(t_output));
figure;
Output vs Time');
xlabel('Time (s)');
ylabel('Amplitude'); grid
on;
abs(X_shifted_data)/length(user_data_rep)); title('Frequency
abs(X_shifted_spread)/length(spread_signal_rep));
abs(X_shifted_data)/length(user_data_rep)); title('Frequency
N = length(signal);
X = zeros(1, N);
n = 0:N-1
X(k+1) = X(k+1) + signal(n+1) * exp(-1i * 2 * pi * k * n / N);
end
end
MATLAB CODE:
f = 2.4e9;
c = 3e8;
lambda = c / f;
P_t = 1;
G_t = 1;
G_r = 1;
h_t = 50;
h_r = 2;
d_LOS = d;
h_object = 30;
d_ref2 = sqrt(d.^2 + (h_t - h_object)^2 + (h_object - h_r)^2);
E_total = A_LOS .* exp(-1i * phi_LOS) + A_ref1 .* exp(-1i * phi_ref1) + A_ref2 .* exp(-1i * phi_ref2);
P_r = abs(E_total).^2;
figure;
subplot(2,1,1);
plot(d / 1000, P_r_dBm);
title('Received Power vs Distance in a 3-Ray Model');
xlabel('Distance (km)');
ylabel('Received Power (dBm)');
grid on;
subplot(2,1,2);
plot(d / 1000, unwrap(phi_LOS), 'r', d / 1000, unwrap(phi_ref1), 'b', d / 1000, unwrap(phi_ref2),
'g');
title('Phase vs Distance for 3-Ray Model');
xlabel('Distance (km)');
ylabel('Phase (radians)');
legend('LOS', 'Reflected 1', 'Reflected 2');
grid on;
EXPERIMENT 5
AIM: To find the signal at the receiver from the transmitter using Rayleigh channel
SOFTWARE REQUIRED: MATLAB SOFTWARE
MATLAB CODE:
n = 2;
fs = 300;
t = 0:1/fs:1-1/fs;
sigma = 60;
x = t;
rcf = zeros(1, length(t));
for i = 1:length(t)
c = i - 1;
rcf(i) = c * exp(-c^2 / (2 * sigma^2)) / sigma^2;
end
for i = 1:n
f = randi([1 10], 1) * 1e9;
A = randi([1 10], 1);
signal = A * sind(2 * pi * f * t);
hold on;
plot(t, out);
end
hold off;
xlabel('Time (s)');
ylabel('Amplitude');
title('Modulated Signal with RCF');
EXPERIMENT 6
AIM: To study the signal using Rician
MATLAB CODE:
fs = 1e3;
t = 0:1/fs:1;
f = 5;
n = 3;
scale = 1;
K = 3;
x = 0:0.01:10;
A = sqrt(K / (K + 1));
pdfRician = (x / scale^2) .* exp(-(x.^2 + A^2) / (2 * scale^2)) .* besseli(0, x * A / scale^2);
figure;
for i = 1:n
subplot(n, 1, i);
plot(t, sineWaves(i, :));
title(['Original Sine Wave from Transmitter ', num2str(i)]);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
end
figure;
for r = 1:n
subplot(n, 1, r);
plot(t, fadedSignals(r, :));
title(['Faded Signal at Receiver ', num2str(r)]);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
end
figure;
plot(x, pdfRician, 'LineWidth', 2);
title('Rician Distribution PDF');
xlabel('x');
ylabel('Probability Density');
grid on;
xlim([0 5]);
EXPERIMENT 7
AIM: To study the working of an Equalizer
MATLAB CODE:
time = 0.001:0.001:5;
input_signal = sin(2*pi*time);
SNR = 15;
signal_power = mean(input_signal.^2);
noise_power = signal_power / (10^(SNR/10));
noise = sqrt(noise_power) * randn(size(input_signal));
mu = 0.01;
output_signal = zeros(size(input_signal));
error_signal = zeros(size(input_signal));
for n = numCoeffs:length(input_signal)
input_vector = input_signal(n:-1:n-numCoeffs+1);
output_signal(n) = filter_coefficients * input_vector';
error_signal(n) = received_signal(n) - output_signal(n);
filter_coefficients = filter_coefficients + mu * error_signal(n) * input_vector;
end
window_size = 50;
smoothed_output_signal = filter(ones(1, window_size) / window_size, 1, output_signal);
subplot(3, 1, 1);
plot(time, input_signal, 'LineWidth', 1.5);
title('Input Signal');
subplot(3, 1, 2);
plot(time, received_signal, 'LineWidth', 1.5);
title('Received Signal (Equalizer Input)');
subplot(3, 1, 3);
plot(time, smoothed_output_signal, 'LineWidth', 1.5);
title('Smoothed Equalized Output');