Is there any Matlab built-in function for 4ASK and 8ASK modulation?
Show older comments
i have found below function but i don't know where to change for 4 and 8Ask.
format long;
% Clear all variables and close all figures
clear all;
close all;
% The number of bits to send - Frame Length
N = 8;
% Generate a random bit stream
bit_stream = round(rand(1,N));
% Enter the two Amplitudes
% Amplitude for 0 bit
A1 = 3;
% Amplitude for 1 bit
A2 = 5;
% Frequency of Modulating Signal
f = 3;
% Sampling rate - This will define the resoultion
fs = 100;
% Time for one bit
t = 0: 1/fs : 1;
% This time variable is just for plot
time = [];
ASK_signal = [];
Digital_signal = [];
for ii = 1: 1: length(bit_stream)
% The FSK Signal
ASK_signal = [ASK_signal (bit_stream(ii)==0)*A1*sin(2*pi*f*t)+...
(bit_stream(ii)==1)*A2*sin(2*pi*f*t)];
% The Original Digital Signal
Digital_signal = [Digital_signal (bit_stream(ii)==0)*...
zeros(1,length(t)) + (bit_stream(ii)==1)*ones(1,length(t))];
time = [time t];
t = t + 1;
end
% Plot the ASK Signal
subplot(2,1,1);
plot(time,ASK_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('ASK Signal with two Amplitudes');
%axis([0 time(end) 1.5 1.5]);
grid on;
% Plot the Original Digital Signal
subplot(2,1,2);
plot(time,Digital_signal,'r','LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('Original Digital Signal');
axis([0 time(end) -0.5 1.5]);
grid on;
Answers (1)
Walter Roberson
on 10 Jun 2021
0 votes
No, there is no built-in function for that. See however the File Exchange https://www.mathworks.com/matlabcentral/fileexchange/47375-ber-of-m-ask-modulation and use different M= values.
16 Comments
Faheem Ur Rehman
on 10 Jun 2021
Walter Roberson
on 10 Jun 2021
Replace
N = 1e6; % total Number of symbols
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = 16; % Number of Symbols
k = log2(M); % Number of bits per Symbol
alphabet = [-(M-1) : 2 : (M-1)];
Eavg = (1/M)*(sum(alphabet.^2)); % average power of transmitted signal
Eb_N0_dB = SNR; % signal to noise ratio
Eb_N0 = 10.^(Eb_N0_dB/10);
Es_N0 = Eb_N0*k; % symbols energy to noise ratio
% M-ASK transmitted signal
St = randsrc(1,N,alphabet);
with
% M-ASK transmitted signal
St = x;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = length(St); % total Number of symbols
M = 16; % Number of Symbols
k = log2(M); % Number of bits per Symbol
alphabet = [-(M-1) : 2 : (M-1)];
Eavg = (1/M)*(sum(alphabet.^2)); % average power of transmitted signal
Eb_N0_dB = SNR; % signal to noise ratio
Eb_N0 = 10.^(Eb_N0_dB/10);
Es_N0 = Eb_N0*k; % symbols energy to noise ratio
Faheem Ur Rehman
on 10 Jun 2021
Walter Roberson
on 10 Jun 2021
That code does not use sampling rate. It assumes that each bit is emitted in consecutive time intervals, but does not define the interval between bits.
If your sampling frequency matches your bit transmission rate, then you need to do is change the time on your graphs.
If your sampling frequency is faster than your bit transmission rate, then resample() the bitstream according to the ratio... and then change the time on your graphs.
Faheem Ur Rehman
on 10 Jun 2021
Walter Roberson
on 12 Jun 2021
fulllength = ceil(length(binary_signal)/spf) * spf;
padsignal = binary_signal;
padsignal(end+1:fulllength) = 0;
buffered_signal = reshape(padsignal, spf, []);
Now take each column of buffered_signal and reshape it to 8 x symbolsPerFrame . Each column should then be encoded into a single 8-ASK symbol, for a total of 128 8-ASK symbols per frame. Now wrap that group of 128 symbols with any error detection or correction or sequence symbols that are appropriate, and logically queue the result for transmission.
You do not change the 8-ASK encoding procedure at all according to the sampling frequency. Instead, the transmission facility should be getting a sequence of (possibly complex) values and taking care of the transmission details. The choice of what values to send is not affected at all by the transmission frequency: the transmission frequency affects how long to send them for.
Faheem Ur Rehman
on 12 Jun 2021
Walter Roberson
on 12 Jun 2021
Convert your audio to a sequence of bits. For example
data = audioread('Filename.wav', 'native')
binary_signal = de2bi(data(:, 1), 8);
Faheem Ur Rehman
on 14 Jun 2021
sps = 8; % Samples per symbol
spf = 1024; % Samples per frame
if mod(spf, sps) ~= 0
error('Samples per frame must be divisible by Samples per symbol');
end
symbolsPerFrame = spf / sps;
fs = 200e3; % Sample rate
data = audioread('audio_mix_441.wav', 'native');
udata = typecast(data(:,1), 'uint8');
binary_signal = reshape(de2bi(udata, 8).', 1, []);
full_length = ceil(length(binary_signal)/spf) * spf;
padsignal = binary_signal;
padsignal(end+1:full_length) = 0;
buffered_signal = reshape(padsignal, spf, []);
St = buffered_signal;
St_by_sample = reshape(St, sps, symbolsPerFrame, []);
symbol_index = reshape(sum(double(St_by_sample) .* 2.^((sps-1:-1:0).'),1), symbolsPerFrame, []) + 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k = sps; % Number of bits per Symbol
M = 2.^k;
alphabet = -(M-1) : 2 : (M-1);
Eavg = (1/M)*(sum(alphabet.^2)); % average power of transmitted signal
St_symbols = alphabet(symbol_index);
St_norm = St_symbols/sqrt(Eavg); % Normalization of transmitted signal power to one
t = (0:symbolsPerFrame-1)/fs;
plot(t, St_norm(:,1:3)); xlabel('time relative to frame'); ylabel('amplitude');
legend("frame " + (1:3))
I think the parts about SNR were just for modeling to see how robust it is.
I would recommend that you add error detection and correction bits to each frame. You would do either by making each frame longer (so 1024 samples plus the number of samples used for detection and correction), or else by making each frame shorter (so that after adding error codes, it came out as 1024 samples).
After the assignment to binary_signal then binary_signal is just a vector of bits. In this particular case it happens to be derived from int16 sound values, 16 bits per sound value, but one binary_signal exists it does not matter how it was created.
sps is not required to be 8. When it is 8, then the effect is that the bytes in udata are decomposed into bits and then later reconstructed into the same bytes (the symbol_index), but it would be valid to go down to (say) sps = 4, which would have the effect of making the transmission more robust.
Faheem Ur Rehman
on 14 Jun 2021
Walter Roberson
on 14 Jun 2021
Set sps to 8 for 8Ask. Set sps to 4 for 4Ask.
Faheem Ur Rehman
on 14 Jun 2021
Edited: Faheem Ur Rehman
on 14 Jun 2021
Walter Roberson
on 14 Jun 2021
john karli
on 21 Jan 2022
Edited: Walter Roberson
on 21 Jan 2022
Hellow Walter
I need your help please.
Can you add the above ASK modulation code in the following function of MATLAB?
Walter Roberson
on 21 Jan 2022
As I read through the example, it looks to me as if it would be do-able to edit in support for ASK as well.
However, this is not something that I have time to do myself at present.
Categories
Find more on Modulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!