Skip to main content
Home Wireless Communication Modulation MATLAB Beamforming Project Ideas MIMO Computer Networks Lab 🚀

MATLAB Code for Pulse Width Modulation (PWM) and Demodulation

 

 Pulse Width Modulation (PWM)

MATLAB Script

 clc;
clear all;
close all;
fs=5; %frequency of the sawtooth signal
fm=5; %frequency of the message signal
sampling_frequency = 10e3;
a=0.5; % amplitide

t=0:(1/sampling_frequency):1; %sampling rate of 10kHz


sawtooth=1.01*a.*sawtooth(2*pi*fs*t); %generating a sawtooth wave


subplot(4,1,1);
plot(t,sawtooth); % plotting the sawtooth wave
title('Comparator Wave');

msg=a.*sin(2*pi*fm*t); %generating message wave

subplot(4,1,2);
plot(t,msg); %plotting the sine message wave
title('Message Signal');


for i=1:length(sawtooth)
if (msg(i)>=sawtooth(i))
pwm(i)=1; %is message signal amplitude at i th sample is greater than
%sawtooth wave amplitude at i th sample
else
pwm(i)=0;
end
end

subplot(4,1,3);
plot(t,pwm,'r');
title('PWM');
axis([0 1 0 1.1]); %to keep the pwm visible during plotting.

%% Demodulation
% Demodulation: Measure the pulse width to reconstruct the signal
demodulated_signal = zeros(size(msg));

for i = 1:length(pwm)-1
if pwm(i) == 1
% Measure the time until the next falling edge
j = i + 1;
while pwm(j) == 1 && j < length(pwm)
j = j + 1;
end
% Reconstruct the analog value based on pulse width
demodulated_signal(i) = mean(msg(i:j-1));
end
end
% Plot the demodulated signal for comparison
subplot(4,1,4);
plot(t, demodulated_signal);
title('Demodulated Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;

Output 


 Copy the code from here

 

People are good at skipping over material they already know!

View Related Topics to







Admin & Author: Salim

profile

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

Modulation Constellation Diagrams BER vs. SNR BER vs SNR for M-QAM, M-PSK, QPSk, BPSK, ... 1. What is Bit Error Rate (BER)? The abbreviation BER stands for bit error rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. It is defined as,  In mathematics, BER = (number of bits received in error / total number of transmitted bits)  On the other hand, SNR refers to the signal-to-noise power ratio. For ease of calculation, we commonly convert it to dB or decibels.   2. What is Signal the signal-to-noise ratio (SNR)? SNR = signal power/noise power (SNR is a ratio of signal power to noise power) SNR (in dB) = 10*log(signal power / noise power) [base 10] For instance, the SNR for a given communication system is 3dB. So, SNR (in ratio) = 10^{SNR (in dB) / 10} = 2 Therefore, in this instance, the signal power i

Comparisons among ASK, PSK, and FSK | And the definitions of each

Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK Comparison among ASK,  FSK, and PSK Performance Comparison: 1. Noise Sensitivity:    - ASK is the most sensitive to noise due to its reliance on amplitude variations.    - PSK is less sensitive to noise compared to ASK.    - FSK is relatively more robust against noise, making it suitable for noisy environments. 2. Bandwidth Efficiency:    - PSK is the most bandwidth-efficient, requiring less bandwidth than FSK for the same data rate.    - FSK requires wider bandwidth compared to PSK.    - ASK's bandwidth efficiency lies between FSK and PSK. Bandwidth Calculator for ASK, FSK, and PSK The baud rate represents the number of symbols transmitted per second Select Modulation Type: ASK FSK PSK Baud Rate (Hz):

Constellation Diagrams of ASK, PSK, and FSK

Modulation ASK, FSK & PSK Constellation BASK (Binary ASK) Modulation: Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BFSK (Binary FSK) Modulation: Transmits one of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals: +√Eb​ or -√Eb (they differ by 180 degree phase shift), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  This article will primarily discuss constellation diagrams, as well as what constellation diagrams tell us and the significance of constellation diagrams. Constellation diagrams can often demonstrate how the amplitude and phase of signals or symbols differ. These two characteristics lessen the interference between t

What is the Step Size in FFT?

  In FFT (Fast Fourier Transform), the step size refers to the spacing between consecutive points in the input data before performing the transform. It's often determined by the sampling rate of the signal. The step size is crucial for accurate frequency representation, and smaller step sizes provide finer frequency resolution in the resulting frequency domain representation.   Step Size of a Signal in the Time Domain Suppose you have a signal sampled at 1000 Hz (sampling rate) for a duration of 1 second. The step size, or the time difference between consecutive samples, is then given by the inverse of the sampling rate: Step size = 1 Sampling rate = 1 1000   Hz = 0.001   seconds If you perform an FFT on this signal, the resulting frequency resolution in the frequency domain will be determined in part by this step size. Smaller step sizes provide a finer frequency resolution.   Step Size of a Signal in the Frequency / FFT Domain  The term "step size" can have diffe

Coherence Bandwidth and Coherence Time

  Coherence Bandwidth Coherence bandwidth is a concept in wireless communication and signal processing that relates to the frequency range over which a wireless channel remains approximately constant in terms of its characteristics. coherence bandwidth is  The inverse of Doppler spread delay time, or any spread delay time due to fading in general.  The coherence bandwidth is related to the delay spread of the channel, which is a measure of the time it takes for signals to traverse the channel. The two are related by the following formulae: Coherence bandwidth = 1/(delay spread time) Or, Coherence Bandwidth = 1/(root-mean-square delay spread time) (Coherence bandwidth in Hertz) For instance, the coherence bandwidth is 2 MHz when the delay spread is {1/(2*10^6)} = 500 ns in a household indoor environment. For narrowband approximation, Coherence Bandwidth = 1/root-mean-square delay spread time Coherence bandwidth is a measure of the frequency spread over which a wireless communic

RMS Delay Spread, Excess Delay Spread and Multi-path ...

Signal Processing RMS Delay Spread, Excess Delay Spread, and Multipath... RMS Delay Spread, Excess Delay Spread, and Multipath (MPCs) The fundamental distinction between wireless and wired connections is that in wireless connections signal reaches at receiver thru multipath signal propagation rather than directed transmission like co-axial cable. Wireless Communication has no set communication path between the transmitter and the receiver. The line of sight path, also known as the LOS path, is the shortest and most direct communication link between TX and RX. The other communication pathways are called non-line of sight (NLOS) paths. Reflection and refraction of transmitted signals with building walls, foliage, and other objects create NLOS paths. [ Read More about LOS and NLOS Paths] Multipath Components or MPCs: The linear nature of the multipath component signals is evident. This signifies that one multipath component signal is a scalar multiple of

Frequency Bands : EHF, SHF, UHF, VHF, HF, MF, LF, VLF and Their Uses

Frequency Bands EHF, SHF, UHF, VHF, HF, MF, LF... 1. Extremely High Frequency (EHF)30 - 300 GHz Uses 5G Networks 5G millimeter wave band , 6G and beyond (Experimental) RADAR, 2. Super High Frequency (SHF)3 - 30 GHz Uses Ultra-wideband (UWB , Airborne RADAR, Satellite Communication, Microwave Link Communication or SATCOM 3. Ultra High Frequency (UHF)300 - 3000 MHz Uses Satellite Communication, Television, surveillance, navigation aids Also, read important wireless communication terms 4. Very High Frequency (VHF)30 - 300 MHz Uses Television, FM broadcast, navigation aids, air traffic control, 5. High Frequency (HF)3 - 30 MHz Uses Telephone, Telegram and Facsimile, ship to coast, ship to aircraft communication, amateur radio, 6. Medium Frequency (MF)300 - 3000 KHz Uses coast guard communication, direction finding, AM broadcasting , maritime radio, 7. Low Frequency (LF)30 - 300 KHz Uses Radio beacons, Navigational Aids 8. Very Low Frequency (VLF)3 - 30 KHz

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022: Previous Year Question Papers ...   NET | GATE | ESE | UGC-NET (Electronics Science, Subject code: 88 ) UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [December 2024] UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [June 2024] UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [December 2023] UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [June 2023] UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [December 2022]  UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [June 2022]   UGC Net Electronic Science Questions Paper With Answer Key Download Pdf [December 2021] UGC Net Electronic Science Questions With Answer Key Download Pdf [June 2020] UGC Net Electronic Science Questions With Answer Key Download Pdf [December 2019] UGC Net Electronic Science Questions With Answer Key Download Pdf [