Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Binary array from MATLAB to simulink

184 views
Skip to first unread message

Sohaib Mansoor

unread,
Apr 15, 2009, 12:05:04 PM4/15/09
to
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

Sohaib Mansoor

unread,
Apr 15, 2009, 12:48:01 PM4/15/09
to
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.

Amit Kansal

unread,
Apr 15, 2009, 2:40:13 PM4/15/09
to
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...@gmail.com> wrote in message
news:gs5341$3r5$1...@fred.mathworks.com...

Sohaib Mansoor

unread,
Apr 16, 2009, 1:48:01 AM4/16/09
to
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

amal

unread,
Jan 28, 2015, 10:36:14 AM1/28/15
to
"Sohaib Mansoor" wrote in message <gs6gqh$jrl$1...@fred.mathworks.com>...
> 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

Hello Sohaib,

Maybe, my reply is so late but it can be useful for others.
You can use reschape function,it's faster.

res= reshape(bitsream,1,[])

Good luck
0 new messages