problem with qam
9 views (last 30 days)
Show older comments
[EDIT: 20110525 12:21 CDT - reformat - WDR]
hi all,
i have a problem with my code for qam
i getting error on line 37
% Define parameters.
M = 16; % Size of signal constellation
k = log2(M); % Number of bits per symbol
n = 3e4; % Number of bits to process = 30,000
Fd=1;Fs=1; %Input message sampling frequency, output message sampling frequency
nsamp = 1; % Oversampling rate
% Signal Source
% Create a binary data stream as a column vector.
x = randint(n,1); % Random binary data stream
% Plot first 40 bits in a stem plot.
stem(x(1:40),'filled');
title('Random Bits');
xlabel('Bit Index'); ylabel('Binary Value');
% Bit-to-Symbol Mapping
% Convert the bits in x into k-bit symbols.
xsym = bi2de(reshape(x,k,length(x)/k).','left-msb');
% Stem Plot of Symbols
% Plot first 10 symbols in a stem plot.
figure; % Create new figure window.
stem(xsym(1:10));
title('Random Symbols');
xlabel('Symbol Index'); ylabel('Integer Value');
% Modulation
odd=real(xsym);
even=imag(xsym);
A=1;
Ts=1; %dec
fs=200; %Hz
fc=2; %Hz
Df=1/Ts;
A=1; %volt
S=[];
t1=[];
t=0:1/fs:Ts ; %sec
for i=1:n/2 % לולאה שמציגה את כל ה-M
s_t=A*(odd).*(cos(2*pi*fs*t))+(even).*(sin(2*pi*fs*t));
S=[S,s_t];
t1=[t1,t];
t= t( length(t)):1/fs:t(length(t))+Ts ;
end
figure;
plot (t1,S)
xlabel ('t')
ylabel ('Amp[volt]')
xlim ( [0,4*Ts] )
4 Comments
Sarthak Garg
on 5 Apr 2018
Edited: Walter Roberson
on 7 Apr 2018
xsym = bi2de(reshape(x,k,length(x)/k).','left-msb');
this is the error...Can you fix it?
Answers (2)
Walter Roberson
on 25 May 2011
bi2de() cannot produce imaginary numbers, so even = imag(xsym) is going to produce a vector of zeros.
Please recheck your code in this regard.
0 Comments
yossi
on 26 May 2011
1 Comment
Walter Roberson
on 26 May 2011
cos(2*pi*fs*t) with fs a scalar value, will have the same length as t.
odd will have a very different length.
Similar problems exist for even and the sin() expression.
You cannot use .* to multiply matrices of very different lengths.
Perhaps what you want there is
s_t=odd(i).*cos(2*pi*fs*t)+even(i).*sin(2*pi*fs*t);
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!