Thread Subject: Binary array from MATLAB to simulink

Subject: Binary array from MATLAB to simulink

From: Sohaib Mansoor

Date: 15 Apr, 2009 16:05:04

Message: 1 of 4

Note: I am using MATLAB r2008a

I am working on a project on Adaptive Video Coding for wireless channels.
So far I have an encoded bitstream similar to the one below (but more than 800,000 bits long):

>>bitstr =

11010100000101000100000000010101000000010100010001001
>>

Now I am trying to modulate it in Simulink using QPSK and import the result back into MATLAB. The problem I am facing is importing 'bitstr' into simulink, I have tried to use the 'From Workspace' block (simin) but it gives the following error:

"Invalid matrix-format variable specified as workspace input in 'untitled/From Workspace'. The matrix must have two dimensions and at least to columns......."

How can I fix this error, is there any other way to import the bitstr into simulink? I am not very good in simulink, so I need a good explanation to understand how it works.

Thanks

Subject: Binary array from MATLAB to simulink

From: Sohaib Mansoor

Date: 15 Apr, 2009 16:48:01

Message: 2 of 4

Here's another related question:
Why is bitstr like this:
bitstr=[1010100101010101001111000]
instead of this:
bitstr=[1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0]

is it because I use dec2bin to get the bit stream.

Subject: Binary array from MATLAB to simulink

From: Amit Kansal

Date: 15 Apr, 2009 18:40:13

Message: 3 of 4

Hi Sohaib,

    Yes, since you are using dec2bin the output is a string of bits which is
not usable by the From Workspace block.
The block only works with decimals/doubles.

Try using de2bi if you have the comms toolbox also or a element by element
conversion on the string using str2num.

As an example,
>>bits = de2bi(200, 'left-msb')
and now use "bits" as the variable in the From workspace block.

or

>>bitstr = dec2bin(200);
>>for i=1:length(bitstr)
>> bits2(i) = str2num(bitstr(i));
>>end
and now use "bits2" as the variable in the From workspace block.

>>isequal(bits, bits2)

hth,
Amit

"Sohaib Mansoor" <contact.sohaib@gmail.com> wrote in message
news:gs5341$3r5$1@fred.mathworks.com...
> Here's another related question:
> Why is bitstr like this:
> bitstr=[1010100101010101001111000]
> instead of this:
> bitstr=[1 0 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0]
>
> is it because I use dec2bin to get the bit stream.

Subject: Binary array from MATLAB to simulink

From: Sohaib Mansoor

Date: 16 Apr, 2009 05:48:01

Message: 4 of 4

Thanks Amit;

the for loop is working well, but I have one little problem. Its taking too much time because the size of the string is more than 800,000 bits. Is there any way the same operation can be done but without the loops, to save time?

Sohaib

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
binary Sohaib Mansoor 15 Apr, 2009 12:10:19
array Sohaib Mansoor 15 Apr, 2009 12:10:19
import simulink Sohaib Mansoor 15 Apr, 2009 12:10:19
simulink Sohaib Mansoor 15 Apr, 2009 12:10:19
qpsk Sohaib Mansoor 15 Apr, 2009 12:10:19
video Sohaib Mansoor 15 Apr, 2009 12:10:19
bits Sohaib Mansoor 15 Apr, 2009 12:10:19
rssFeed for this Thread

Contact us at files@mathworks.com