PPM Modulator
古いコメントを表示
Hi, Please how can I build a PPM modulator in simulink. The block is not available in my matlab. i am using 2008b
5 件のコメント
Fangjun Jiang
2011 年 12 月 19 日
What is PPM?
Walter Roberson
2011 年 12 月 19 日
Pulse Position Modulation
ska109
2016 年 2 月 13 日
I've made it working somehow...
Yashwanth
2026 年 10 月 28 日 2:59
ppm full code
clc;
clear all;
close all;
% Binary PPM
fs = 100;
dt = 1/fs;
t1 = 0:dt:1-dt;
t2 = 1:dt:2-dt;
t = [t1 t2];
% PPM signals
s1 = [ones(1,length(t1)), zeros(1,length(t2))];
s2 = [zeros(1,length(t1)), ones(1,length(t2))];
% Plot transmitted signals
figure;
subplot(2,1,1);
plot(t,s1);
title('PPM Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t,s2);
title('PPM Signal 0');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Energy and first basis function
e1 = sum(s1.^2)*dt;
psi1 = s1/sqrt(e1);
% Second basis function using orthogonalization
s21 = sum(s2.*psi1)*dt;
d2 = s2-s21*psi1;
ed2 = sum(d2.^2)*dt;
psi2 = d2/sqrt(ed2);
% Plot basis functions
figure;
subplot(2,1,1);
plot(t,psi1);
title('Basis Function 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t,psi2);
title('Basis Function 2');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Signal-space coordinates
s_11 = sum(s1.*psi1)*dt;
s_21 = sum(s2.*psi1)*dt;
s_12 = sum(s1.*psi2)*dt;
s_22 = sum(s2.*psi2)*dt;
figure;
stem([s_11 s_21],[s_12 s_22],'filled');
title('PPM Signal Space Representation');
xlabel('Coordinate 1');
ylabel('Coordinate 2');
grid on;
% AWGN with variances 0, 0.1, 1 and 2
n1 = sqrt(0)*randn(size(s1));
n2 = sqrt(0.1)*randn(size(s1));
n3 = sqrt(1)*randn(size(s1));
n4 = sqrt(2)*randn(size(s1));
% Received signals
r1 = s1+n1;
r2 = s1+n2;
r3 = s1+n3;
r4 = s1+n4;
r5 = s2+n1;
r6 = s2+n2;
r7 = s2+n3;
r8 = s2+n4;
% Plot received signals
figure;
subplot(4,2,1);
plot(t,r1);
title('Signal 1: Variance 0');
grid on;
subplot(4,2,2);
plot(t,r5);
title('Signal 0: Variance 0');
grid on;
subplot(4,2,3);
plot(t,r2);
title('Signal 1: Variance 0.1');
grid on;
subplot(4,2,4);
plot(t,r6);
title('Signal 0: Variance 0.1');
grid on;
subplot(4,2,5);
plot(t,r3);
title('Signal 1: Variance 1');
grid on;
subplot(4,2,6);
plot(t,r7);
title('Signal 0: Variance 1');
grid on;
subplot(4,2,7);
plot(t,r4);
title('Signal 1: Variance 2');
grid on;
subplot(4,2,8);
plot(t,r8);
title('Signal 0: Variance 2');
grid on;
% Correlation receiver
R = [r1; r2; r3; r4; r5; r6; r7; r8];
X = zeros(8,2);
for i = 1:8
X(i,1) = sum(R(i,:).*psi1)*dt;
X(i,2) = sum(R(i,:).*psi2)*dt;
end
% Plot signal-space coordinates for each variance
figure;
subplot(2,2,1);
stem(X([1 5],1),X([1 5],2),'filled');
title('Signal Space: Variance 0');
grid on;
subplot(2,2,2);
stem(X([2 6],1),X([2 6],2),'filled');
title('Signal Space: Variance 0.1');
grid on;
subplot(2,2,3);
stem(X([3 7],1),X([3 7],2),'filled');
title('Signal Space: Variance 1');
grid on;
subplot(2,2,4);
stem(X([4 8],1),X([4 8],2),'filled');
title('Signal Space: Variance 2');
grid on;
% Matched-filter impulse responses
h1 = fliplr(psi1);
h2 = fliplr(psi2);
% Matched-filter outputs for both basis functions
Y1 = zeros(8, length(t)+length(h1)-1);
Y2 = zeros(8, length(t)+length(h2)-1);
for i = 1:8
Y1(i,:) = conv(R(i,:),h1)*dt;
Y2(i,:) = conv(R(i,:),h2)*dt;
end
ty = 0:dt:2*(length(t)-1)*dt;
% Plot the matched-filter outputs
figure;
subplot(2,2,1);
plot(ty,Y1(1,:));
hold on;
plot(ty,Y1(5,:));
title('Matched Filter: Variance 0');
xlabel('Time (s)');
ylabel('Output');
legend('Signal 1','Signal 0');
grid on;
subplot(2,2,2);
plot(ty,Y1(2,:));
hold on;
plot(ty,Y1(6,:));
title('Matched Filter: Variance 0.1');
xlabel('Time (s)');
ylabel('Output');
legend('Signal 1','Signal 0');
grid on;
subplot(2,2,3);
plot(ty,Y1(3,:));
hold on;
plot(ty,Y1(7,:));
title('Matched Filter: Variance 1');
xlabel('Time (s)');
ylabel('Output');
legend('Signal 1','Signal 0');
grid on;
subplot(2,2,4);
plot(ty,Y1(4,:));
hold on;
plot(ty,Y1(8,:));
title('Matched Filter: Variance 2');
xlabel('Time (s)');
ylabel('Output');
legend('Signal 1','Signal 0');
grid on;
% Display correlation coordinates
disp('Rows: r1 through r8');
disp('Columns: basis function 1 and basis function 2');
disp(X);
Yashwanth
2026 年 10 月 28 日 3:00
PAM
clc;
clear all;
close all;
% BINARY PAM MODULATION AND DEMODULATION
fs = 100;
dt = 1/fs;
t = 0:dt:1;
% Binary PAM signals
s1 = ones(1,length(t));
s2 = -1*ones(1,length(t));
% Plotting signals
figure;
subplot(2,1,1);
plot(t,s1);
title('Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t,s2);
title('Signal 0');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Energy and basis function
e1 = sum(s1.*s1)*dt;
psi1 = s1/sqrt(e1);
figure;
subplot(2,1,1);
plot(t,psi1);
title('Basis Function 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Signal space representation
s_11 = sum(s1.*psi1)*dt;
s_21 = sum(s2.*psi1)*dt;
subplot(2,1,2);
stem([s_11 s_21],[0 0],'filled');
title('Signal Space Representation');
xlabel('Signal Coordinate');
ylabel('Amplitude');
grid on;
% AWGN with different variances
n1 = sqrt(0)*randn(size(s1));
n2 = sqrt(0.1)*randn(size(s1));
n3 = sqrt(1)*randn(size(s1));
n4 = sqrt(2)*randn(size(s1));
% Received signals
r1 = s1+n1;
r2 = s1+n2;
r3 = s1+n3;
r4 = s1+n4;
r5 = s2+n1;
r6 = s2+n2;
r7 = s2+n3;
r8 = s2+n4;
% Plot received signals
figure;
subplot(4,2,1);
plot(t,r1);
title('Signal 1: Noise Variance 0');
grid on;
subplot(4,2,2);
plot(t,r5);
title('Signal 0: Noise Variance 0');
grid on;
subplot(4,2,3);
plot(t,r2);
title('Signal 1: Noise Variance 0.1');
grid on;
subplot(4,2,4);
plot(t,r6);
title('Signal 0: Noise Variance 0.1');
grid on;
subplot(4,2,5);
plot(t,r3);
title('Signal 1: Noise Variance 1');
grid on;
subplot(4,2,6);
plot(t,r7);
title('Signal 0: Noise Variance 1');
grid on;
subplot(4,2,7);
plot(t,r4);
title('Signal 1: Noise Variance 2');
grid on;
subplot(4,2,8);
plot(t,r8);
title('Signal 0: Noise Variance 2');
grid on;
% CORRELATION RECEIVER
x1 = sum(r1.*psi1)*dt;
x2 = sum(r2.*psi1)*dt;
x3 = sum(r3.*psi1)*dt;
x4 = sum(r4.*psi1)*dt;
x5 = sum(r5.*psi1)*dt;
x6 = sum(r6.*psi1)*dt;
x7 = sum(r7.*psi1)*dt;
x8 = sum(r8.*psi1)*dt;
% Correlator output plots
figure;
subplot(2,2,1);
stem([x1 x5],[0 0],'filled');
title('Correlation: Variance 0');
grid on;
subplot(2,2,2);
stem([x2 x6],[0 0],'filled');
title('Correlation: Variance 0.1');
grid on;
subplot(2,2,3);
stem([x3 x7],[0 0],'filled');
title('Correlation: Variance 1');
grid on;
subplot(2,2,4);
stem([x4 x8],[0 0],'filled');
title('Correlation: Variance 2');
grid on;
% MATCHED FILTER
h = fliplr(psi1);
figure;
plot(t,h);
title('Matched Filter Impulse Response');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Convolution outputs
y1 = conv(r1,h)*dt;
y2 = conv(r2,h)*dt;
y3 = conv(r3,h)*dt;
y4 = conv(r4,h)*dt;
y5 = conv(r5,h)*dt;
y6 = conv(r6,h)*dt;
y7 = conv(r7,h)*dt;
y8 = conv(r8,h)*dt;
% Convolution time axis
ty = 0:dt:2;
% Plot matched filter outputs
figure;
subplot(2,2,1);
plot(ty,y1);
hold on;
plot(ty,y5);
title('Matched Filter: Variance 0');
legend('Signal 1','Signal 0');
xlabel('Time (s)');
ylabel('Output');
grid on;
subplot(2,2,2);
plot(ty,y2);
hold on;
plot(ty,y6);
title('Matched Filter: Variance 0.1');
legend('Signal 1','Signal 0');
xlabel('Time (s)');
ylabel('Output');
grid on;
subplot(2,2,3);
plot(ty,y3);
hold on;
plot(ty,y7);
title('Matched Filter: Variance 1');
legend('Signal 1','Signal 0');
xlabel('Time (s)');
ylabel('Output');
grid on;
subplot(2,2,4);
plot(ty,y4);
hold on;
plot(ty,y8);
title('Matched Filter: Variance 2');
legend('Signal 1','Signal 0');
xlabel('Time (s)');
ylabel('Output');
grid on;
% Demodulation decision using correlator outputs
corr_out = [x1 x2 x3 x4; x5 x6 x7 x8];
disp('Correlation outputs:');
disp(corr_out);
disp('Decision: positive = Signal 1, negative = Signal 0');
disp(sign(corr_out));
採用された回答
その他の回答 (3 件)
dave
2011 年 12 月 19 日
0 投票
1 件のコメント
KURUVA LAKSHMI
2026 年 10 月 28 日 16:57
clc;
clear;
close all;
phase = input('Enter system type (1 for single phase, 3 for three phase): ');
Vr = input('Enter receiving end voltage (kV): ');
pf = input('Enter load power factor: ');
type = input('Enter 1 for lagging or 2 for leading power factor: ');
R = input('Enter resistance per phase per km (ohm/km): ');
l = input('Enter line length (km): ');
choice = input('Enter 1 if reactance is given, 2 if inductance is given: ');
if choice == 1
X = input('Enter reactance per phase per km (ohm/km): ');
Xtotal = X * l;
elseif choice == 2
L = input('Enter inductance per phase per km (mH/km): ');
f = input('Enter frequency (Hz): ');
L = L / 1000;
X = 2 * pi * f * L;
Xtotal = X * l;
else
error('Invalid choice. Enter 1 or 2.');
end
Rtotal = R * l;
Z = Rtotal + 1i * Xtotal;
phi = acos(pf);
if type == 1
angleI = -phi;
elseif type == 2
angleI = phi;
else
error('Invalid power factor type. Enter 1 for lagging or 2 for leading.');
end
if phase == 1
S = input('Enter apparent power (kVA): ');
Vr_ph = Vr * 1000;
Ir = (S * 1000) / Vr_ph;
Ir_phasor = Ir * exp(1i * angleI);
Vs_phasor = Vr_ph + Ir_phasor * Z;
Vs = abs(Vs_phasor);
Pout = S * 1000 * pf;
Ploss = Ir^2 * Rtotal;
efficiency = (Pout / (Pout + Ploss)) * 100;
regulation = ((Vs - Vr_ph) / Vr_ph) * 100;
fprintf('\n--- SINGLE PHASE RESULTS ---\n');
fprintf('Total resistance = %.4f ohm\n', Rtotal);
fprintf('Total reactance = %.4f ohm\n', Xtotal);
fprintf('Line impedance = %.4f + j%.4f ohm\n', Rtotal, Xtotal);
fprintf('Receiving end current = %.4f A\n', Ir);
fprintf('Sending end voltage = %.4f kV\n', Vs / 1000);
fprintf('Voltage regulation = %.4f %%\n', regulation);
fprintf('Line loss = %.4f kW\n', Ploss / 1000);
fprintf('Efficiency = %.4f %%\n', efficiency);
elseif phase == 3
P = input('Enter real power (kW): ');
Vr_line = Vr * 1000;
Ir = (P * 1000) / (sqrt(3) * Vr_line * pf);
Ir_phasor = Ir * exp(1i * angleI);
Vr_ph = Vr_line / sqrt(3);
Vs_phasor = Vr_ph + Ir_phasor * Z;
Vs_line = sqrt(3) * abs(Vs_phasor);
Pout = P * 1000;
Ploss = 3 * Ir^2 * Rtotal;
efficiency = (Pout / (Pout + Ploss)) * 100;
regulation = ((Vs_line - Vr_line) / Vr_line) * 100;
fprintf('\n--- THREE PHASE RESULTS ---\n');
fprintf('Total resistance = %.4f ohm/phase\n', Rtotal);
fprintf('Total reactance = %.4f ohm/phase\n', Xtotal);
fprintf('Line impedance = %.4f + j%.4f ohm/phase\n', Rtotal, Xtotal);
fprintf('Receiving end current = %.4f A\n', Ir);
fprintf('Sending end line voltage = %.4f kV\n', Vs_line / 1000);
fprintf('Voltage regulation = %.4f %%\n', regulation);
fprintf('Line loss = %.4f kW\n', Ploss / 1000);
fprintf('Efficiency = %.4f %%\n', efficiency);
else
error('Invalid system type. Enter 1 for single phase or 3 for three phase.');
end
sivasena reddy
2019 年 5 月 8 日
clc;
close all;
clear all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
pwm(i)=1;
elseif (m(i)<=s(i))
pwm(i)=0;
end
end
plot(t,pwm,'g',t,m,'r',t,s,'--b');
ylabel('Amplitude');
axis([0 1 -1.5 1.5]);
xlabel('Time index');
title('PWM Wave');
grid on;
1 件のコメント
Walter Roberson
2019 年 5 月 8 日
The user had requested Simulink implementation, though.
Also, you appear to be doing PWM (Pulse Width Modification) rather than PPM (Pulse Position Modification)
Atul Kumar
2021 年 3 月 21 日
clc;
close all;
clear all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
if (m(i)>=s(i))
pwm(i)=1;
elseif (m(i)<=s(i))
pwm(i)=0;
end
end
plot(t,pwm,'g',t,m,'r',t,s,'--b');
ylabel('Amplitude');
axis([0 1 -1.5 1.5]);
xlabel('Time index');
title('PWM Wave');
grid on;
1 件のコメント
Walter Roberson
2021 年 3 月 21 日
How does this differ from https://www.mathworks.com/matlabcentral/answers/24247-ppm-modulator#answer_374142 other than the spacing?
カテゴリ
ヘルプ センター および File Exchange で Matched Filter and Ambiguity Function についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!