11-24-2008 11:13 PM
Greetings,
I am kind of confused on binary data processing from labview to matlab. I tried to follow this thread by C. Minnella:
http://forums.ni.com/ni/board/message?board.id=170&message.id=211371&query.id=131675#M211371
And it was a great help for me to understand many of my issues. However there is something wrong with data that I am writting and retrieving in Matlab
Here is how signal looks in Labview
http://img126.imageshack.us/my.php?image=picture1va4.png
And its spectrum
http://img126.imageshack.us/my.php?image=picture3hn6.png
http://img146.imageshack.us/my.php?image=picture4br6.png
And this is what I am getting in Matlab:
http://img357.imageshack.us/my.php?image=picture7jq7.jpg
my vi:
http://img146.imageshack.us/my.php?image=picture2wn0.png
The only change I did was replacing DAQ task with Global chanel constant, since it has original scaling for the data from Load Cell (Fx Axis in particular), this is the device I am getting data from, it is in rest, sitting on the table.
I can't figureout what is happening, looks like it is clipped, besides the amplitude is not correct.
Would really appreciate any insights,
Oleks
11-24-2008 11:29 PM
Find one bug,
Data type was i32 and should have 4 bytes per sample instead of 2, that I had originally. However frequency differs by factor of 10 and amplitude is still not as one that I see in Labview. I am out of ideas
11-25-2008 01:21 AM
How do you read your data in Matlab?
LabVIEW stores data little endian, and Matlab (on an Intel processor) reads data Big endian.
If you do a read in Matlab, you can adjust the endianess with a switche ',b' or ',B' (I'm not sure which).
Ton
11-25-2008 12:40 PM
Hello Ton,
Thank you for the fast reply, here is a part of the code that reads from Labview data file:
%Read header information, return in a structure
[headerInfo,fileMark] = GetHeader(fileName,pathName, dataBytes);
%Open binary file Big endian format
fid=fopen([pathName fileName],'rb','ieee-be');
%Move file marker to begining of scans
fseek(fid,fileMark+startScan,'bof');
%Read number of requested scans
y=fread(fid,headerInfo.NumChannels*scans,dataType);
%Reshape data into a matrix [scans x channels]
y=reshape(y,headerInfo.NumChannels,[])';
%Close binary file
fclose(fid);
I basically followed example posted in 2006 on NI forum. I think my major concern is whether data is getting to matlab scaled correctly (it is scaled within global channel to Newtons) and looks like I am not getting the same data type in Matlab.
11-25-2008 12:54 PM
TonP wrote:How do you read your data in Matlab?
LabVIEW stores data little endian, and Matlab (on an Intel processor) reads data Big endian.
If you do a read in Matlab, you can adjust the endianess with a switche ',b' or ',B' (I'm not sure which).
Ton
good catch TonP, never would have thought to look at the endianess