%Pwm调制 matlab代码,绘制符号集和功率谱
%Pwm调制 matlab代码
fs = 2e6;
msgLen=8;
x = randi([0 200], msgLen, 1)/256;
period_Base=1;
period_Fs=50;
if 1
% [x_map,t_out]=modulate(x,period_Base,period_Fs,'ppm');
[x_map,t_out]=modulate(x,period_Base,period_Fs,'pwm');
N_symbol=length(x_map);
else
M=16;
N_symbol=100;
x_sym=randi([0 M-1], 1,N_symbol);
x_map=qammod(x_sym,M);
end
Nsample=2;
rate_symbol=fs/Nsample;
if 1
wave_intp=rectpulse(x_map,Nsample)*0; % 改用这种插值,成型后还是幅度1
wave_intp(1:Nsample:Nsample*N_symbol)=x_map;
else
wave_intp=rectpulse(x_map,Nsample); % 全插值 成型后的幅度是十倍,谱也是10倍
end
rolloff=0.9;
delay=8;%.没有一定的标准
coef= rcosine(rate_symbol,fs,'fir/normal',rolloff,delay);
if 1
wave_LPF=filter(coef,1, wave_intp); % 用这个 不变长
else
[wave_LPF,t_LPF]=rcosflt(x_map,rate_symbol,fs,'filter',coef);
end
y=wave_LPF;
% y=wave_intp; % 必须要成型,不然谱是乱的
Nfft=2048;
Pxx_lin=fftshift(fft(y,Nfft));
Pxx_dB=abs(10*log10((Pxx_lin+1)));
figure
Spec=Pxx_dB;
% Spec=abs(Pxx_lin);
Len= length(Spec) ; %总的谱长度就是NFFT
% f1=(0:Len-1)*df;
df=fs/Nfft;
f1=(0:Len*1-1)*df-fs/2;
plot(f1,Spec(1:length(f1)));
xlabel('frequency');
title('功率谱')
grid on
figure
subplot(311)
plot(x_map,'-')
ylim([-0.1 1.1])
title('调制符号')
grid on
subplot(312)
plot(wave_intp,'-')
ylim([-0.1 1.1])
title('内插符号')
subplot(313)
plot(wave_LPF)
ylim([-0.1 1.1])
title('成型波形')