MATLAB Script
% User input for choosing the type of impulse response
response_type = input('Enter "random" for random channel impulse response or "ideal" for near-ideal impulse response: ', 's');
if strcmpi(response_type, 'random')
% Parameters for random impulse response
num_taps = input('Enter the number of taps: '); % Number of taps in the channel
delay_spread = input('Enter the maximum delay spread in samples: '); % Maximum delay spread in samples
channel_gain = input('Enter the overall channel gain: '); % Overall channel gain
% Generate random tap delays
tap_delays = randi(delay_spread, 1, num_taps);
% Generate random complex gains for each tap
tap_gains = (rand(1, num_taps) + 1i * rand(1, num_taps)) * channel_gain;
% Generate impulse response
channel_impulse_response = zeros(1, max(tap_delays) + 1);
for i = 1:num_taps
channel_impulse_response(tap_delays(i) + 1) = tap_gains(i);
end
elseif strcmpi(response_type, 'ideal')
% Parameters for near-ideal impulse response
num_taps = 1; % Number of taps in the channel
channel_gain = input('Enter the overall channel gain: '); % Overall channel gain
% Generate impulse response
channel_impulse_response = zeros(1, num_taps);
channel_impulse_response(1) = channel_gain;
else
error('Invalid input. Please enter either "random" or "ideal"');
end
% Plot impulse response
stem(0:length(channel_impulse_response)-1, abs(channel_impulse_response), 'filled');
xlabel('Time (samples)');
ylabel('Magnitude');
if strcmpi(response_type, 'random')
title('Random Channel Impulse Response');
else
title('Near-Ideal Channel Impulse Response');
end
response_type = input('Enter "random" for random channel impulse response or "ideal" for near-ideal impulse response: ', 's');
if strcmpi(response_type, 'random')
% Parameters for random impulse response
num_taps = input('Enter the number of taps: '); % Number of taps in the channel
delay_spread = input('Enter the maximum delay spread in samples: '); % Maximum delay spread in samples
channel_gain = input('Enter the overall channel gain: '); % Overall channel gain
% Generate random tap delays
tap_delays = randi(delay_spread, 1, num_taps);
% Generate random complex gains for each tap
tap_gains = (rand(1, num_taps) + 1i * rand(1, num_taps)) * channel_gain;
% Generate impulse response
channel_impulse_response = zeros(1, max(tap_delays) + 1);
for i = 1:num_taps
channel_impulse_response(tap_delays(i) + 1) = tap_gains(i);
end
elseif strcmpi(response_type, 'ideal')
% Parameters for near-ideal impulse response
num_taps = 1; % Number of taps in the channel
channel_gain = input('Enter the overall channel gain: '); % Overall channel gain
% Generate impulse response
channel_impulse_response = zeros(1, num_taps);
channel_impulse_response(1) = channel_gain;
else
error('Invalid input. Please enter either "random" or "ideal"');
end
% Plot impulse response
stem(0:length(channel_impulse_response)-1, abs(channel_impulse_response), 'filled');
xlabel('Time (samples)');
ylabel('Magnitude');
if strcmpi(response_type, 'random')
title('Random Channel Impulse Response');
else
title('Near-Ideal Channel Impulse Response');
end
Output
Enter "random" for random channel impulse response or "ideal" for near-ideal impulse response: random
Enter the number of taps: 3
Enter the maximum delay spread in samples: 3
Enter the overall channel gain: 0.5
Enter the number of taps: 3
Enter the maximum delay spread in samples: 3
Enter the overall channel gain: 0.5
Fig: Channel Impulse Response (Random Generation)
Enter "random" for random channel impulse response or "ideal" for near-ideal impulse response: ideal
Enter the overall channel gain: 0.8