ask调制matlab实验,ASK调制的matlab代码
記錄一個完整ASK調(diào)制過程的matlab代碼。
%E5_1_AskMod.m
function [ASK2,ASK2_filter,ASK4,ASK4_filter]=E5_1_AskMod(Len,IsPlot,IsOutput)
%產(chǎn)生2ASK、4ASK調(diào)制信號
%Len:碼元長度,默認(rèn)值為1000
%IsPlot:是否繪圖,'1’表示繪圖,否則不繪圖
%IsOutput:是否將ASK調(diào)制數(shù)據(jù)輸出到文本文件中,'1’表示輸出,否則不輸出
%設(shè)置函數(shù)的默認(rèn)參數(shù)值
if nargin < 1
Len=1000; %數(shù)據(jù)長度為1000
IsPlot=0; %不繪圖
IsOutput=0; %不將數(shù)據(jù)寫入文本文件中
end;
Rb=110^6; %碼元速率
Fs=8Rb; %采樣頻率
LenData=LenFs/Rb; %數(shù)據(jù)長度
Fc=7010^6; %載波頻率
Qn=8; %量化位數(shù)
a=0.8; %成形濾波器滾降因子
%產(chǎn)生載波信號
t=0:1/Fs:Len/Rb;
carrier=cos(2piFc*t);
carrier=carrier(1:LenData);
%產(chǎn)生隨機分布的二進制數(shù)據(jù)
%code_2ask=randint(1,Len,2);
code_2ask=(randi(2,Len,1)-1)’;
%對基帶數(shù)據(jù)以Fs速率采樣
code_2ask_upsamp=rectpulse(code_2ask,Fs/Rb);
%對基帶數(shù)據(jù)進行成形濾波,同時進行Fs/Rb倍采樣
code_2ask_filter=rcosflt(code_2ask,1,Fs/Rb);
%產(chǎn)生未進行成形濾波的2ASK信號
ASK2=carrier.*code_2ask_upsamp;
%產(chǎn)生成形濾波后的2ASK信號
ASK2_filter=carrier.*code_2ask_filter(1:LenData)’;
%獲取2ASK信號的頻譜
ASK2_Spec=20log10(abs(fft(ASK2,1024)));
ASK2_Spec=ASK2_Spec-max(ASK2_Spec);
ASK2_filter_Spec=20log10(abs(fft(ASK2_filter,1024)));
ASK2_filter_Spec=ASK2_filter_Spec-max(ASK2_filter_Spec);
%產(chǎn)生隨機分布的四進制數(shù)據(jù)
%code_4ask=randint(1,Len,4);
code_4ask=(randi(4,Len,1)-1)’;
%對基帶數(shù)據(jù)以Fs速率采樣
code_4ask_upsamp=rectpulse(code_4ask,Fs/Rb);
%對基帶數(shù)據(jù)進行成形濾波,同時進行Fs/Rb倍采樣
code_4ask_filter=rcosflt(code_4ask,1,Fs/Rb);
%產(chǎn)生未進行成形濾波的4ASK信號
ASK4=carrier.*code_4ask_upsamp;
%產(chǎn)生成形濾波后的4ASK信號
ASK4_filter=carrier.*code_4ask_filter(1:LenData)’;
%獲取4ASK信號的頻譜
ASK4_Spec=20log10(abs(fft(ASK4,1024)));
ASK4_Spec=ASK4_Spec-max(ASK4_Spec);
ASK4_filter_Spec=20log10(abs(fft(ASK4_filter,1024)));
ASK4_filter_Spec=ASK4_filter_Spec-max(ASK4_filter_Spec);
%繪圖
if IsPlot==1
figure(1);x=0:200;x=x/Fs*(10^6);
subplot(221);plot(x,ASK2(100:300));xlabel(‘時間(us)’);ylabel(‘幅度(v)’);
title(‘未經(jīng)成形濾波的2ASK時域波形’);grid on;
subplot(222);plot((0:200),ASK2_filter(100:300));;xlabel(‘時間(us)’);ylabel(‘幅度(v)’);
title(‘成形濾波后的2ASK時域波形’);grid on;
subplot(223);plot((0:200),ASK4(100:300));;xlabel(‘時間(us)’);ylabel(‘幅度(v)’);
title(‘未經(jīng)成形濾波的4ASK時域波形’);grid on;
subplot(224);plot((0:200),ASK4_filter(100:300));;xlabel(‘時間(us)’);ylabel(‘幅度(v)’);
title(‘成形濾波后的4ASK時域波形’);grid on;
figure(2);x=0:length(ASK2_Spec)-1;x=x/length(x)*Fs/10^6;
subplot(221);plot(x,ASK2_Spec);xlabel('頻率(MHz)');ylabel('幅度(dB)');
title('未經(jīng)成形濾波的2ASK頻譜');grid on;
subplot(222);plot(x,ASK2_filter_Spec);xlabel('頻率(MHz)');ylabel('幅度(dB)');
title('成形濾波后的2ASK頻譜');grid on;
subplot(223);plot(x,ASK4_Spec);xlabel('頻率(MHz)');ylabel('幅度(dB)');
title('未經(jīng)成形濾波的4ASK頻譜');grid on;
subplot(224);plot(x,ASK4_filter_Spec);xlabel('頻率(MHz)');ylabel('幅度(dB)');
title('成形濾波后的4ASK頻譜');grid on;
end;
%量化數(shù)據(jù)并寫入文本文件中
if IsOutput1
norm_Data=ASK2/max(abs(ASK2));%歸一化處理
Q_s=round(norm_Data*(2^(Qn-1)-1));
fid=fopen(‘D:\ModemPrograms\Chapter_5\E5_1_ASKMod\ASK2.txt’,‘w’);
for i=1:length(Q_s)
B_s=dec2bin(Q_s(i)+(Q_s(i)<0)*2^Qn,Qn);
for j=1:Qn
if B_s(j)‘1’
tb=1;
else
tb=0;
end
fprintf(fid,’%d’,tb);
end
fprintf(fid,’\r\n’);
end
fprintf(fid,’;’);
fclose(fid);
norm_Data=ASK2_filter/max(abs(ASK2_filter));%歸一化處理
Q_s=round(norm_Data*(2^(Qn-1)-1));
fid=fopen('D:\ModemPrograms\Chapter_5\E5_1_ASKMod\ASK2_filter.txt','w');
for i=1:length(Q_s)
B_s=dec2bin(Q_s(i)+(Q_s(i)<0)*2^Qn,Qn);
for j=1:Qn
if B_s(j)=='1'
tb=1;
else
tb=0;
end
fprintf(fid,'%d',tb);
end
fprintf(fid,'\r\n');
end
fprintf(fid,';');
fclose(fid);
norm_Data=ASK4/max(abs(ASK4));%歸一化處理
Q_s=round(norm_Data*(2^(Qn-1)-1));
fid=fopen('D:\ModemPrograms\Chapter_5\E5_1_ASKMod\ASK4.txt','w');
for i=1:length(Q_s)
B_s=dec2bin(Q_s(i)+(Q_s(i)<0)*2^Qn,Qn);
for j=1:Qn
if B_s(j)=='1'
tb=1;
else
tb=0;
end
fprintf(fid,'%d',tb);
end
fprintf(fid,'\r\n');
end
fprintf(fid,';');
fclose(fid);
norm_Data=ASK4_filter/max(abs(ASK4_filter));%歸一化處理
Q_s=round(norm_Data*(2^(Qn-1)-1));
fid=fopen('D:\ModemPrograms\Chapter_5\E5_1_ASKMod\ASK4_filter.txt','w');
for i=1:length(Q_s)
B_s=dec2bin(Q_s(i)+(Q_s(i)<0)*2^Qn,Qn);
for j=1:Qn
if B_s(j)=='1'
tb=1;
else
tb=0;
end
fprintf(fid,'%d',tb);
end
fprintf(fid,'\r\n');
end
fprintf(fid,';');
fclose(fid);
end;
總結(jié)
以上是生活随笔為你收集整理的ask调制matlab实验,ASK调制的matlab代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java就应该这样学pdf
- 下一篇: matlab 2ask原理,基于Matl