Thread Subject: code representation

Subject: code representation

From: ahmed

Date: 21 May, 2008 16:32:02

Message: 1 of 5

hi
if i have a signal (look like a sawtooth)i want to take
the maximum values in this vector and from them to
construct a binary code which represent this signal. can
one tell me how to do this.

Subject: code representation

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 May, 2008 17:10:37

Message: 2 of 5

In article <g11iq2$rak$1@fred.mathworks.com>,
Ahmed <mogwari2000@yahoo.com> wrote:

>if i have a signal (look like a sawtooth)i want to take
>the maximum values in this vector and from them to
>construct a binary code which represent this signal. can
>one tell me how to do this.


One way:

binarycode = (abs(signal - max(signal)) < tolerance);

for an appropriately chosen tolerance to take into account that
there might be a small bit of round-off in the calculation of
the signal value at peaks.

The result is a single-bit local vector that is 1 at peaks and
0 elsewhere.


Other binary codes:

sigmin = min(signal);
sigmax = max(signal);
bits = 3;
binarycode = bin2dec( ceil(eps + 2^bits * (signal - sigmin) / (sigmax - sigmin)) - 1, bits);

The result is an array, length(signal) x bits, of characters that are
'0' or '1'. A number of people refer to this text representation of
binary as a "binary stream" -- which I don't think is sufficiently
correct, but using the phrase does give you an idea of what kind of
output there would be.

Each row would represent one sample point, and if one were to
interpret the number in that row as binary, it would be which
quartile or octile or hexadectile (or whatever the name is according
to the number of bits you choose) the signal at that point was of
the maximum signal range. For example, '000' would indicate that
the sample was in the bottom 1/8th of the signal range, and '110' would
indicate that the sample was in the second-from-the-top 8'th of
the signal range.

This is effectively a quantization of the signal into binary,
and if you keep the signal minimum and maximum values, then
you can use these values to recreate the signal to any desired
binary degree of accuracy (by using more bits.) With the binary codes
in hand, you could also run compression algorithms if you had some
reason to do so.


But this is just speculation: your question is not at all
descriptive of what kind of "binary codes" you want to
construct to represent the signal. Like, are you looking for
the signal to be represented by spokesbits, or is the signal
looking for a good two-bit shyster to negotiate "appearance" fees,
or is the signal looking for a good tax accountant because when
it comes to tax dodges, every little bit helps?
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block

Subject: code representation

From: ahmed

Date: 21 May, 2008 21:49:03

Message: 3 of 5

thanks for guide and help.

i well try to implement the second way.

i notice in the place of bin2dec i well use dec2bin is it
right?

is it possible to implement it to a matrix in the place of
a vector.

if i like to go a head way and to make a compression to
the resultant array . can you give an idea.


Subject: code representation

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 May, 2008 22:37:48

Message: 4 of 5

In article <g125cf$5mh$1@fred.mathworks.com>,
Ahmed <mogwari2000@yahoo.com> wrote:

>i well try to implement the second way.

>i notice in the place of bin2dec i well use dec2bin is it
>right?

Ah yes, I did get that flipped around.


>is it possible to implement it to a matrix in the place of
>a vector.

Yes, but the output of bin2dec will still end up being
a character vector whose number of columns (width) is the same as
the number of bits. The result is the same as if you had converted
the matrix to a vector:

bin2dec(somematrix,3) is the same as bin2dec(somematrix(:),3)


>if i like to go a head way and to make a compression to
>the resultant array . can you give an idea.

Well, if I were planning compression, then I would not use
exactly the approach I outlined. You indicated that you have
a saw-tooth type wave, which hints that is not particularily
discontinuous. If you take the difference between successive samples
using diff() then especially if you have sampled at a much higher
frequency than the sawtooth frequency, the differences in
the percentile (or whatever) of successive samples will tend to
be small. You can histogram the changes to get counts for each
difference, and thus probabilities of each difference. Probabilitie
in hand, you can built a variable-length representation, such as using
the well-known Huffman algorithm. Then just run through the difference
array, outputting the variable-length code corresponding to the
difference, and the output will be a compressed string representation
of the signal. Then by knowing the signal maximum and minimum
and the resolution of the encoding, and the variable-length
encoding table, the process could be reversed.

That is, if what you are looking for is to have some fun and
learn something building a signal compressor. If you were applying
this to real signals that you had a lot of, then more complex
predictive methods and more compact encodings might become important
in order to achieve the maximum compression while still maintaining
key signal properties. For example with EKG signals, the main signals
are relatively predictable, but preserving the shapes of oddities in
the signal can be *very* important: smoothing out an EKG signal
to remove some inconvenient bumps is *not* acceptable. But there are
a lot of other signal types where a random spike is mostly just noise
to be removed; you use differenc compressions for those cases than for EKG.

--
'Roberson' is my family name; my given name is 'Walter'.

Subject: code representation

From: ahmed

Date: 12 Jun, 2008 22:56:02

Message: 5 of 5


if i have signal like this
a =
[0.0003,0.0103,0.0108,0.0113,0.0148,0.0188,0.0180,0.0186,0.
0195,0.0176,0.0189,0.0189,0.0198,0.0197,0.0204,0.0192,0.020
1,0.0193,
    
0.0184,0.0201,0.0212,0.0309,0.0442,0.0447,0.0479,0.0337,0.0
426,0.0500,0.0481,0.0488,0.0481,0.0491,0.0391,0.0479,0.0577
,0.0552,
    
0.0563,0.0590,0.0622,0.0581,0.0610,0.0541,0.0293,0.0307,0.0
448,0.0519,0.0784,0.1600,0.1951,0.1914,0.2036,0.1865,0.0719
,0.0434,
    
0.0543,0.0485,0.0435,0.0462,0.0506,0.0568,0.0646,0.0687,0.0
761,0.0788,0.0457,0.0417,0.0290,0.0326,0.0711,0.0938,0.1112
,0.0715,
    
0.0526,0.0472,0.0437,0.0558,0.0627,0.0639,.0717,0.0716,0.07
38,0.0628,0.0495,0.0450,0.0361,0.0340,0.0378,0.0372,0.0350,
0.0364,0.0361,0.0403,0.0958,
    
0.0861,0.0308,0.0270,0.0320,0.0278,0.0271,0.0287,0.0254,0.0
257,0.0260,0.0270,0.0288,0.0283,0.0262,0.0257,0.0341,0.0449
,0.0877,0.0790,0.0112,0.0094,0.0094,0.0094,0.0074,
    
0.0099,0.0108,0.0099,0.0100,0.0094,0.0081,0.0081,0.0069,0.0
067,0.0061,0.0029]

you can plot it to see the shape: plot(a);

i like to take just into account the extreme points (peaks
and valleys) in this signal,
i dont like to consider ripples points in the signal

how can i do that?

Tags for this Thread

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com