0% found this document useful (0 votes)
6 views

hARISH SIR LAB FINAL

Uploaded by

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

hARISH SIR LAB FINAL

Uploaded by

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

HARSHIT KUMAR GUPTA

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

Fs = 1000; % Sampling frequency

Fc = 50; % Carrier frequency

Rb = 10; % Bit rate

Tb = 1/Rb; % Bit duration Nb = 10; %

Number of bits t = 0:1/Fs:Nb*Tb-

1/Fs; % Time vector

% Generate random binary data data

= randi([0 1], 1, Nb);

% Generate ASK signal

ask_signal = zeros(1, length(t));

carrier = cos(2*pi*Fc*t); for i =

1:Nb

if data(i) == 1 ask_signal((i-1)*Fs*Tb+1:i*Fs*Tb) = carrier((i-

1)*Fs*Tb+1:i*Fs*Tb);

else ask_signal((i-

1)*Fs*Tb+1:i*Fs*Tb) = 0; end

end

% Plot data and ASK signal figure;

subplot(2, 1, 1); stairs(0:Nb-1,

data, 'LineWidth', 2); title('Binary

Data'); xlabel('Bit');
ylabel('Amplitude'); axis([0 Nb -0.5

1.5]); grid on;

subplot(2, 1, 2); plot(t,

ask_signal); title('ASK

Signal'); xlabel('Time

(s)');

ylabel('Amplitude');

grid on;

% Compute and plot the frequency response of ASK

figure;

N = length(ask_signal); f = (-N/2:N/2-

1)*(Fs/N); % Frequency vector ASK_FFT =

fftshift(fft(ask_signal, N)); plot(f,

abs(ASK_FFT)/N); title('ASK Frequency

Response'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on;

disp('ASK modulation and frequency response generated.');


PSK and ITS FREQUENCY RESPONSE
% File: psk_modulation_frequency_response.m

% Parameters

Fs = 1000; % Sampling frequency

Fc = 50; % Carrier frequency

Rb = 10; % Bit rate

Tb = 1/Rb; % Bit duration Nb = 10; %

Number of bits t = 0:1/Fs:Nb*Tb-

1/Fs; % Time vector

% Generate random binary data

data = randi([0 1], 1, Nb);

% Map binary data to BPSK symbols (+1 and -1) bpsk_symbols

= 2*data - 1;

% Generate PSK signal psk_signal = zeros(1, length(t)); for i = 1:Nb psk_signal((i-

1)*Fs*Tb+1:i*Fs*Tb) = bpsk_symbols(i) * cos(2*pi*Fc*t((i-1)*Fs*Tb+1:i*Fs*Tb)); end

% Plot data and PSK signal

figure; subplot(2, 1, 1); stairs(0:Nb-

1, data, 'LineWidth', 2);

title('Binary Data'); xlabel('Bit');

ylabel('Amplitude'); axis([0

Nb -0.5 1.5]); grid on;

subplot(2, 1, 2); plot(t,

psk_signal); title('PSK

Signal'); xlabel('Time

(s)');
ylabel('Amplitude');

grid on;

% Compute and plot the frequency response of PSK

figure;

N = length(psk_signal); f = (-N/2:N/2-

1)*(Fs/N); % Frequency vector PSK_FFT =

fftshift(fft(psk_signal, N)); plot(f,

abs(PSK_FFT)/N); title('PSK Frequency

Response'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on;

disp('PSK modulation and frequency response generated.');


FSK and ITS FREQUENCY RESPONSE

% File: fsk_modulation_frequency_response.m

% Parameters

Fs = 1000; % Sampling frequency

Fc1 = 30; % Frequency for bit 0

Fc2 = 70; % Frequency for bit 1

Rb = 10; % Bit rate

Tb = 1/Rb; % Bit duration Nb = 10; %

Number of bits t = 0:1/Fs:Nb*Tb-

1/Fs; % Time vector

% Generate random binary data

data = randi([0 1], 1, Nb);

% Generate FSK signal

fsk_signal = zeros(1, length(t));

for i = 1:Nb if data(i) == 0

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

% Plot data and FSK signal figure;

subplot(2, 1, 1); stairs(0:Nb-1,

data, 'LineWidth', 2); title('Binary

Data'); xlabel('Bit');

ylabel('Amplitude');

axis([0 Nb -0.5 1.5]); grid

on;
subplot(2, 1, 2); plot(t,

fsk_signal); title('FSK

Signal'); xlabel('Time

(s)');

ylabel('Amplitude');

grid on;

% Compute and plot the frequency response of FSK

figure;

N = length(fsk_signal); f = (-N/2:N/2-

1)*(Fs/N); % Frequency vector FSK_FFT =

fftshift(fft(fsk_signal, N)); plot(f,

abs(FSK_FFT)/N); title('FSK Frequency

Response'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on;

disp('FSK modulation and frequency response generated.');


HARSHIT KUMAR GUPTA
211211
LAB 2- CDMA MODULATION
% Parameters

Fs = 1000; % Sampling frequency (common for both)


Rb_input = 5; % Bit rate for input data (lower rate for longer bit duration)

Tb_input = 1/Rb_input; % Bit duration for input data

Nb = 5; % Number of bits (for input data)

Rb_code = 20; % Bit rate for spreading code (higher rate for shorter bit duration)

Tb_code = 1/Rb_code; % Bit duration for spreading code

Nc = 4; % Number of bits in the spreading code

% Time vectors t_input = 0:1/Fs:Nb*Tb_input-1/Fs; % Time vector

for input data t_code = 0:1/Fs:Nc*Tb_code-1/Fs; % Time vector for

spreading code

% Generate random binary input data data

= randi([0 1], 1, Nb);

% Generate a fixed one-bit spreading code '1 0 1 0' pattern one_bit_code

= [1 0 1 0];

% Prepare for XOR operation: extend spreading code to match the duration of input bits

extended_spread_code = []; for i = 1:Nb

extended_spread_code = [extended_spread_code, one_bit_code]; end

% 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

spread_signal = zeros(1, Nb*Nc); for i = 1:Nb start_idx = (i-1)*Nc + 1; end_idx =

i*Nc; spread_signal(start_idx:end_idx) = xor(data(i), one_bit_code); end

% Manual FFT function as before function [f,

X_shifted] = manual_fft(signal, Fs)


N = length(signal);

X = zeros(1, N);

for k = 0:N-1 for

n = 0:N-1

X(k+1) = X(k+1) + signal(n+1) * exp(-1i * 2 * pi * k * n / N);

end end

% Manual FFT shift (fftshift equivalent)

X_shifted = zeros(1, N); half_N =

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

% Compute the frequency response for input data user_data_rep

= repelem(data, Fs*Tb_input);

[f_data, X_shifted_data] = manual_fft(user_data_rep, Fs);

% Compute the frequency response for the spreading code spread_code_rep

= repelem(one_bit_code, Fs*Tb_code);

[f_code, X_shifted_code] = manual_fft(spread_code_rep, Fs);

% Compute the frequency response for the spread signal spread_signal_rep

= repelem(spread_signal, Fs*Tb_code);

[f_spread, X_shifted_spread] = manual_fft(spread_signal_rep, Fs);

% Plot 1: Input data and its frequency response

figure; subplot(2, 1, 1); stairs(0:Nb-1, data,

'LineWidth', 2); title('Input Binary Data (Time

Domain)');
xlabel('Bit');

ylabel('Amplitude');

axis([0 Nb -0.5 1.5]); grid

on;

subplot(2, 1, 2); plot(f_data,

abs(X_shifted_data)/length(user_data_rep)); title('Input

Binary Data (Frequency Domain)'); xlabel('Frequency

(Hz)'); ylabel('Magnitude'); grid on;

% Plot 2: Spreading code and its frequency response

figure; subplot(2, 1, 1); stairs(0:Nc-1,

one_bit_code, 'LineWidth', 2);

title('Spreading Code (Time Domain)');

xlabel('Bit');

ylabel('Amplitude');

axis([0 Nc -0.5 1.5]); grid

on;

subplot(2, 1, 2);

plot(f_code, abs(X_shifted_code)/length(spread_code_rep));

title('Spreading Code (Frequency Domain)');

xlabel('Frequency (Hz)'); ylabel('Magnitude'); grid on;

% Plot 3: Spread signal and its frequency response

figure; subplot(2, 1, 1); stairs(0:Nb*Nc-1, spread_signal,

'LineWidth', 2); title('Spread Signal after XOR Operation

(Time Domain)'); xlabel('Bit');

ylabel('Amplitude'); axis([0

Nb*Nc -0.5 1.5]); grid on;


subplot(2, 1, 2); plot(f_spread,

abs(X_shifted_spread)/length(spread_signal_rep)); title('Spread

Signal (Frequency Domain)'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on;

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

Fs = 1000; % Sampling frequency

Rb_input = 2; % Bit rate for input data

Tb_input = 1/Rb_input; % Bit duration for input data

Nb = 5; % Number of bits (for input data)

Rb_code = 50; % Bit rate for spreading code

Tb_code = 1/Rb_code; % Bit duration for spreading code

Nc = 4; % Number of bits in the spreading code

% Time vectors t_input = 0:1/Fs:Nb*Tb_input-1/Fs; % Time vector for

input data t_code = 0:1/Fs:Nc*Tb_code-1/Fs; % Time vector for spreading

code t_output = 0:1/Fs:(Nb*Nc)*Tb_code-1/Fs; % Time vector for spread

signal

% Generate random binary input data

data = randi([0 1], 1, Nb);

% Generate a fixed one-bit spreading code '1 0 1 0' pattern one_bit_code

= [1 0 1 0];

% Extend the spreading code to match the duration of input bits

extended_spread_code = repmat(one_bit_code, 1, Nb); extended_spread_code

= extended_spread_code(1:Nb*Nc);
% Perform XOR operation between each input bit and corresponding spreading code

spread_signal = zeros(1, Nb*Nc); for i = 1:Nb start_idx = (i-1)*Nc + 1; end_idx =

i*Nc; spread_signal(start_idx:end_idx) = xor(data(i), one_bit_code); end

% CDMA Demodulation despread_signal

= zeros(1, Nb*Nc);

for i = 1:Nb start_idx = (i-1)*Nc + 1; end_idx = i*Nc; despread_signal(start_idx:end_idx) =

xor(spread_signal(start_idx:end_idx), one_bit_code); end

% Reconstruct the original data using majority vote

demodulated_data = zeros(1, Nb); for i = 1:Nb

start_idx = (i-1)*Nc + 1; end_idx = i*Nc; if

sum(despread_signal(start_idx:end_idx)) > Nc/2

demodulated_data(i) = 1;

else

demodulated_data(i) = 0;

end

end

% Frequency Analysis user_data_rep = repelem(data,

length(t_input)/length(data)); [f_data, X_shifted_data] =

manual_fft(user_data_rep, Fs); spread_signal_rep =

repelem(spread_signal,

length(t_output)/length(spread_signal)); spread_signal_rep =

spread_signal_rep(1:length(t_output));

[f_spread, X_shifted_spread] = manual_fft(spread_signal_rep, Fs);

despread_signal_rep = repelem(despread_signal, length(t_output)/length(despread_signal));

despread_signal_rep = despread_signal_rep(1:length(t_output));

[f_despread, X_shifted_despread] = manual_fft(despread_signal_rep, Fs);


% Plot Time Domain

figure;

subplot(3, 1, 1); stairs(t_input,

user_data_rep(1:length(t_input)), 'LineWidth', 2); title('Input

Data vs Time'); xlabel('Time (s)'); ylabel('Amplitude'); grid on;

subplot(3, 1, 2); plot(t_output, spread_signal_rep, 'LineWidth',

2); title('Spread Signal vs Time'); xlabel('Time (s)');

ylabel('Amplitude'); grid on; subplot(3, 1, 3); plot(t_output,

despread_signal_rep, 'LineWidth', 2); title('Demodulated

Output vs Time');

xlabel('Time (s)');

ylabel('Amplitude'); grid

on;

% Plot Frequency Domain

figure; subplot(3, 1, 1); plot(f_data,

abs(X_shifted_data)/length(user_data_rep)); title('Frequency

Response of Input Data'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on; subplot(3, 1, 2); plot(f_spread,

abs(X_shifted_spread)/length(spread_signal_rep));

title('Frequency Response of Spread Signal'); xlabel('Frequency

(Hz)'); ylabel('Magnitude'); grid on; subplot(3, 1, 3); plot(f_data,

abs(X_shifted_data)/length(user_data_rep)); title('Frequency

Response of Demodulated Data'); xlabel('Frequency (Hz)');

ylabel('Magnitude'); grid on;

disp('CDMA modulation, demodulation, and frequency response analysis completed.');

function [f, X_shifted] = manual_fft(signal, Fs)

N = length(signal);

X = zeros(1, N);

for k = 0:N-1 for

n = 0:N-1
X(k+1) = X(k+1) + signal(n+1) * exp(-1i * 2 * pi * k * n / N);

end

end

X_shifted = [X(N/2+1:N) X(1:N/2)]; % Shift FFT result

f = (-N/2:N/2-1)*(Fs/N); % Frequency vector end


EXPERIMENT 4
AIM: To find power received by the transmitter and the receiver due to three paths
between the transmitter and the receiver

SOTWARE REQUIRED: MATLAB SOFTWARE

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 = linspace(100, 5000, 1000);

d_LOS = d;

d_ref1 = sqrt(d.^2 + (h_t + h_r)^2);

h_object = 30;
d_ref2 = sqrt(d.^2 + (h_t - h_object)^2 + (h_object - h_r)^2);

phi_LOS = 2 * pi * d_LOS / lambda;


phi_ref1 = 2 * pi * d_ref1 / lambda;
phi_ref2 = 2 * pi * d_ref2 / lambda;

A_LOS = sqrt(P_t * G_t * G_r) ./ d_LOS;


A_ref1 = sqrt(P_t * G_t * G_r) ./ d_ref1;
A_ref2 = sqrt(P_t * G_t * G_r) ./ d_ref2;

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;

P_r_dBm = 10 * log10(P_r / 1e-3);

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

signal = zeros(1, length(t));

for i = 1:n
f = randi([1 10], 1) * 1e9;
A = randi([1 10], 1);
signal = A * sind(2 * pi * f * t);

norm_factor = normpdf(t, 0.5, 0.1);

out = rcf .* (signal + norm_factor);

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

SOFTWARE REQUIRED: MATLAB SOFTWARE

MATLAB CODE:
fs = 1e3;
t = 0:1/fs:1;
f = 5;
n = 3;
scale = 1;
K = 3;

sineWaves = zeros(n, length(t));


for i = 1:n
sineWaves(i, :) = sin(2 * pi * f * t + (i-1) * (pi/4));
end

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

fadedSignals = zeros(n, length(t));


for r = 1:n
for tIndex = 1:n
fadedSignals(r, :) = pdfRician .* sineWaves(tIndex, :);
end
end

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

SOFTWARE REQUIRED: MATLAB SOFTWARE

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

received_signal = input_signal + noise;


numCoeffs = 10;
filter_coefficients = zeros(1, numCoeffs);

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

error_signal_smoothed = received_signal - smoothed_output_signal;


MSE_smoothed = mean(error_signal_smoothed.^2);
RMSE_smoothed = sqrt(MSE_smoothed);
Experimet-8
Aim – To perform OFDM
Software used – MATLAB
Code---
% Parameters
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1; % Time vector (1 second)
f_message = 5; % Frequency of the message signal
A_message = 1; % Amplitude of the message signal
% Create the message signal (sine wave)
message_signal = A_message * sin(2 * pi * f_message * t);
% Frequency modulation parameters
f_mod1 = 50; % Modulation frequency 1
f_mod2 = 100; % Modulation frequency 2
f_mod3 = 150; % Modulation frequency 3
k1 = 5; % Frequency sensitivity for mod1
k2 = 5; % Frequency sensitivity for mod2
k3 = 5; % Frequency sensitivity for mod3
% Modulated signals
modulated_signal1 = A_message * sin(2 * pi * f_mod1 * t + k1 * message_signal);
modulated_signal2 = A_message * sin(2 * pi * f_mod2 * t + k2 * message_signal);
modulated_signal3 = A_message * sin(2 * pi * f_mod3 * t + k3 * message_signal);
% Phase offsets
phase_offset1 = pi / 4; % Phase offset for signal 1
phase_offset2 = pi / 3; % Phase offset for signal 2
phase_offset3 = pi / 6; % Phase offset for signal 3
% Adjusted signals after subtracting phase offsets
adjusted_signal1 = modulated_signal1 .* exp(-1i * phase_offset1);
adjusted_signal2 = modulated_signal2 .* exp(-1i * phase_offset2);
adjusted_signal3 = modulated_signal3 .* exp(-1i * phase_offset3);
% Demodulation using frequency demodulation
demodulated_signal1 = angle(hilbert(real(adjusted_signal1)));
demodulated_signal2 = angle(hilbert(real(adjusted_signal2)));
demodulated_signal3 = angle(hilbert(real(adjusted_signal3)));
% Normalize demodulated signals
demodulated_signal1 = demodulated_signal1 / max(abs(demodulated_signal1));
demodulated_signal2 = demodulated_signal2 / max(abs(demodulated_signal2));
demodulated_signal3 = demodulated_signal3 / max(abs(demodulated_signal3));
% Plotting all signals in separate figure windows
% Plot Original Message Signal
figure;
plot(t, message_signal);
title('Original Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Modulated Signal 1
figure;
plot(t, modulated_signal1);
title('Modulated Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Modulated Signal 2
figure;
plot(t, modulated_signal2);
title('Modulated Signal 2');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Modulated Signal 3
figure;
plot(t, modulated_signal3);
title('Modulated Signal 3');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Demodulated Signal 1
figure;
plot(t, demodulated_signal1);
title('Demodulated Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Demodulated Signal 2
figure;
plot(t, demodulated_signal2);
title('Demodulated Signal 2');
xlabel('Time (s)');
ylabel('Amplitude');
% Plot Demodulated Signal 3
figure;
plot(t, demodulated_signal3);
title('Demodulated Signal 3');
xlabel('Time (s)');
ylabel('Amplitude');
figure;
plot(t, message_signal);
title('Demodulated Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');

You might also like