user will give bits code will give fsk,psk,ask in matlab

To generate FSK (Frequency Shift Keying), PSK (Phase Shift Keying), and ASK (Amplitude Shift Keying) signals in MATLAB based on a given bit code, you can use the following code:

main.m
bits = input('Enter the bit code: '); % Prompt the user to enter the bit code

% FSK modulation parameters
fsk_freq1 = 1000; % Frequency for bit '0'
fsk_freq2 = 2000; % Frequency for bit '1'
fsk_duration = 0.1; % Duration of each bit

% PSK modulation parameters
psk_phase0 = 0; % Phase for bit '0'
psk_phase1 = pi; % Phase for bit '1'
psk_duration = 0.1; % Duration of each bit

% ASK modulation parameters
ask_amp0 = 0; % Amplitude for bit '0'
ask_amp1 = 1; % Amplitude for bit '1'
ask_duration = 0.1; % Duration of each bit

% Initialize the arrays for storing the generated signals
fsk_signal = [];
psk_signal = [];
ask_signal = [];

% Generate the FSK, PSK, and ASK signals based on the input bit code
for i = 1:length(bits)
    % FSK modulation
    if bits(i) == '0'
        fsk_bit = sin(2*pi*fsk_freq1*(0:1/1000:fsk_duration));
    elseif bits(i) == '1'
        fsk_bit = sin(2*pi*fsk_freq2*(0:1/1000:fsk_duration));
    else
        disp('Invalid bit code.'); % Display an error message for invalid input
        return;
    end
    fsk_signal = [fsk_signal, fsk_bit];
    
    % PSK modulation
    if bits(i) == '0'
        psk_bit = sin(psk_phase0 + 2*pi*(0:1/1000:psk_duration));
    elseif bits(i) == '1'
        psk_bit = sin(psk_phase1 + 2*pi*(0:1/1000:psk_duration));
    else
        disp('Invalid bit code.'); % Display an error message for invalid input
        return;
    end
    psk_signal = [psk_signal, psk_bit];
    
    % ASK modulation
    if bits(i) == '0'
        ask_bit = ask_amp0 .* ones(1001,1);
    elseif bits(i) == '1'
        ask_bit = ask_amp1 .* ones(1001,1);
    else
        disp('Invalid bit code.'); % Display an error message for invalid input
        return;
    end
    ask_signal = [ask_signal, ask_bit];
end

% Plot the generated FSK, PSK, and ASK signals
t = (0:length(fsk_signal)-1)/1000;
subplot(3,1,1);
plot(t, fsk_signal);
title('FSK Signal');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(3,1,2);
plot(t, psk_signal);
title('PSK Signal');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(3,1,3);
plot(t, ask_signal);
title('ASK Signal');
xlabel('Time (s)');
ylabel('Amplitude');
2138 chars
78 lines

In this code, the user will be prompted to enter the bit code. The code then generates FSK, PSK, and ASK signals based on the input bit code. The modulation parameters for each signal type are defined (frequency, phase, and amplitude for '0' and '1'). The signals are generated iteratively for each bit using a for loop and stored in arrays. Finally, the generated signals are plotted using subplot.

related categories

gistlibby LogSnag