MATLAB EXAMPE RUNS FAILED

When I try to run the exampe: ModulationClassificationWithDeepLearningExample, this error accurs:
"类 'helperModClassFrameStore' 中的属性 'OutputFormat' 的默认值无效:
无法解析名称 FrameStoreOutputFormat.IQAsRows。"
matlab version:2019b
How can I solve this poblem?
Thanks a lot for your answers!

2 Comments

Hi Squirrel,
我建议你把matlab的语言切换成英文,然后把报错信息在英文版块提问,这样会被回复的快一点。
Squirrel
Squirrel on 30 Aug 2020
好的,谢谢您。

Sign in to comment.

 Accepted Answer

刘 檬
刘 檬 on 28 Aug 2020
I had the same problem,but i did`nt find the real reason,i think you write the wrong code or less a line code,you can try this code.
% 使用深度学习进行调制分类 —— CNN训 练部分
% 您将生成合成的、信道减损的波形。使用生成的波形作为训练数据,训练 CNN 进行调制分类。
%
% 目录
% 1 生成用于训练的波形
% 1.1 信道创建
% 1.1.1 AWGN
% 1.1.2 莱斯多径衰落
% 1.1.3 时钟偏移
% 1.1.4 合成后的信道
% 1.2 波形生成
% 2 训练 CNN
% 3 进一步探查
% 4 参考文献
% 5 附录:辅助函数
% 6 附录:调制器
%
%
clear all;
clc;
%% 1 生成用于训练的波形
% 为每种调制类型生成 10000 个帧,其中 80% 用于训练,10% 用于验证,10% 用于测试。我们在网络训练阶段使用训练和验证帧。使用测试帧获得最终分类准确度。每帧的长度为 1024 个样本,采样率为 200 kHz。对于数字调制类型,八个样本表示一个符号。网络根据单个帧而不是多个连续帧(如视频)作出每个决定。假设数字和模拟调制类型的中心频率分别为 900 MHz 和 100 MHz。
% 要快速运行此示例,请使用经过训练的网络并生成少量训练帧。要在计算机上训练网络,请选择 “train network now” 选项(即将 trainNow 设置为true)。
trainNow = false;
if trainNow == true
numFramesPerModType = 100;
else
numFramesPerModType = 100;
end
percentTrainingSamples = 80;
percentValidationSamples = 10;
percentTestSamples = 10;
sps = 8; % Samples per symbol
spf = 1024; % Samples per frame
symbolsPerFrame = spf / sps;
fs = 200e3; % Sample rate
fc = [902e6 100e6]; % Center frequencies
%% 1.1 信道创建
% 让每帧通过信道并具有
% AWGN
% 莱斯多径衰落
% 时钟偏移,导致中心频率偏移和采样时间偏移
% 由于本示例中的网络基于单个帧作出决定,因此每个帧必须通过独立的信道
%% 1.1.1 AWGN
% 添加 SNR 为 30 dB 的 AWGN。由于帧经过归一化,因此噪声标准差可以计算为
SNR = 30;
std = sqrt(10.^(-SNR/10))
% 使用 comm.AWGNChannel 实现
awgnChannel = comm.AWGNChannel(...
'NoiseMethod', 'Signal to noise ratio (SNR)', ...
'SignalPower', 1, ...
'SNR', SNR);
%% 1.1.2 莱斯多径衰落
% 使用 comm.RicianChannel System object 实现通过莱斯多径衰落信道。假设延迟分布为 [0 1.8 3.4] 个样本,对应的平均路径增益为 [0 -2 -10] dB。K 因子为 4,最大多普勒频移为 4 Hz,等效于 900 MHz 的步行速度。使用以下设置实现信道。
multipathChannel = comm.RicianChannel(...
'SampleRate', fs, ...
'PathDelays', [0 1.8 3.4]/fs, ...
'AveragePathGains', [0 -2 -10], ...
'KFactor', 4, ...
'MaximumDopplerShift', 4);
%% 1.1.3 时钟偏移
% .时钟偏移是发送器和接收器的内部时钟源不准确造成的。时钟偏移导致中心频率(用于将信号下变频至基带)和数模转换器采样率不同于理想值。信道仿真器使用时钟偏移因子 C,表示为 C=1+Δclock106,其中 Δclock 是时钟偏移。对于每个帧,通道基于 [−maxΔclock maxΔclock] 范围内一组均匀分布的值生成一个随机 Δclock 值,其中 maxΔclock 是最大时钟偏移。时钟偏移以百万分率 (ppm) 为单位测量。对于本示例,假设最大时钟偏移为 5 ppm。
maxDeltaOff = 5;
deltaOff = (rand()*2*maxDeltaOff) - maxDeltaOff;
C = 1 + (deltaOff/1e6);
% 频率偏移
% 基于时钟偏移因子 C 和中心频率,对每帧进行频率偏移。使用 comm.PhaseFrequencyOffset 实现信道。
offset = -(C-1)*fc(1);
frequencyShifter = comm.PhaseFrequencyOffset(...
'SampleRate', fs, ...
'FrequencyOffset', offset);
% 采样率偏移
% 基于时钟偏移因子 C,对每帧进行采样率偏移。使用 interp1 函数实现通道,以 C×fs 的新速率对帧进行重新采样。
%% 1.1.4 合成后的信道
% 使用 helperModClassTestChannel 对象对帧应用所有三种信道衰落
channel = helperModClassTestChannel(...
'SampleRate', fs, ...
'SNR', SNR, ...
'PathDelays', [0 1.8 3.4] / fs, ...
'AveragePathGains', [0 -2 -10], ...
'KFactor', 4, ...
'MaximumDopplerShift', 4, ...
'MaximumClockOffset', 5, ...
'CenterFrequency', 902e6)
% 您可以使用 info 对象函数查看有关通道的基本信息。
chInfo = info(channel);
%% 1.2 波形生成
% 创建一个循环,它为每种调制类型生成信道衰落的帧,并将这些帧及其对应标签存储在 frameStore 中。从每帧的开头删除随机数量的样本,以去除瞬变并确保帧相对于符号边界具有随机起点。
% Set the random number generator to a known state to be able to regenerate
% the same frames every time the simulation is run
rng(1235)
tic
modulationTypes = categorical(["BPSK", "QPSK", "8PSK", ...
"16QAM", "64QAM", "PAM4", "GFSK", "CPFSK", ...
"B-FM", "DSB-AM", "SSB-AM"]);
numModulationTypes = length(modulationTypes);
channelInfo = info(channel);
frameStore = helperModClassFrameStore(...
numFramesPerModType*numModulationTypes,spf,modulationTypes);
transDelay = 50;
for modType = 1:numModulationTypes
fprintf('%s - Generating %s frames\n', ...
datestr(toc/86400,'HH:MM:SS'), modulationTypes(modType))
numSymbols = (numFramesPerModType / sps);
dataSrc = getSource(modulationTypes(modType), sps, 2*spf, fs);
modulator = getModulator(modulationTypes(modType), sps, fs);
if contains(char(modulationTypes(modType)), {'B-FM','DSB-AM','SSB-AM'})
% Analog modulation types use a center frequency of 100 MHz
channel.CenterFrequency = 100e6;
else
% Digital modulation types use a center frequency of 902 MHz
channel.CenterFrequency = 902e6;
end
for p=1:numFramesPerModType
% Generate random data
x = dataSrc();
% Modulate
y = modulator(x);
% Pass through independent channels
rxSamples = channel(y);
% Remove transients from the beginning, trim to size, and normalize
frame = helperModClassFrameGenerator(rxSamples, spf, spf, transDelay, sps);
% Add to frame store
add(frameStore, frame, modulationTypes(modType));
end
end
% 接下来,将帧分为训练数据、验证数据和测试数据。默认情况下,frameStore 将 I/Q 基带样本按行放置在输出帧中。输出帧的大小为 [2xspf×1×N],其中第一行是同相采样,第二行是正交采样。
[mcfsTraining,mcfsValidation,mcfsTest] = splitData(frameStore,...
[percentTrainingSamples,percentValidationSamples,percentTestSamples]);
[rxTraining,rxTrainingLabel] = get(mcfsTraining);
[rxValidation,rxValidationLabel] = get(mcfsValidation);
[rxTest,rxTestLabel] = get(mcfsTest);
size(rxTraining)
% Plot the amplitude of the real and imaginary parts of the example frames
% against the sample number
plotTimeDomain(rxTest,rxTestLabel,modulationTypes,fs)
% Plot a spectrogram of the example frames
plotSpectrogram(rxTest,rxTestLabel,modulationTypes,fs,sps)
% 通过确保标签(调制类型)分布均匀,避免训练数据中的类不平衡。绘制标签分布图,以检查生成的标签是否分布均匀。
% Plot the label distributions
figure
subplot(3,1,1)
histogram(rxTrainingLabel)
title("Training Label Distribution")
subplot(3,1,2)
histogram(rxValidationLabel)
title("Validation Label Distribution")
subplot(3,1,3)
histogram(rxTestLabel)
title("Test Label Distribution")
%% 2 训练 CNN
% 本示例使用的 CNN 由六个卷积层和一个全连接层组成。除最后一个卷积层外,每个卷积层后面都有一个批量归一化层、修正线性单元 (ReLU) 激活层和最大池化层。在最后一个卷积层中,最大池化层被一个平均池化层取代。输出层具有 softmax 激活。有关网络设计指导原则,请参阅Deep Learning Tips and Tricks。
dropoutRate = 0.5;
numModTypes = numel(modulationTypes);
netWidth = 1;
filterSize = [1 sps];
poolSize = [1 2];
modClassNet = [
imageInputLayer([2 spf 1], 'Normalization', 'none', 'Name', 'Input Layer')
convolution2dLayer(filterSize, 16*netWidth, 'Padding', 'same', 'Name', 'CNN1')
batchNormalizationLayer('Name', 'BN1')
reluLayer('Name', 'ReLU1')
maxPooling2dLayer(poolSize, 'Stride', [1 2], 'Name', 'MaxPool1')
convolution2dLayer(filterSize, 24*netWidth, 'Padding', 'same', 'Name', 'CNN2')
batchNormalizationLayer('Name', 'BN2')
reluLayer('Name', 'ReLU2')
maxPooling2dLayer(poolSize, 'Stride', [1 2], 'Name', 'MaxPool2')
convolution2dLayer(filterSize, 32*netWidth, 'Padding', 'same', 'Name', 'CNN3')
batchNormalizationLayer('Name', 'BN3')
reluLayer('Name', 'ReLU3')
maxPooling2dLayer(poolSize, 'Stride', [1 2], 'Name', 'MaxPool3')
convolution2dLayer(filterSize, 48*netWidth, 'Padding', 'same', 'Name', 'CNN4')
batchNormalizationLayer('Name', 'BN4')
reluLayer('Name', 'ReLU4')
maxPooling2dLayer(poolSize, 'Stride', [1 2], 'Name', 'MaxPool4')
convolution2dLayer(filterSize, 64*netWidth, 'Padding', 'same', 'Name', 'CNN5')
batchNormalizationLayer('Name', 'BN5')
reluLayer('Name', 'ReLU5')
maxPooling2dLayer(poolSize, 'Stride', [1 2], 'Name', 'MaxPool5')
convolution2dLayer(filterSize, 96*netWidth, 'Padding', 'same', 'Name', 'CNN6')
batchNormalizationLayer('Name', 'BN6')
reluLayer('Name', 'ReLU6')
averagePooling2dLayer([1 ceil(spf/32)], 'Name', 'AP1')
fullyConnectedLayer(numModTypes, 'Name', 'FC1')
softmaxLayer('Name', 'SoftMax')
classificationLayer('Name', 'Output') ]
% 接下来配置 TrainingOptionsSGDM 以使用小批量大小为 256 的 SGDM 求解器。将最大轮数设置为 12,因为更多轮数不会提供进一步的训练优势。通过将执行环境设置为 'gpu',在 GPU 上训练网络。将初始学习率设置为 2x10−2。每 9 轮后将学习率降低十分之一。将 'Plots' 设置为“training-progress' 以对训练进度绘图。在 NVIDIA Titan Xp GPU 上,网络需要大约 25 分钟来完成训练。
maxEpochs = 12;
miniBatchSize = 256;
validationFrequency = floor(numel(rxTrainingLabel)/miniBatchSize);
options = trainingOptions('sgdm', ...
'InitialLearnRate',2e-2, ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{rxValidation,rxValidationLabel}, ...
'ValidationFrequency',validationFrequency, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropPeriod', 9, ...
'LearnRateDropFactor', 0.1, ...
'ExecutionEnvironment', 'gpu');
% 或者训练网络,或者使用已经过训练的网络。默认情况下,此示例使用经过训练的网络。
if trainNow == true
fprintf('%s - Training the network\n', datestr(toc/86400,'HH:MM:SS'))
trainedNet = trainNetwork(rxTraining,rxTrainingLabel,modClassNet,options);
else
load trainedModulationClassificationNetwork
end
% 如训练进度图所示,网络在大约 12 轮后收敛于几乎 90% 的准确度。
% 通过获得测试帧的分类准确度来评估经过训练的网络。结果表明,该网络对这组波形实现的准确度达到 95% 左右。
fprintf('%s - Classifying test frames\n', datestr(toc/86400,'HH:MM:SS'))
rxTestPred = classify(trainedNet,rxTest);
testAccuracy = mean(rxTestPred == rxTestLabel);
disp("Test accuracy: " + testAccuracy*100 + "%")
% 绘制测试帧的混淆矩阵。如矩阵所示,网络混淆了 16-QAM 和 64-QAM 帧。此问题是预料之中的,因为每个帧只携带 128 个符号,而 16-QAM 是 64-QAM 的子集。该网络还混淆了 QPSK 和 8-PSK 帧,因为在信道衰落和频率偏移引发相位旋转后,这些调制类型的星座图看起来相似。
figure
cm = confusionchart(rxTestLabel, rxTestPred);
cm.Title = 'Confusion Matrix for Test Data';
cm.RowSummary = 'row-normalized';
cm.Parent.Position = [cm.Parent.Position(1:2) 740 424];
%% 3 进一步探查
% 要提高准确度,可以优化网络参数,例如过滤器数量、过滤器大小;或者优化网络结构,例如添加更多层,使用不同激活层等。
% Communication Toolbox 提供了更多调制类型和信道减损。有关详细信息,请参阅Modulation (Communications Toolbox) 和 部分。您还可以使用 LTE Toolbox、WLAN Toolbox 和 5G Toolbox 添加标准特定信号。您还可以使用 Phased Array System Toolbox 添加雷达信号。
% 附录:“调制器”部分提供用于生成调制信号的 MATLAB 函数。您还可以探查以下函数和 System object 以获得详细信息:
% helperModClassTestChannel.m
% helperModClassFrameGenerator.m
% helperModClassFrameStore.m
% 4 参考文献
% O'Shea, T. J., J. Corgan, and T. C. Clancy. "Convolutional Radio Modulation Recognition Networks." Preprint, submitted June 10, 2016. https://arxiv.org/abs/1602.04105
% O'Shea, T. J., T. Roy, and T. C. Clancy. "Over-the-Air Deep Learning Based Radio Signal Classification." IEEE Journal of Selected Topics in Signal Processing. Vol. 12, Number 1, 2018, pp. 168–179.
% Liu, X., D. Yang, and A. E. Gamal. "Deep Neural Network Architectures for Modulation Classification." Preprint, submitted January 5, 2018. https://arxiv.org/abs/1712.00443v3
%% 5 附录:辅助函数
function modulator = getModulator(modType, sps, fs)
%getModulator Modulation function selector
% MOD = getModulator(TYPE,SPS,FS) returns the modulator function handle
% MOD based on TYPE. SPS is the number of samples per symbol and FS is
% the sample rate.
switch modType
case "BPSK"
modulator = @(x)bpskModulator(x,sps);
case "QPSK"
modulator = @(x)qpskModulator(x,sps);
case "8PSK"
modulator = @(x)psk8Modulator(x,sps);
case "16QAM"
modulator = @(x)qam16Modulator(x,sps);
case "64QAM"
modulator = @(x)qam64Modulator(x,sps);
case "GFSK"
modulator = @(x)gfskModulator(x,sps);
case "CPFSK"
modulator = @(x)cpfskModulator(x,sps);
case "PAM4"
modulator = @(x)pam4Modulator(x,sps);
case "B-FM"
modulator = @(x)bfmModulator(x, fs);
case "DSB-AM"
modulator = @(x)dsbamModulator(x, fs);
case "SSB-AM"
modulator = @(x)ssbamModulator(x, fs);
end
end
function src = getSource(modType, sps, spf, fs)
%getSource Source selector for modulation types
% SRC = getSource(TYPE,SPS,SPF,FS) returns the data source
% for the modulation type TYPE, with the number of samples
% per symbol SPS, the number of samples per frame SPF, and
% the sampling frequency FS.
switch modType
case {"BPSK","GFSK","CPFSK"}
M = 2;
src = @()randi([0 M-1],spf/sps,1);
case {"QPSK","PAM4"}
M = 4;
src = @()randi([0 M-1],spf/sps,1);
case "8PSK"
M = 8;
src = @()randi([0 M-1],spf/sps,1);
case "16QAM"
M = 16;
src = @()randi([0 M-1],spf/sps,1);
case "64QAM"
M = 64;
src = @()randi([0 M-1],spf/sps,1);
case {"B-FM","DSB-AM","SSB-AM"}
src = @()getAudio(spf,fs);
end
end
function x = getAudio(spf,fs)
%getAudio Audio source for analog modulation types
% A = getAudio(SPF,FS) returns the audio source A, with the
% number of samples per frame SPF, and the sample rate FS.
persistent audioSrc audioRC
if isempty(audioSrc)
audioSrc = dsp.AudioFileReader('audio_mix_441.wav',...
'SamplesPerFrame',spf,'PlayCount',inf);
audioRC = dsp.SampleRateConverter('Bandwidth',30e3,...
'InputSampleRate',audioSrc.SampleRate,...
'OutputSampleRate',fs);
[~,decimFactor] = getRateChangeFactors(audioRC);
audioSrc.SamplesPerFrame = ceil(spf / fs * audioSrc.SampleRate / decimFactor) * decimFactor;
end
x = audioRC(audioSrc());
x = x(1:spf,1);
end
function frames = getNNFrames(rx,modType)
%getNNFrames Generate formatted frames for neural networks
% F = getNNFrames(X,MODTYPE) formats the input X, into frames
% that can be used with the neural network designed in this
% example, and returns the frames in the output F.
frames = helperModClassFrameGenerator(rx,1024,1024,32,8);
frameStore = helperModClassFrameStore(10,1024,categorical({modType}));
add(frameStore,frames,modType);
frames = get(frameStore);
end
function plotScores(score,labels)
%plotScores Plot classification scores of frames
% plotScores(SCR,LABELS) plots the classification scores SCR as a stacked
% bar for each frame. SCR is a matrix in which each row is the score for a
% frame.
co = [0.08 0.9 0.49;
0.52 0.95 0.70;
0.36 0.53 0.96;
0.09 0.54 0.67;
0.48 0.99 0.26;
0.95 0.31 0.17;
0.52 0.85 0.95;
0.08 0.72 0.88;
0.12 0.45 0.69;
0.22 0.11 0.49;
0.65 0.54 0.71];
figure; ax = axes('ColorOrder',co,'NextPlot','replacechildren');
bar(ax,[score; nan(2,11)],'stacked'); legend(categories(labels),'Location','best');
xlabel('Frame Number'); ylabel('Score'); title('Classification Scores')
end
function plotTimeDomain(rxTest,rxTestLabel,modulationTypes,fs)
%plotTimeDomain Time domain plots of frames
numRows = ceil(length(modulationTypes) / 4);
spf = size(rxTest,2);
t = 1000*(0:spf-1)/fs;
if size(rxTest,1) == 2
IQAsRows = true;
else
IQAsRows = false;
end
for modType=1:length(modulationTypes)
subplot(numRows, 4, modType);
idxOut = find(rxTestLabel == modulationTypes(modType), 1);
if IQAsRows
rxI = rxTest(1,:,1,idxOut);
rxQ = rxTest(2,:,1,idxOut);
else
rxI = rxTest(1,:,1,idxOut);
rxQ = rxTest(1,:,2,idxOut);
end
plot(t,squeeze(rxI), '-'); grid on; axis equal; axis square
hold on
plot(t,squeeze(rxQ), '-'); grid on; axis equal; axis square
hold off
title(string(modulationTypes(modType)));
xlabel('Time (ms)'); ylabel('Amplitude')
end
end
function plotSpectrogram(rxTest,rxTestLabel,modulationTypes,fs,sps)
%plotSpectrogram Spectrogram of frames
if size(rxTest,1) == 2
IQAsRows = true;
else
IQAsRows = false;
end
numRows = ceil(length(modulationTypes) / 4);
for modType=1:length(modulationTypes)
subplot(numRows, 4, modType);
idxOut = find(rxTestLabel == modulationTypes(modType), 1);
if IQAsRows
rxI = rxTest(1,:,1,idxOut);
rxQ = rxTest(2,:,1,idxOut);
else
rxI = rxTest(1,:,1,idxOut);
rxQ = rxTest(1,:,2,idxOut);
end
rx = squeeze(rxI) + 1i*squeeze(rxQ);
spectrogram(rx,kaiser(sps),0,1024,fs,'centered');
title(string(modulationTypes(modType)));
end
h = gcf; delete(findall(h.Children, 'Type', 'ColorBar'))
end
function flag = isPlutoSDRInstalled
%isPlutoSDRInstalled Check if ADALM-PLUTO Radio HSP is installed
spkg = matlabshared.supportpkg.getInstalled;
flag = ~isempty(spkg) && any(contains({spkg.Name},'ADALM-PLUTO','IgnoreCase',true));
end
function flag = isUSRPInstalled
%isUSRPInstalled Check if USRP Radio HSP is installed
spkg = matlabshared.supportpkg.getInstalled;
flag = ~isempty(spkg) && any(contains({spkg.Name},'USRP','IgnoreCase',true));
end
%% 6 附录:调制器
function y = bpskModulator(x,sps)
%bpskModulator BPSK modulator with pulse shaping
% Y = bpskModulator(X,SPS) BPSK modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 1]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
end
% Modulate
syms = pskmod(x,2);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = qpskModulator(x,sps)
%qpskModulator QPSK modulator with pulse shaping
% Y = qpskModulator(X,SPS) QPSK modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 3]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
end
% Modulate
syms = pskmod(x,4,pi/4);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = psk8Modulator(x,sps)
%psk8Modulator 8-PSK modulator with pulse shaping
% Y = psk8Modulator(X,SPS) 8-PSK modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 7]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
end
% Modulate
syms = pskmod(x,8);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = qam16Modulator(x,sps)
%qam16Modulator 16-QAM modulator with pulse shaping
% Y = qam16Modulator(X,SPS) 16-QAM modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 15]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
end
% Modulate and pulse shape
syms = qammod(x,16,'UnitAveragePower',true);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = qam64Modulator(x,sps)
%qam64Modulator 64-QAM modulator with pulse shaping
% Y = qam64Modulator(X,SPS) 64-QAM modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 63]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
end
% Modulate
syms = qammod(x,64,'UnitAveragePower',true);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = pam4Modulator(x,sps)
%pam4Modulator PAM4 modulator with pulse shaping
% Y = pam4Modulator(X,SPS) PAM4 modulates the input X, and returns the
% root-raised cosine pulse shaped signal Y. X must be a column vector
% of values in the set [0 3]. The root-raised cosine filter has a
% roll-off factor of 0.35 and spans four symbols. The output signal
% Y has unit power.
persistent filterCoeffs amp
if isempty(filterCoeffs)
filterCoeffs = rcosdesign(0.35, 4, sps);
amp = 1 / sqrt(mean(abs(pammod(0:3, 4)).^2));
end
% Modulate
syms = amp * pammod(x,4);
% Pulse shape
y = filter(filterCoeffs, 1, upsample(syms,sps));
end
function y = gfskModulator(x,sps)
%gfskModulator GFSK modulator
% Y = gfskModulator(X,SPS) GFSK modulates the input X and returns the
% signal Y. X must be a column vector of values in the set [0 1]. The
% BT product is 0.35 and the modulation index is 1. The output signal
% Y has unit power.
persistent mod meanM
if isempty(mod)
M = 2;
mod = comm.CPMModulator(...
'ModulationOrder', M, ...
'FrequencyPulse', 'Gaussian', ...
'BandwidthTimeProduct', 0.35, ...
'ModulationIndex', 1, ...
'SamplesPerSymbol', sps);
meanM = mean(0:M-1);
end
% Modulate
y = mod(2*(x-meanM));
end
function y = cpfskModulator(x,sps)
%cpfskModulator CPFSK modulator
% Y = cpfskModulator(X,SPS) CPFSK modulates the input X and returns
% the signal Y. X must be a column vector of values in the set [0 1].
% the modulation index is 0.5. The output signal Y has unit power.
persistent mod meanM
if isempty(mod)
M = 2;
mod = comm.CPFSKModulator(...
'ModulationOrder', M, ...
'ModulationIndex', 0.5, ...
'SamplesPerSymbol', sps);
meanM = mean(0:M-1);
end
% Modulate
y = mod(2*(x-meanM));
end
function y = bfmModulator(x,fs)
%bfmModulator Broadcast FM modulator
% Y = bfmModulator(X,FS) broadcast FM modulates the input X and returns
% the signal Y at the sample rate FS. X must be a column vector of
% audio samples at the sample rate FS. The frequency deviation is 75 kHz
% and the pre-emphasis filter time constant is 75 microseconds.
persistent mod
if isempty(mod)
mod = comm.FMBroadcastModulator(...
'AudioSampleRate', fs, ...
'SampleRate', fs);
end
y = mod(x);
end
function y = dsbamModulator(x,fs)
%dsbamModulator Double sideband AM modulator
% Y = dsbamModulator(X,FS) double sideband AM modulates the input X and
% returns the signal Y at the sample rate FS. X must be a column vector of
% audio samples at the sample rate FS. The IF frequency is 50 kHz.
y = ammod(x,50e3,fs);
end
function y = ssbamModulator(x,fs)
%ssbamModulator Single sideband AM modulator
% Y = ssbamModulator(X,FS) single sideband AM modulates the input X and
% returns the signal Y at the sample rate FS. X must be a column vector of
% audio samples at the sample rate FS. The IF frequency is 50 kHz.
y = ssbmod(x,50e3,fs);
end

2 Comments

Squirrel
Squirrel on 30 Aug 2020
Thanks a lot! I will try later.
刘 檬
刘 檬 on 30 Aug 2020
It's not all code,Source code download you can refer to this: https://download.csdn.net/download/weixin_43935696/12774755

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 10 Jun 2020

Commented:

on 30 Aug 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!