I got how to locate my data from the signal in the following link: http://www.mathworks.com/matlabcentral/answers/229678#answer_185935
but how to decompose my data int a matrix. I attached my row data.

2 个评论

Decompose Data int a Matrix? What does that mean?
each column in the matrix has one pulse from the row data in this example i have 8 column.

请先登录,再进行评论。

 采纳的回答

The data you want is when the ‘lowSignal’ vector is equal to 1. If each column in your matrix has one pulse from that record, the separation has already been done. By definition, each column is a pulse, so if your matrix is ‘M’ and it is of size (Nx8), where ‘N’ is the number of rows, to get the first and eighth pulses:
Pulse_1 = M(:,1);
Pulse_8 = M(:,8);

8 个评论

so do i have to use if statement.
if lowSignal==1;
pulse_1=M(:,1);
pulse_2=M(:,2);
end
No if statement is necessary unless you want it. I am simply showing you how to address the individual columns in your matrix.
It is not good to create separate variables (as I did here) for each column. I did that simply to illustrate the effects of addressing them correctly.
See the documentation on Matrix Indexing for details.
I don't know how it is work. it did not work with me. sorry i am new to Matlab. I appreciate your help.
I don’t know what ‘did not work’ means in the context of your code.
Again, please see the documentation on Matrix Indexing for details on how to address your matrix.
load TXDATA.mat
signal = TX(1:1400000);
subplot(3,1,1);
plot(signal);
grid on;
% MAIN CODE IS THE FOLLOWING TWO LINES OF CODE.
% Threshold the signal
lowSignal = abs(signal) < 0.04;
% Remove stretches less than 10,000 elements long.
% And invert it to get the high signal areas instead of the quiet areas.
lowSignal = ~bwareaopen(lowSignal, 10000);
% Now we're done. Plot the results.
subplot(3,1,2);
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;
% Plot both on the same graph now.
subplot(3,1,3);
plot(signal, '-', 'Color', [0,.5,0]);
hold on;
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;
I attached my data file and my code for the signal. I want to have the each pulse in the signal when lowsignal =1, to one colmn in a matrix
Put this at the end of the code you posted above:
ls_idx1 = find(lowSignal);
ls_idx2 = find(~lowSignal);
epk_start = ls_idx1(find(diff([0; ls_idx1]) > 1));
epk_end = ls_idx2(find(diff([0; ls_idx2]) > 1));
time_vct = 1:length(signal);
for k1 = 1:length(epk_start)
sig_mtx(:,k1) = signal(epk_start(k1):epk_end(k1));
tim_mtx(:,k1) = time_vct(epk_start(k1):epk_end(k1));
end
figure(2)
subplot(3,1,1)
plot(tim_mtx(:,1), sig_mtx(:,1))
subplot(3,1,2)
plot(tim_mtx(:,2), sig_mtx(:,2))
subplot(3,1,3)
plot(tim_mtx(:,3), sig_mtx(:,3))
The ‘sig_mtx’ assignment is the matrix of your data with each of the three waveforms as equal-length columns.
I added a time vector and a reference to it in the plots. If you don’t want it or need it, simply remove all the ‘time_vct’ and ‘tim_mtx’ assignments and references.
Dear Strider,
why i got this
Error in threshold (line 33) sig_mtx(:,k1) = signal(epk_start(k1):epk_end(k1));
and thank you again.
I have no idea. My code worked with your data, or I’d not have posted it.
What was the error?

请先登录,再进行评论。

更多回答(1 个)

the error is in this, it said
Subscripted assignment dimension mismatch.
Error in threshold (line 33)
sig_mtx(:,k1) = signal(epk_start(k1):epk_end(k1));

2 个评论

Now it is work thank you so much for you help sir
My pleasure.
That usually means the array sizes between the LHS and RHS of an assignment don’t match. My code assumes all the ‘epochs’ (as I called them) were of equal lengths, since they were the same in the file you provided.
Change the loop to:
for k1 = 1:length(epk_start)
sig_mtx{k1} = signal(epk_start(k1):epk_end(k1));
tim_mtx{k1} = time_vct(epk_start(k1):epk_end(k1));
end
This converts ‘sig_mtx’ and tim_mtx to cell arrays. That should at least solve the current problem. However you will have to program subsequent assignments involving them to accommodate the different lengths, and to change the cell arrays to double arrays in your code. See the documentation on Cell Arrays for details.

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by