Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

write a matlab code that performs frequency modulation of a signal and then passes it…

  1. User

    write a matlab code that performs frequency modulation of a signal and then passes it through awgn noise and rygeigh fading channel and then does autocorrelation of both the signals also plot all the curvers by using subplot

  2. Assistant
    % Parameters
    fc = 1000; % Carrier frequency (Hz)
    fm = 100; % Modulation frequency (Hz)
    Fs = 20000; % Sampling frequency (Hz)
    duration = 2; % Signal duration (seconds)
    deviation = 300; % Frequency deviation (Hz)
    
    % Generate time vector
    t = 0:1/Fs:duration;
    
    % Generate message signal (sinusoidal)
    message = sin(2 * pi * fm * t);
    
    % Perform frequency modulation
    modulated = fmmod(message, fc, Fs, deviation);
    
    % Pass the signal through AWGN noise
    snr = 20; % Signal-to-noise ratio (dB)
    noisy_signal = awgn(modulated, snr);
    
    % Pass the signal through Rayleigh fading channel
    rayleigh_channel = comm.RayleighChannel('SampleRate',Fs);
    faded_signal = rayleigh_channel(noisy_signal');
    
    % Calculate autocorrelations
    modulated_autocorr = xcorr(modulated, modulated);
    faded_autocorr = xcorr(faded_signal, faded_signal);
    
    % Plot the signals and autocorrelations
    figure;
    
    subplot(2, 2, 1);
    plot(t, modulated);
    xlabel('Time (s)');
    ylabel('Amplitude');
    title('Frequency Modulated Signal');
    
    subplot(2, 2, 2);
    plot(t, faded_signal);
    xlabel('Time (s)');
    ylabel('Amplitude');
    title('Signal after AWGN noise and Rayleigh fading');
    
    subplot(2, 2, 3);
    plot(modulated_autocorr);
    xlabel('Lag');
    ylabel('Amplitude');
    title('Autocorrelation of the modulated signal');
    
    subplot(2, 2, 4);
    plot(faded_autocorr);
    xlabel('Lag');
    ylabel('Amplitude');
    title('Autocorrelation of the faded signal');