Getting error in using reshape syntax

조회 수: 1 (최근 30일)
Dipsikha Roy
Dipsikha Roy 2021년 2월 19일
댓글: Walter Roberson 2021년 2월 19일
I have written this code
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);
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')
now I want to change
S2P = reshape(qam_modulated_data, no_of_data_bits/M,M);
I want to pass udata1 as the argument instead of qam_modulated_data
but I am getting error message:
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.
how it can be resolved?
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 2월 19일
how it can be resolved?
I gave an outline towards a solution several weeks ago.
I did not repair the underlying problem in the code: I only fixed the graph to do what you think you want it to do. I did this specifically so that you could see that, in reality, your program is broken and that you have been focusing too long on getting the graph to look just right when really you should be rethinking about the logic of the program and fixing the logic.
The changes needed to fix your program are substantial enough that if we made them for you, you would not be eligible to submit the program for credit.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by