You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how to make an array with the constellation point of qam
10 views (last 30 days)
Show older comments
qam_modulated_data = qammod(data_source, M); %where =8
now output will be points. How to insert those point in a array ?
please help me by writing the proper code,
Accepted Answer
More Answers (6)
Walter Roberson
on 28 Nov 2020
qam_modulated_data is already an array.
Perhaps you mean
scatter(real(qam_modulated_data), imag(qam_modulated_data))
14 Comments
Dipsikha Roy
on 29 Nov 2020
Edited: Dipsikha Roy
on 29 Nov 2020
Hi please i need ur more help..please send me 'hi' in my mail id dipsikharoy0@gmail.com Please Its urgent🙏
Walter Roberson
on 29 Nov 2020
Sorry, I am not accepting any additional private contracts at the moment. I am dealing with a significant hardware problem, and I am having a lot of trouble keeping up with my existing obligations.
Dipsikha Roy
on 29 Nov 2020
Ok I hv applied qam modulation on normal function.Got 8 constellation point. Now on those constalletion point i need to apply x(k)=-x(k+n/2) Where n is number of constallation point..in my case it is 8.and k varies 0 to (n/2-1). How i can apply x(k)=-x(k+n/2) If on those constallation point?? If i write x(i)=qammod(x,8) It is saying array element can not b imaginary.if i can not write this how i can apply x(k)=-x(k+n/2)?? Please give me some suggestion.
Dipsikha Roy
on 29 Nov 2020
Walter roberson Thanks a ton Hope u will b avl for any further assistance..🙂
Dipsikha Roy
on 1 Dec 2020
qam_modulated_data = qammod(data_source, M);
scatterplot(qam_modulated_data);title('MODULATED TRANSMITTED DATA');
qam_modulated_data(0:3)=-qam_modulated_data(4:7)
I wrote this as per suggestion.
now i m getting
Array indices must be positive integers or logical values.
Error in s (line 12)
qam_modulated_data(0:3)=-qam_modulated_data(4:7)
how to remove this?
Walter Roberson
on 1 Dec 2020
To remove that error, take the source code for the open source software Octave and modify the way that array indexing works for it, so that you can have a matlab-like language that permits a subscript of 0. But MATLAB itself is not going to gain the ability to index double array with 0 any time in the next few years.
Dipsikha Roy
on 1 Dec 2020
Sir i m new in matlab.please elaborate .what exactly needed to do. If possible give me the changed code please🙏
Dipsikha Roy
on 1 Dec 2020
Edited: Dipsikha Roy
on 1 Dec 2020
Sir please can u give me any idea why output contain 10 data While input contain 8 data.. X(1:4)=-x(5:8) Does it mean x(1)=-x(5), X(2)=-x(6), X(3)=-x(7), X(4)=-x(8)?? Exactly i want to implement this.
Walter Roberson
on 1 Dec 2020
Edited: Walter Roberson
on 1 Dec 2020
X(1:4)=-x(5:8)
means
temporary = x;
X(1) = temporary(5);
X(2) = temporary(6);
X(3) = temporary(7);
X(4) = temporary(8);
The way this differs from
X(1) = x(5);
X(2) = x(6);
X(3) = x(7);
X(4) = x(8);
is that in the syntax
A(indices) = B(other_indices)
includes the possibility that A and B name the same variable and that there is overlap between indices and other_indices. For example,
X(2:5) = X(1:4)
if written out step by step the way you did, might give you the impression that the generated code would be
X(2) = X(1);
X(3) = X(2);
X(4) = X(3);
X(5) = X(4);
but if you look at those steps at code, notice that whatever was originally in X(1) gets copied to X(2), and then what is now in X(2) gets copied to X(3)... so what was originally in X(1) would get copied to X(3) then X(4) then X(5). But that is not what happens: the data source effectively gets copied to a temporary variable, and it the temporary variable that is copied out of, so you are always copying out the old contents, never the content that you just wrote into.
Also I recommend that you use names that are more different than x compared to X, as it is easy to get confused over what is being asked for. Are you wanting to copy from the original data x, or are you wanting to copy from the qammod output ?
Dipsikha Roy
on 1 Dec 2020
Edited: Walter Roberson
on 14 Dec 2020
sir i used this code
M=8
qam_modulated_data = qammod(data_source, M); // it will generate 8 constallention point.so i got 8 input
scatterplot(qam_modulated_data);title('MODULATED TRANSMITTED DATA');// i m plotting
qam_modulated_data(1:4)=-qam_modulated_data(5:8)
here out of that 8 input i m taking 4 input that is
1,2,3,4 th constallation point and then by putting a
minus sign in front of them i m trying to find out
5,6,7 8th element.so that my 5 to 8 th element
should be minus of my 4 input,my total output should
8,but after executing this code i m getting 10 output.
sir please can u help.
Dipsikha Roy
on 1 Dec 2020
Edited: Dipsikha Roy
on 1 Dec 2020
That 8 constallation point i want to arrange like suppose constallation pt means c
then c1,c2,c3,c4,-c1,-c2,-c3,c4 please help sir.
Dipsikha Roy
on 5 Dec 2020
Hi,
clear all
clc
close
M =8; %here we initialize the number of constallation point of qam
no_of_data_points = 128;
data_source= abs(round(randn(1,10)));%here we take random normal function
stem(data_source);
grid on;
xlabel('Data Points');
ylabel('transmitted data phase representation');
title('Transmitted Data') %here we plot that transmitted data
qam_modulated_data = qammod(data_source, M); %here we perform 8bit qam on the random normal function
scatterplot(qam_modulated_data);
title('MODULATED TRANSMITTED DATA'); %here we plot those constallation point
qam_modulated_data1(1:(M/2))=qam_modulated_data(1:(M/2)) %here we introduce another array named qam_modulated_data1 where first four element is first four constallation point
qam_modulated_data1(((M/2)+1):M)=-qam_modulated_data(1:(M/2))% in my qam_modulated_data1 array last four point is hermitian of first four point
y=fft(qam_modulated_data1) %here we apply fast fourier transform on the data of qam_modulated_data1 array
stem(y) %here we plot that fft result
xlabel('frequency');
ylabel('amplitude')
grid on;
title('odd frequency suppressed output')
Walter sir with your help I m able to do this much.But when I run this programme I get transmitted data graph and odd freq suppressed graph but not the scatterplot.Please help me.
3 Comments
Walter Roberson
on 5 Dec 2020
You do not use hold on and you do not use subplot and you do not use figure and you do not use tiled layout. So when you stem(), that is going to automatically erase existing graphics.
Dipsikha Roy
on 5 Dec 2020
clc
close
M =8; %here we initialize the number of constellation point of qam
no_of_data_points = 128;
data_source= abs(round(randn(1,10)));%here we take random normal function
figure(1)
stem(data_source);
grid on;
xlabel('Data Points');
ylabel('transmitted data phase representation');
title('Transmitted Data') %here we plot that transmitted data
qam_modulated_data = qammod(data_source, M) %here we perform 8bit qam on the random normal function
scatterplot(qam_modulated_data)
title('MODULATED TRANSMITTED DATA')%here we plot those constellation point
qam_modulated_data1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
qam_modulated_data1(((M/2)+1):M)=-qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
y=fft(qam_modulated_data1); %here we apply fast Fourier transform on the data of qam_modulated_data1 array
figure(3)
stem(y); %here we plot that fft result
grid on;
xlabel('frequency');
ylabel('amplitude');
title('odd frequency suppressed output');
yc=conj(y);
real_y=y.*yc ;
figure(4)
stem(real_y);
grid on;
xlabel('frequency');
ylabel('amplitude of real values of fft');
title('real value of fft');
sir how to get 4 plot distinguisly?
Walter Roberson
on 15 Dec 2020
"sir how to get 4 plot distinguisly?"
I do not understand the question? You are creating four different figures, and none of the plots looks the same as each other, so as far as I can see they are already distinguishable ?
You could use subplot() or tiledlayout() if you wanted.
Dipsikha Roy
on 14 Dec 2020
walter sir i want to plot above graph but frequency axis should be in mehahertz.which kind of changes in code should be done?please help..
18 Comments
Walter Roberson
on 15 Dec 2020
stem() can take two parameters. Pass the frequency in megahertz as the first parameter. See the first example in the fft() documentation for information on how to calculate the frequency.
Dipsikha Roy
on 15 Dec 2020
If i do scatterplot i get graph like this..what should be done to show line between the constellation point??
Walter Roberson
on 15 Dec 2020
annotation('arrow') possibly? There are File Exchange contributions that make it easier to build the correct coordinates
I have no idea what you intend the arrows to represent.
Dipsikha Roy
on 22 Dec 2020
Edited: Walter Roberson
on 22 Dec 2020
qam_modulated_data = qammod(data_source, M); %here we perform 8bit qam on the random normal function
figure(1);
stem(qam_modulated_data)
title('MODULATED TRANSMITTED DATA');
if i write this code I get graph like
now I want amplitude to be positive,Please give some suggestion.Why amplitude will come in negative?What are the commend to plot constallation points of qam in better way apart from scatterplot?
Walter Roberson
on 22 Dec 2020
qam modulated data is complex valued. It contains components with positive and negative real parts, and components with positive and negative imaginary parts. You should not be using stem() on qam modulated data: stem() is only for real-valued data.
Dipsikha Roy
on 22 Dec 2020
what is the best annotation to show constallation point of 8 bit qam?In scatterplot constallation points are not clear.
Walter Roberson
on 22 Dec 2020
Dipsikha Roy
on 1 Jan 2021
Edited: Walter Roberson
on 31 Jan 2021
clc
close
M =8; %here we initialize the number of constellation point of qam
no_of_data_points = 1024;
fs=10^6;
data_source= abs(round(randn(1,8)));%here we take random normal function
figure(1);
stem(data_source);
grid on;
xlabel('Data Points','Fontsize',14);
ylabel('transmitted data phase representation','Fontsize',14);
title('Transmitted Data','Fontsize',14); %here we plot that transmitted data
qam_modulated_data = qammod(data_source, M,'bin'); %here we perform 8bit qam on the random normal function
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
grid on
for k=1:M
text(real(qam_modulated_data(k))-0.4,imag(qam_modulated_data(k))+0.4,num2str(data(k)));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',14);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:M;
stem(x*(1/fs),abs(y));
grid on;
xlabel('time(microsec)');
ylabel('amplitude of fft');
title('without hermitian ifft','Fontsize',14);
qam_modulated_data1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
qam_modulated_data1(((M/2)+1):M)=-qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
figure(5);
stem(qam_modulated_data1);
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Hermitian symmetry','Fontsize',14);
y1=ifft(qam_modulated_data1); %here we apply fast Fourier transform on the data of qam_modulated_data1 array
figure(6);
x=1:M;
stem(x*(1/fs),abs(y1)); %here we plot that fft result
grid on;
xlabel('time(microsec)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('odd frequency suppressed output','Fontsize',14);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:M;
stem(x*(1/fs),real_y1);
grid on;
xlabel('time(microsec)','Fontsize',14);
ylabel('amplitude of real values of ifft','Fontsize',14);
title('real value of ifft','Fontsize',14);
z=fft(y1);
figure(8);
x=1:M;
stem(x*fs,z); %here we plot that fft result
grid on;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('fft output','Fontsize',14);
qam_modulated_data2(1:(M/2))=z(1:(M/2));
qam_modulated_data2(((M/2)+1):M)=qam_modulated_data(((M/2)+1):M);
figure(9);
stem(qam_modulated_data2);
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('reverse Hermitian symmetry','Fontsize',14);
receieved_data=qamdemod(qam_modulated_data2,M);
figure(10)
x=1:M;
stem(x*(1/fs),receieved_data); %here we plot that fft result
grid on;
xlabel('time(microsec)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('received data','Fontsize',14);
after writing this code I was asked to implement 'Take more number of random data as all the QAM constellation points not appeared.
Third, Now try to form one OFDM symbol say 1 ms long and all the ofdm carriers should be within that one symbol. Like this generate symbol by symbol transmission.'
what change should i do to implement the above highlighted lines?
Dipsikha Roy
on 25 Jan 2021
Hi walter sir,can u please help me by giving matlab code how to add cyclic prefix and remove the same in ofdm?
Dipsikha Roy
on 25 Jan 2021
I have written S2P = reshape(qam_modulated_data, no_of_data_bits/M,M)
Got error
Error using reshape
Number of elements must not change. Use [] as one of the
size inputs to automatically calculate the appropriate
size for that dimension.
Error in rq (line 65)
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M)
what can be done to solve this?
Walter Roberson
on 26 Jan 2021
You did not post your code, so it is difficult to say. I suspect, though, that what you call qam_modulated_data is now not your qam_modulated_data and is instead your data with cyclic prefix, that is no longer the same size as before, and in particular is no longer no_of_data_bits in length.
Dipsikha Roy
on 26 Jan 2021
clc
close
M =8; %here we initialize the number of constellation point of qam
no_of_data_bits=512;
Fm=10^6;%Max freq
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.3 * block_size); %Length of the cyclic prefix
data_source= abs(round(randn(1,8)));%here we take random normal function
figure(1);
x=1:M;
stem (x*(1/Fm),data_source);
grid minor;
xlabel('time(Microsecond)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Transmitted Data','Fontsize',14);%here we plot that transmitted data
qam_modulated_data = qammod(data_source, M);%here we perform 8bit qam on the random normal function
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
grid minor
for k=1:M
text(real(qam_modulated_data(k))-0.4,imag(qam_modulated_data(k))+0.4,num2str(data(k)));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',14);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:M;
stem(x*Fm,abs(y));
grid minor;
xlabel('freq(Mhz)');
ylabel('amplitude of ifft');
title('without hermitian ifft','Fontsize',14);
qam_modulated_data1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
qam_modulated_data1(((M/2)+1):M)=qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
figure(5);
x=1:M;
stem (x*Fm,abs(qam_modulated_data1));
grid minor;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Hermitian symmetry','Fontsize',14);
y1=ifft(qam_modulated_data1); %here we apply fast Fourier transform on the data of qam_modulated_data1 array
figure(6);
x=1:M;
stem(x*Fm,abs(y1)); %here we plot that fft result
grid minor;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('even frequency suppressed output','Fontsize',14);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:M;
stem(x*Fm,real_y1);
grid on;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude of real values of ifft','Fontsize',14);
title('real value of ifft','Fontsize',14);
number_of_subcarriers=8;
cp_start=block_size-cp_len;
for i=1:number_of_subcarriers,
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M)
ifft_Subcarrier(:,i) = ifft((S2P(:,i)),8)% 8 is the ifft point
for j=1:cp_len,
cyclic_prefix(j,i) = ifft_Subcarrier(j+cp_start,i)
end
Append_prefix(:,i) = vertcat( cyclic_prefix(:,i), ifft_Subcarrier(:,i))
% Appends prefix to each subcarriers
end
A1=Append_prefix(:,1);
A2=Append_prefix(:,2);
A3=Append_prefix(:,3);
A4=Append_prefix(:,4);
A5=Append_prefix(:,5);
A6=Append_prefix(:,6);
A7=Append_prefix(:,7);
A8=Append_prefix(:,8);
figure(5), subplot(4,1,1),plot(real(A1),'r'),title('Cyclic prefix added to all the sub-carriers')
subplot(4,1,2),plot(real(A2),'c')
subplot(4,1,3),plot(real(A3),'b')
subplot(4,1,4),plot(real(A4),'g')
subplot(4,1,5),plot(real(A1),'r')
subplot(4,1,6),plot(real(A2),'c')
subplot(4,1,7),plot(real(A3),'b')
subplot(4,1,8),plot(real(A4),'g')
figure(11),plot((real(A1)),'r'),title('Orthogonality'),hold on ,plot((real(A2)),'c'),hold on ,
plot((real(A3)),'b'),hold on ,plot((real(A4)),'g'),hold on ,plot((real(A5)),'r'),hold on,plot((real(A6)),'b'),hold on,plot((real(A7)),'c'),hold on,plot((real(A8)),'g'),hold on,grid on
%Convert to serial stream for transmission,plot((real(A3)),'b'),hold on,
[rows_Append_prefix cols_Append_prefix]=size(Append_prefix)
len_ofdm_data = rows_Append_prefix*cols_Append_prefix
% OFDM signal to be transmitted
ofdm_signal = reshape(Append_prefix, 1, len_ofdm_data);
figure(6),plot(real(ofdm_signal)); xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal');grid on;
%...............................................................
Passing time domain data through channel and AWGN
%.............................................................
channel = randn(1,2) + sqrt(-1)*randn(1,2);
after_channel = filter(channel, 1, ofdm_signal);
awgn_noise = awgn(zeros(1,length(after_channel)),0);
recvd_signal = awgn_noise+after_channel; % With AWGN noise
figure(7),plot(real(recvd_signal)),xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal after passing through channel');grid on;
%...........................................................
now u please help me exactly what to b done to execute this code?
Walter Roberson
on 26 Jan 2021
M =8; %here we initialize the number of constellation point of qam
no_of_data_bits=512;
Fm=10^6;%Max freq
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.3 * block_size); %Length of the cyclic prefix
data_source= abs(round(randn(1,no_of_data_bits)));%here we take random normal function
figure(1);
x=1:no_of_data_bits;
stem (x*(1/Fm),data_source);
grid minor;
xlabel('time(Microsecond)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Transmitted Data','Fontsize',14);%here we plot that transmitted data
qam_modulated_data = qammod(data_source, M);%here we perform 8bit qam on the random normal function
nqdata = length(qam_modulated_data);
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
[udata, uidx] = unique(qam_modulated_data);
nudata = length(udata);
grid minor
for k=1:nudata
text(real(udata(k))-0.4,imag(udata(k))+0.4,num2str(data_source(uidx(k))));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',14);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:nqdata;
stem(x*Fm,abs(y));
grid minor;
xlabel('freq(Mhz)');
ylabel('amplitude of ifft');
title('without hermitian ifft','Fontsize',14);
udata1 = udata;
H = floor(length(udata)/2);
udata1(end-H+1:end) = conj(-udata(1:H)); % in my udata1 array last four point is Hermitian of first four point %CHANGED
figure(5);
x=1:nudata;
stem (x*Fm,abs(udata1));
grid minor;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Hermitian symmetry','Fontsize',14);
y1=ifft(udata1); %here we apply fast Fourier transform on the data of udata1
figure(6);
x=1:nudata;
stem(x*Fm,abs(y1)); %here we plot that fft result
grid minor;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('even frequency suppressed output','Fontsize',14);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:nudata;
stem(x*Fm,real_y1);
grid on;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude of real values of ifft','Fontsize',14);
title('real value of ifft','Fontsize',14);
number_of_subcarriers=8;
assert(number_of_subcarriers <= M);
cp_start=block_size-cp_len;
for i=1:number_of_subcarriers,
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M);
size(S2P)
ifft_Subcarrier(:,i) = ifft((S2P(:,i)),8);% 8 is the ifft point
size(ifft_Subcarrier)
for j=1:cp_len,
cyclic_prefix(j,i) = ifft_Subcarrier(j+cp_start,i);
end
Append_prefix(:,i) = vertcat( cyclic_prefix(:,i), ifft_Subcarrier(:,i))
% Appends prefix to each subcarriers
end
ans = 1×2
64 8
ans = 1×2
8 1
Index in position 1 exceeds array bounds (must not exceed 8).
A1=Append_prefix(:,1);
A2=Append_prefix(:,2);
A3=Append_prefix(:,3);
A4=Append_prefix(:,4);
A5=Append_prefix(:,5);
A6=Append_prefix(:,6);
A7=Append_prefix(:,7);
A8=Append_prefix(:,8);
figure(5), subplot(4,1,1),plot(real(A1),'r'),title('Cyclic prefix added to all the sub-carriers')
subplot(4,1,2),plot(real(A2),'c')
subplot(4,1,3),plot(real(A3),'b')
subplot(4,1,4),plot(real(A4),'g')
subplot(4,1,5),plot(real(A1),'r')
subplot(4,1,6),plot(real(A2),'c')
subplot(4,1,7),plot(real(A3),'b')
subplot(4,1,8),plot(real(A4),'g')
figure(11),plot((real(A1)),'r'),title('Orthogonality'),hold on ,plot((real(A2)),'c'),hold on ,
plot((real(A3)),'b'),hold on ,plot((real(A4)),'g'),hold on ,plot((real(A5)),'r'),hold on,plot((real(A6)),'b'),hold on,plot((real(A7)),'c'),hold on,plot((real(A8)),'g'),hold on,grid on
%Convert to serial stream for transmission,plot((real(A3)),'b'),hold on,
[rows_Append_prefix cols_Append_prefix]=size(Append_prefix)
len_ofdm_data = rows_Append_prefix*cols_Append_prefix
% OFDM signal to be transmitted
ofdm_signal = reshape(Append_prefix, 1, len_ofdm_data);
figure(6),plot(real(ofdm_signal)); xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal');grid on;
%...............................................................
Passing time domain data through channel and AWGN
%.............................................................
channel = randn(1,2) + sqrt(-1)*randn(1,2);
after_channel = filter(channel, 1, ofdm_signal);
awgn_noise = awgn(zeros(1,length(after_channel)),0);
recvd_signal = awgn_noise+after_channel; % With AWGN noise
figure(7),plot(real(recvd_signal)),xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal after passing through channel');grid on;
%...........................................................
Walter Roberson
on 26 Jan 2021
You need to go back through and rework what you are doing. At any one point you need to decide whether you are working with:
- the signal to be transmitted
- the qam modulated version of the signal to be transmitted
- one copy of all M possible unique inputs, for the purpose of plotting showing all of the possible constellation points
- one copy of all the unique used qam modulated data, for the purpose of plotting showing all of the possible used constellation points
- an array for calculating sub-band information
- an OFDM block
What is the relationship (if any) between the number of subcarriers and M ? You set both of them to 8, but if they are certain to be equal then set the number of sub-carriers to M.
What is the relationship between the OFDM block size and anything else? Where are you stuffing data into an OFDM block in order to be able to extract it to build the cyclic prefix? Should you be doing the reshape() with respect to the OFDM block size instead of with respect to M ? If so what happens if the signal length is not a multiple of the OFDM block size?
Dipsikha Roy
on 26 Jan 2021
Edited: Dipsikha Roy
on 26 Jan 2021
clc
close
M =8; %here we initialize the number of constellation point of qam
no_of_data_points = 1024;
Fm=10^6;%Max freq
data_source= abs(round(randn(1,8)));%here we take random normal function
figure(1);
x=1:M;
stem (x*(1/Fm),data_source);
grid minor;
xlabel('time(Microsecond)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Transmitted Data','Fontsize',14);%here we plot that transmitted data
qam_modulated_data = qammod(data_source, M);%here we perform 8bit qam on the random normal function
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
grid minor
for k=1:M
text(real(qam_modulated_data(k))-0.4,imag(qam_modulated_data(k))+0.4,num2str(data(k)));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',14);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:M;
stem(x*Fm,abs(y));
grid minor;
xlabel('freq(Mhz)');
ylabel('amplitude of ifft');
title('without hermitian ifft','Fontsize',14);
qam_modulated_data1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
qam_modulated_data1(((M/2)+1):M)=qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
figure(5);
x=1:M;
stem (x*Fm,abs(qam_modulated_data1));
grid minor;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Hermitian symmetry','Fontsize',14);
y1=ifft(qam_modulated_data1); %here we apply fast Fourier transform on the data of qam_modulated_data1 array
figure(6);
x=1:M;
stem(x*Fm,abs(y1)); %here we plot that ifft result
grid minor;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('even frequency suppressed output','Fontsize',14);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:M;
stem(x*Fm,real_y1);
grid on;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude of real values of ifft','Fontsize',14);
title('real value of ifft','Fontsize',14);
##
z=fft(y1);
figure(8);
x=1:M;
stem(x*Fm,abs(z)); %here we plot that fft result
grid minor;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('fft output','Fontsize',14);
qam_modulated_data2(1:(M/2))=z(1:(M/2));
qam_modulated_data2(((M/2)+1):M)=qam_modulated_data(((M/2)+1):M);
figure(9);
x=1:M;
stem(x*Fm,abs(qam_modulated_data2));
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('reverse Hermitian symmetry','Fontsize',14);
receieved_data=qamdemod(qam_modulated_data2,M);
figure(10)
x=1:M;
stem(x*(1/Fm),receieved_data); %here we plot that fft result
grid minor;
xlabel('time(Microsec)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('received data','Fontsize',14);
here after ifft(In the ## place) i want to perform cyclic prefix then transmit in receiver section removing cyclic prefix and then recover signal.How can i do that?
Walter Roberson
on 26 Jan 2021
You cannot do that in that program.
However if you were to read my earlier comments and compare the version of code I posted to your earlier code, you would be in a better position to modify your program to make it possible to do what you want.
Dipsikha Roy
on 31 Jan 2021
as per ur code that u gave me i got error like
Index in position 1
exceeds array bounds
(must not exceed 8).
Error in Untitled2
(line 74)
cyclic_prefix(j,i) =
ifft_Subcarrier(j+cp_start,i);
what can be done to make it correct?
4 Comments
Walter Roberson
on 31 Jan 2021
You need to go back through and rework what you are doing. At any one point you need to decide whether you are working with:
- the signal to be transmitted
- the qam modulated version of the signal to be transmitted
- one copy of all M possible unique inputs, for the purpose of plotting showing all of the possible constellation points
- one copy of all the unique used qam modulated data, for the purpose of plotting showing all of the possible used constellation points
- an array for calculating sub-band information
- an OFDM block
What is the relationship (if any) between the number of subcarriers and M ? You set both of them to 8, but if they are certain to be equal then set the number of sub-carriers to M.
What is the relationship between the OFDM block size and anything else? Where are you stuffing data into an OFDM block in order to be able to extract it to build the cyclic prefix? Should you be doing the reshape() with respect to the OFDM block size instead of with respect to M ? If so what happens if the signal length is not a multiple of the OFDM block size?
Dipsikha Roy
on 31 Jan 2021
here I took normal function as input,
data_source= abs(round(randn(1,no_of_data_bits)))
this is input line
then 8 bit qam
then took an array of 8 bit lenght where first 4 point are same as first four point of qam constallation point and last 4 bit also same also first 4 point of qam,then perform ifft to suppress even fren,now i want to do cyclic prefixing,where that 8 bit ifft data last 3 or 4 point will be added in the front of ifft block,so my 8 bit ifft block will same as say 12bit ifft block,then I want transmit data through a channel,subcarrier is 8 which is same as M(no of constallation point).I dont understant the utility of reshape,here I am assuming signal length is same as ofdm block size.
Please help me in coding,i am not able to excute it.
Walter Roberson
on 31 Jan 2021
then took an array of 8 bit lenght where first 4 point are same as first four point of qam constallation point and last 4 bit also same
Why did you do that? You throw all of the results of that related code away without using it except to plot. The code reads more like you are required to demonstrate that 8-QAM has a particular relationship between the basic symbols. It does not read like you are calculating anything about your 8-QAM encoded input signal. You are not, for example, removing even frequencies of the 8-QAM version of the input signal, and using that as part of the information you build up into ODFM blocks that you might then apply cyclic prefixes to.
Dipsikha Roy
on 31 Jan 2021
Edited: Dipsikha Roy
on 31 Jan 2021
it is project of clipped ofdm, I want to supress even freq so that my ofdm efficiency increased,that clipped ofdm means even freq clipped ofdm should be added with cyclic prefix just to avoid inter block interference,
if i do "then took an array of 8 bit lenght where first 4 point are same as first four point of qam constallation point and last 4 bit also same" and then perform IFFT on that array then even frequency will be suppressed,that is main key of my project.
Dipsikha Roy
on 9 Feb 2021
Edited: Dipsikha Roy
on 9 Feb 2021
clc;
M =8; %here we initialize the number of constellation point of qam
no_of_data_bits=1024;
Fm=10^6;%Max freq
block_size = 16; %Size of each OFDM block to add cyclic prefix
cp_len = floor(0.1 * block_size); %Length of the cyclic prefix
data_source= abs(round(randn(1,no_of_data_bits)));%here we take random normal function
figure(1);
x=1:no_of_data_bits;
stem (x*(1/Fm),data_source);
grid minor;
xlabel('time(Microsecond)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Transmitted Data','Fontsize',14);%here we plot that transmitted data
qam_modulated_data = qammod(data_source, M);%here we perform 8bit qam on the random normal function
nqdata = length(qam_modulated_data);
data = 0:M-1;
scatterplot(qam_modulated_data,1,0,'r*');
[udata, uidx] = unique(qam_modulated_data);
nudata = length(udata);
grid minor
for k=1:nudata
text(real(udata(k))-0.4,imag(udata(k))+0.4,num2str(data_source(uidx(k))));
end
axis([-4 4 -2 2])
qm = abs(qam_modulated_data);
figure(3);
stem(qm)
title('MODULATED TRANSMITTED DATA','Fontsize',14);%here we plot those constellation point
y=ifft(qam_modulated_data);
figure(4);
x=1:nqdata;
stem(x*Fm,abs(y));
grid minor;
xlabel('freq(Mhz)');
ylabel('amplitude of ifft');
title('without hermitian ifft','Fontsize',14);
data1 = udata;
udata1(1:(M/2))=qam_modulated_data(1:(M/2)); %here we introduce another array named qam_modulated_data1 where first four element is first four constellation point
udata1(((M/2)+1):M)=qam_modulated_data(1:(M/2));% in my qam_modulated_data1 array last four point is Hermitian of first four point
figure(5);
x=1:M;
stem (x*Fm,abs(udata1));
grid minor;
xlabel('frequency(MHZ)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('Hermitian symmetry','Fontsize',14);
y1=ifft(udata1); %here we apply fast Fourier transform on the data of udata1
figure(6);
x=1:M;
stem(x*Fm,abs(y1)); %here we plot that fft result
grid minor;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude','Fontsize',14);
title('even frequency suppressed output','Fontsize',14);
y1c=conj(y1);
real_y1=y1.*y1c ;
figure(7);
x=1:M;
stem(x*Fm,real_y1);
grid on;
xlabel('Freq(Mhz)','Fontsize',14);
ylabel('amplitude of real values of ifft','Fontsize',14);
title('real value of ifft','Fontsize',14);
number_of_subcarriers=M;
assert(number_of_subcarriers <= M);
cp_start=block_size-cp_len;
for i=1:number_of_subcarriers,
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M);
size(S2P)
ifft_Subcarrier(:,i) = ifft((S2P(:,i)),16);% 16 is the ifft point
size(ifft_Subcarrier)
for j=1:cp_len,
cyclic_prefix(j,i) = ifft_Subcarrier(j+cp_start,i);
end
Append_prefix(:,i) = vertcat( cyclic_prefix(:,i), ifft_Subcarrier(:,i))
% Appends prefix to each subcarriers
end
A1=Append_prefix(:,1);
A2=Append_prefix(:,2);
A3=Append_prefix(:,3);
A4=Append_prefix(:,4);
A5=Append_prefix(:,5);
A6=Append_prefix(:,6);
A7=Append_prefix(:,7);
A8=Append_prefix(:,8);
figure(12), subplot(8,1,1),plot(real(A1),'r'),title('Cyclic prefix added to all the sub-carriers')
subplot(8,1,2),plot(real(A2),'y')
subplot(8,1,3),plot(real(A3),'b')
subplot(8,1,4),plot(real(A4),'g')
subplot(8,1,5),plot(real(A5),'m')
subplot(8,1,6),plot(real(A6),'k')
subplot(8,1,7),plot(real(A7),'c')
subplot(8,1,8),plot(real(A8),'g')
figure(11),plot((real(A1)),'r'),title('Orthogonality'),hold on ,plot((real(A2)),'c'),hold on ,
plot((real(A3)),'b'),hold on ,plot((real(A4)),'g'),hold on ,plot((real(A5)),'r'),hold on,plot((real(A6)),'b'),hold on,plot((real(A7)),'c'),hold on,plot((real(A8)),'g'),hold on,grid on
%Convert to serial from parallel
[rows_Append_prefix cols_Append_prefix]=size(Append_prefix)
len_ofdm_data = rows_Append_prefix*cols_Append_prefix
% OFDM signal to be transmitted
ofdm_signal = reshape(Append_prefix, 1, len_ofdm_data);
figure(13),
plot(real(ofdm_signal)); xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal');grid on;
%Serial stream passing through the channel
channel = randn(1,2) + sqrt(-1)*randn(1,2);
after_channel = filter(channel, 1, ofdm_signal);
awgn_noise = awgn(zeros(1,length(after_channel)),0);
recvd_signal = awgn_noise+after_channel; % With AWGN noise
%Converts from serial back to parallel
figure(14),
plot(real(recvd_signal)),xlabel('Time'); ylabel('Amplitude');
title('OFDM Signal after passing through channel');grid on;
recvd_signal_paralleled = reshape(recvd_signal,rows_Append_prefix, cols_Append_prefix);
%now that the signal has passed through the channel we begin to work
%backawards, but we are first going to remove the CP
% Remove cyclic Prefix
%Now that the signal has already passed through the channel, we can get rid
%of the CP
recvd_signal_paralleled(1:cp_len,:)=[];
R1=recvd_signal_paralleled(:,1);
R2=recvd_signal_paralleled(:,2);
R3=recvd_signal_paralleled(:,3);
R4=recvd_signal_paralleled(:,4);
R5=recvd_signal_paralleled(:,5);
R6=recvd_signal_paralleled(:,6);
R7=recvd_signal_paralleled(:,7);
R8=recvd_signal_paralleled(:,8);
figure(15),plot((imag(R1)),'r'),subplot(8,1,1),plot(real(R1),'r'),
title('Cyclic prefix removed from the eight sub-carriers')
subplot(8,1,2),plot(real(R2),'y')
subplot(8,1,3),plot(real(R3),'g')
subplot(8,1,4),plot(real(R4),'b')
subplot(8,1,5),plot(real(R5),'k')
subplot(8,1,6),plot(real(R6),'c')
subplot(8,1,7),plot(real(R7),'m')
subplot(8,1,8),plot(real(R8),'b')
% Fourier Transofrm of the recievied signal
%Similarly to how we took the IFFT of the original signal, as we are back
%tracking we are now taking the FFT
for i=1:number_of_subcarriers,
fft_data(:,i) = fft(recvd_signal_paralleled(:,i),16);
end
F1=fft_data(:,1);
F2=fft_data(:,2);
F3=fft_data(:,3);
F4=fft_data(:,4);
F5=fft_data(:,5);
F6=fft_data(:,6);
F7=fft_data(:,7);
F8=fft_data(:,8);
figure(16), subplot(8,1,1),plot(real(F1),'r'),title('Fourier Transform of all the eight sub-carriers')
subplot(8,1,2),plot(real(F2),'y')
subplot(8,1,3),plot(real(F3),'g')
subplot(8,1,4),plot(real(F4),'b')
subplot(8,1,5),plot(real(F5),'K')
subplot(8,1,6),plot(real(F6),'c')
subplot(8,1,7),plot(real(F7),'m')
subplot(8,1,8),plot(real(F8),'g')
% Conversion to serial and demodulation
%The orignal data was in series, so we are taking the demodulated data
%which is still in parallel form and we are converting back into series to
%hopefully show the same data
recvd_serial_data = reshape(fft_data, 1,(16*8));
qam_demodulated_data = qamdemod(recvd_serial_data,M);
figure(17),
subplot(2,1,1), stem(data_source);
grid on;xlabel('Data Points');ylabel('Amplitude');
title('Original Data')
subplot (2,1,2),
stem(qam_demodulated_data,'bo');
grid on;xlabel('Data Points');ylabel('Amplitude');
title('Recieved Data')
Walter sir I somehow managed to write the code,Now my code has two problem,Channel should be optical fiber channel not wireless channel,at the last I am getting graph like
you can see in received signal and original data graph x axis is not giving same value,in original data x axis is 200,400..and received data x axis is 20,40..so what changes need to be done in the coding so that in both cases x axis should give me same value,please help.
Dipsikha Roy
on 12 Feb 2021
Sir please help me how can I implement rayleigh fading channel here instead of AWGN channel.
Communities
More Answers in the Power Electronics Control
See Also
Categories
Find more on Propagation and Channel Models 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)