Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab gives error when i increase bits from 42 to 43 ormore

Status
Not open for further replies.

moonnightingale

Full Member level 6
Joined
Sep 17, 2009
Messages
362
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
3,832
Re: Matlab gives error when i increase bits from 42 to 43 or

I have made a code in Matlab. The is regarding modulation scheme.
It ruuns well till the time I set the number of bits to 42.
When i increase number of bits from 42 to 43 or any other value higher than that it gives error
The error is

?? Error using ==> plot
Vectors must be the same lengths.

Error in ==> BaseBandModulator at 23
plot(t1,y) % shift the Nyquist pulse by one T and then plot

Error in ==> d2 at 21
NyquistPulsesData = BaseBandModulator(data,number_of_bits)

What is so special shift from 43 and higher. If any body is willing to help me, kindly give me ur email. i will send u code and u kindly clarify my query.Thanks

Added after 23 minutes:

i AM postiing the code of that function

When i inrease number of bits from 42 to 43 it gives error
Number of bits are defiined in main function


function NyquistPulsesData = BaseBandModulator(data,number_of_bits)
lowLimit = -0.5; %lower limit for time array "t"
upperLimit = 0.5;
T = 0.1;
t = [lowLimit:0.01:upperLimit]; % this time array does not change
tempData = [];
tempTime = [];
for k = 1:1:number_of_bits
t1 = [lowLimit:0.01:upperLimit] % this time array changes at each for loop iteration; both ends of array shift by T
ln = length(t1)
k
if data(k) == 1; % for Binary one generate a Nyquist pulse

y = sinc(t/T);

if k ==1 % If data is binary one & first member in data array
plot(t,y)

tempData = y;
end

if k > 1
********************************************************
plot(t1,y) % shift the Nyquist pulse by one T and then plot
**********************DUE TO THIS ERROR MESSAGE COMES

tempData = [tempData, zeros(1,10)] + [zeros(1,(k-1)*10),y];
%tempData = [tempData,y];
end

grid
hold on
end

if data(k) == 0 % if data element is zero
for m = 1:101
y(m) = 0;
end
if k ==1
plot(t,y)

tempData = y;
end
if k > 1
************************************************************
plot(t1,y)
***********************DUE TO THIS ERROR MESSAGE COMES

tempData = [tempData, zeros(1,10)] + [zeros(1,(k-1)*10),y];
%tempData is sued to find out the resultant of all the pulsese
end

grid
hold on
end

lowLimit = lowLimit + 0.1
upperLimit = upperLimit + 0.1
%ylim([-1.5 1.5]);
end
title('Nyquist Pulses');
grid
NyquistPulsesData = tempData;
time = -0.5:0.01:(0.5 + (number_of_bits -1)*0.1);
%time = tempTime;
% hold off
figure(3)
plot(time,NyquistPulsesData)
title('BASE BAND SIGNAL VS TIME');
grid
ylim([-1.5 1.5]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 

Re: Matlab gives error when i increase bits from 42 to 43 or

Is there anybody who can help me to remove this minor error
IF someone wants to help me ,kindly give me ur email
The problem is very small and error occur due to difference in sizes of array when bits increase more than 42. Otherwise it is ok
 

Re: Matlab gives error when i increase bits from 42 to 43 or

Hi moonnightingale,

I don't agree that this is a very small or a minor error, as you say. An error like this makes useless all your program.

The problem is that when you do this:

lowLimit = lowLimit + 0.1
upperLimit = upperLimit + 0.1

the results are not what you expect because of numerical errors.
See the next piece of code, very similar to yours (you do that with the 2 limits):

x=0;
for k=1:100
x=x+0.1;
end

You would expect that the final value of x is exactly 10, right?
No!
Type "x-10":

x-10

ans =

-1.9540e-014


In fact, 0.1 can not be represented exactly in floating point arithmetic; there are small errors that accumulate over the sums.
At some point, (in your case after 42 or 43 iterations) the vector t1 defined in
t1 = [lowLimit:0.01:upperLimit]
has one less component that should have.

I hope you can fix the problem.
Regards

Z
 

Re: Matlab gives error when i increase bits from 42 to 43 or

LowLimit =

3.6000


upperLimit =

4.6000


t1 =

Columns 1 through 11

3.6000 3.6100 3.6200 3.6300 3.6400 3.6500 3.6600 3.6700 3.6800 3.6900 3.7000

Columns 12 through 22

3.7100 3.7200 3.7300 3.7400 3.7500 3.7600 3.7700 3.7800 3.7900 3.8000 3.8100

Columns 23 through 33

3.8200 3.8300 3.8400 3.8500 3.8600 3.8700 3.8800 3.8900 3.9000 3.9100 3.9200

Columns 34 through 44

3.9300 3.9400 3.9500 3.9600 3.9700 3.9800 3.9900 4.0000 4.0100 4.0200 4.0300

Columns 45 through 55

4.0400 4.0500 4.0600 4.0700 4.0800 4.0900 4.1000 4.1100 4.1200 4.1300 4.1400

Columns 56 through 66

4.1500 4.1600 4.1700 4.1800 4.1900 4.2000 4.2100 4.2200 4.2300 4.2400 4.2500

Columns 67 through 77

4.2600 4.2700 4.2800 4.2900 4.3000 4.3100 4.3200 4.3300 4.3400 4.3500 4.3600

Columns 78 through 88

4.3700 4.3800 4.3900 4.4000 4.4100 4.4200 4.4300 4.4400 4.4500 4.4600 4.4700

Columns 89 through 99

4.4800 4.4900 4.5000 4.5100 4.5200 4.5300 4.5400 4.5500 4.5600 4.5700 4.5800

Columns 100 through 101

4.5900 4.6000

ln =

101


k =

42


**************************************************
BUT WHEN NUMBER OF BITS=K=43 LENGTH BECOMES 100

lowLimit =

3.7000


upperLimit =

4.7000


t1 =

Columns 1 through 11

3.7000 3.7100 3.7200 3.7300 3.7400 3.7500 3.7600 3.7700 3.7800 3.7900 3.8000

Columns 12 through 22

3.8100 3.8200 3.8300 3.8400 3.8500 3.8600 3.8700 3.8800 3.8900 3.9000 3.9100

Columns 23 through 33

3.9200 3.9300 3.9400 3.9500 3.9600 3.9700 3.9800 3.9900 4.0000 4.0100 4.0200

Columns 34 through 44

4.0300 4.0400 4.0500 4.0600 4.0700 4.0800 4.0900 4.1000 4.1100 4.1200 4.1300

Columns 45 through 55

4.1400 4.1500 4.1600 4.1700 4.1800 4.1900 4.2000 4.2100 4.2200 4.2300 4.2400

Columns 56 through 66

4.2500 4.2600 4.2700 4.2800 4.2900 4.3000 4.3100 4.3200 4.3300 4.3400 4.3500

Columns 67 through 77

4.3600 4.3700 4.3800 4.3900 4.4000 4.4100 4.4200 4.4300 4.4400 4.4500 4.4600

Columns 78 through 88

4.4700 4.4800 4.4900 4.5000 4.5100 4.5200 4.5300 4.5400 4.5500 4.5600 4.5700

Columns 89 through 99

4.5800 4.5900 4.6000 4.6100 4.6200 4.6300 4.6400 4.6500 4.6600 4.6700 4.6800

Column 100

4.6900


ln =

100


k =

43

HERE AFTER COULUM 100 THERE SHOULD HAVE BEEN COLUMN 101 THAT MUST BE EQUAL TO 4.70

HOW TO FIX THIS PROBLEM
PLZ PLZHELP ME
 

Dear moonnightingale,

Have you read my former post?
Have you understood id?
Regards

Z
 

Re: Matlab gives error when i increase bits from 42 to 43 or

Yes i read it but i am unable to fix the problem uptill now
 

A "dirty" way, but that requires minimum changes in your code, would be to replace

upperLimit = 0.5;

by

upperLimit = 0.500001;

(Do you understand why?)
This should work, although it is not the best way.
Regards

Z
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top