Phase Modulation and Demodulation Using MATLAB with Code Explanation
1. Introduction
- Overview of phase modulation (PM) as a method of transmitting a message signal.
- Explanation of the key objective: to modulate and demodulate an audio signal using MATLAB.
2. Experimental Setup and Parameters
- Define constants and parameters such as sampling frequency (Fs), carrier frequency (fc), and
modulation index (beta).
- Briefly describe the purpose of each parameter in the modulation and demodulation process.
3. Audio Recording and Preprocessing
- Recording the Audio Signal: Explanation of how MATLAB's audiorecorder function is used to
capture a 20-second audio sample.
- Saving and Loading Audio Data: Storing the recorded audio as a .wav file and reloading it for
processing.
4. MATLAB Code Explanation - Line-by-Line
- Fs = 200000; # Sampling frequency of 200 kHz.
- recObj = audiorecorder(Fs, 16, 1); # Creates an audio recorder with 16-bit resolution and mono
channel.
- disp('Start speaking for 20 seconds.'); # Prompts user to start speaking.
- recordblocking(recObj, 20); # Records audio for 20 seconds.
- disp('End of recording.'); # Signals end of recording.
- messageSignal = getaudiodata(recObj); # Extracts the audio data.
- audiowrite('message_signal.wav', messageSignal, Fs); # Saves the audio as a WAV file.
- disp('Audio saved as message_signal.wav'); # Confirms the audio has been saved.
- [messageSignal, Fs] = audioread('message_signal.wav'); # Loads the saved audio file.
- sound(messageSignal, Fs); # Plays back the recorded audio.
- fc = 50000; # Carrier frequency set to 50 kHz.
- fs = Fs; # Sets the sampling frequency to match the audio file.
- beta = 10; # Modulation index for phase modulation.
- t = (0:length(messageSignal)-1) / fs; # Generates time vector based on message length.
- s = cos(2 * pi * fc * t + beta * messageSignal'); # Generates PM signal by phase-shifting the
carrier.
- analytic_signal = hilbert(s); # Computes the analytic signal using Hilbert transform.
- instantaneous_phase = unwrap(angle(analytic_signal)); # Unwraps the phase to avoid
discontinuities.
- phase_derivative = [0, diff(instantaneous_phase) * fs]; # Differentiates phase for message
recovery.
- phase_derivative_without_carrier = phase_derivative - 2 * pi * fc; # Removes carrier component.
- recovered_message = cumtrapz(t, phase_derivative_without_carrier) / beta; # Integrates to
recover message.
- recovered_message = recovered_message - mean(recovered_message); # Removes DC
component.
- demodulated_signal = recovered_message; # Assigns final demodulated message signal.
5. Visualization of Signals
- Time-Domain Plots: Displays original, modulated, and demodulated signals.
- Frequency-Domain Analysis: FFT of original and modulated signals to examine frequency
components.
6. Adding Noise and Signal Analysis
- Adding AWGN Noise: Simulates real-world noise at 20 dBm and 30 dBm levels.
- Demodulation with Noise: Evaluates how added noise impacts the fidelity of demodulation.
7. Results and Observations
- Compares original and demodulated message signals, showing effectiveness of the method.
- Discusses noise effects, demonstrating robustness or limitations of this PM method in noisy
environments.
8. Conclusion
- Summarizes findings on PM signal recovery and recommendations for noise-handling
improvements.