I have added 2 different MATLAB files where "receive_cdm.m" is my main code and "y_send.mat" is a file I am getting some values from it and loaded it in main code section.
If you look at the code then I have assigned 1 parameter c1. Forget about other parameters.
The following tasks are explained in the code.
I have done it with proper MATLAB commands and equations.
But, I am getting error when I calculate it manually and matching it with MATLAB calculations. (What I should get and what I am getting from MATLAB)
Can anyone check my code, please..?
It would be very helpful for me.

12 commentaires

KSSV
KSSV le 5 Jan 2021
You should specify your error.
Noman Abir
Noman Abir le 5 Jan 2021
Can you help me to find error and solve the error..?
I am trying from last 3 days to find the errors and couldn't find it.
I will be very helpful if you help me.
Rik
Rik le 5 Jan 2021
What KSSV means is that you should post the error message.
Noman Abir
Noman Abir le 5 Jan 2021
Ok. I have attached 3 screenshots result files here.
I want to multiply "data1" with "c1" row to row and bit to bit values.
I am using this code for this : "result = bsxfun(@times, c1, data1);
As all the values are "1" in c1.
So, the result values should be as "data1".
But, here you can see the result value in "result" image.
Noman Abir
Noman Abir le 5 Jan 2021
If you run the code on step by step (description given on the code that what should be the value after calculation or what type of values should be).
If you check my code then you will understand easily what i am saying.
There is no error when I run your code. Moreover: the result of bsxfun is exactly as expected:
S=load('y_send.mat');y_send=S.y_send;
c1 = [ 1 1 1 1 ];
%row to row and bit to bit multiplication of y_send and c1.
demultiplex_data_y1 = bsxfun(@times, c1, y_send);
isequal(demultiplex_data_y1, y_send)
ans = logical
1
Noman Abir
Noman Abir le 5 Jan 2021
I am not saying that the code is error. I am saying that the calculation is error. Suppose, you want to calculate 2+2 and you know that the output value should be 4. You gave the input to MATLAB as : A = 2 B = 2 C = A+B But, the value of C shown as ''C = 5'' in MATLAB. There is no error in code but error in calculation. Look at the first row values in "y_send". If you multiply it with " c1" bit to bit then the result should come as equal as "y_send" (as all the values of c1 is 1). But, if you compare the value of "y_send" with the output value (after row to row and bit to bit multiplication) then you will see that the values are different. I hope you got my point.
Rik
Rik le 5 Jan 2021
Modifié(e) : Rik le 5 Jan 2021
That is actually what that last line of code does: it checks if demultiplex_data_y1 and y_send are equal. They are, just as expected. The screenshots you posted look like you were just shifted by 1 row when you made the screenshot.
You need to be careful with your wording: the word 'bit' has a specific meaning: a one or a zero as stored in the actual computer memory. The multiplication times is doing doesn't multiply bit by bit, but element by element, i.e. each value in the array (each of which is encoded with 64 bits as a float64, since the values are stored as a double).
I just confirmed on R2011a that the result of the code I posted is indeed true.
Noman Abir
Noman Abir le 5 Jan 2021
Yes. That is element to element multiplication in every row to row with c1.
There are another two value of c2 and c3 where the values are mixed with +1 and -1.
So, I should get a proper multiplication value after doing the multiplication element to element.
Since, c2 and c3 are mixed with +1 and -1 so i am not going to get exact value everytime as y_send.
I hope you got my point.
And, read my comment on every step in the code. Run and get result from every steps. You will see that the values are coming from MATLAB should not be if you calculate them on calculator or own.
I just need a corrected code where I am getting values on every step correctly.
Which exact line doesn't return the expected value? You have not convinced me that there is anything wrong. Don't refer back to your code, put code in a comment instead. So far, the relevant parts of the code reduce down to the 3 lines in my comment, which don't show your problem.
To go back to your example, show code like this:
A=2;B=2;
C=A+B %should display 4, but does it?
C = 4
if C==4,disp('Everything fine.'),else,disp('There is a severe issue with Matlab! Even plus() doesn''t work correctly!'),end
Everything fine.
Before we can attempt to fix a problem we first need to make sure there is one and figure out what it is exactly.
Noman Abir
Noman Abir le 5 Jan 2021
Modifié(e) : Rik le 5 Jan 2021
clc;
clear all;
close all;
load('y_send.mat');
y_send;
bit = 4;
levels = 16;
Fs = 44100;
len = length(y_send);
t = 0:1/Fs:(len-1)/Fs;
max_x = 1;
min_x = -1;
step=(max_x-min_x)/levels;
c1 = [ 1 -1 1 -1 ];
demultiplex_data_y1 = bsxfun(@times, c1, y_send);
demultiplex_data_y1
adding_rows_y1 = sum(demultiplex_data_y1, 2);
adding_rows_y1
convert_binary_y1 = (sign(adding_rows_y1)+1)/2;
convert_binary_y1
reshape_binary_y1 = reshape(convert_binary_y1,4,[]).';
num_to_string_y1 = num2str(reshape_binary_y1);
binary_to_decimal_y1 = bin2dec(num_to_string_y1);
binary_to_decimal_y1
reconstructing_samples_y1 = min_x+(step*binary_to_decimal_y1)+step/2;
reconstructing_samples_y1
audiowrite('audiofile1 cdm.wav', reconstructing_samples_y1, Fs);
Ok. So here is my full code.
Now, I have got a data set from "y_send''.
  1. To get "demultiplex_data_y1" I have to multiply y_send*c1 row to row and element to element.
  2. To get "adding_rows_y1" we have to sum all the row values got from "demultiplex_data_y1".
  3. To get "convert_binary_y1" we have to convert all the values (values got from "adding_rows_y1") to binary values.
  4. To get "binary_to_decimal_y1" we have to take every 4 values got from "convert_binary_y1" and make it decimal. For example we got [0 0 1 0 0 0 1 1 and so on] from "convert_binary_y1" and we have to make first 4 values in a string then second 4 values in a string and so on (like "0010'', "0011") and lastly making those values into decimal as [2, 3].
  5. Then just use the equation to get "reconstructing_samples_y1".
  6. Lastly, you will get a hearable audio file from "audiowrite('audiofile1 cdm.wav', reconstructing_samples_y1, Fs);" section. If you can't hear the audio then calculations are not correct.
To ensure your calculation just check every step values that what values should I get and what values i am getting from MATLAB.
Rik
Rik le 5 Jan 2021
Are you determined to not get help? You aren't proving anything with your current code. The only thing we know and agree on is that your code applied on your data doesn't return the audio you are expecting. You have not proven why your code should work, or even that your input data is correct.
To ensure your calculation just check every step values that what values should I get and what values i am getting from MATLAB.
No, that is what you need to do. At which step are you getting values that are different from your manual calculations? There are three options:
  1. Matlab has a bug in times that only you just uncovered (despite this being a core function since the first alpha Cleve Moler wrote and probably being tested extensively with regression tests on every new release)
  2. Your data (which is coming from an anonymous undocumented .mat file) is not the exact type and shape your code expects
  3. Your code (which is reasonably documented, but silent on what kind of data it expects and lacks any form of input validation) has incorrect assumptions
Which of these sounds more probable to you?
Unless and until you show me the line of code that diverges from your expectation, I do not expect there is any problem with Matlab.

Connectez-vous pour commenter.

 Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Jan 2021
Modifié(e) : KALYAN ACHARJYA le 5 Jan 2021

0 votes

Here, I provided the answer based on following
"I want to multiply "data1" with "c1" row to row and bit to bit values.
I am using this code for this : "result = bsxfun(@times, c1, data1);
As all the values are "1" in c1.
So, the result values should be as "data1"."
The code
demultiplex_data_y1=bsxfun(@times, c1, y_send);
Here c1
c1 =
1 1 1 1
And y_send
>> whos y_send
Name Size Bytes Class Attributes
y_send 1200000x4 38400000 double
bsxfun @times do the .*Array multiply with to two arrays with implicit expansion enabled. When you do the array operation with any element with "1" you suppose to get the same result, right. Hence in the following code, y_send and demultiplex_data_y1 must be same, because c1 having with all "1" elements
demultiplex_data_y1=bsxfun(@times, c1, y_send);
If you comapare the two array, you should be get the true "1" logic
>> isequal(demultiplex_data_y1,y_send)
ans =
logical
1
If I misunderstood this question, let me know, if I can help you it would be great for me

7 commentaires

Noman Abir
Noman Abir le 5 Jan 2021
Yes. you are right. But, I have another two values of c (c1, c2) and I have to do the same operation with y_send.
Here, c2 and c3 are mixed of +1 and -1 values and I have to multiply them element to element.
Also, I have to do the next operations correctly.
Please open my code file. You will see what to do on every step comment.
I am facing some problems to do those operations.
Just re-correct my code to "binary_to_decimal_y1" every step by step.
Just see the results on every steps that what should be the result and what i am getting from MATLAB.
I just need a re-corrected code.
Help me, Please.
Rik
Rik le 5 Jan 2021
Just a small note: marking an answer as accepted means that it completely solves the problem. It is a signal that your main problem is fixed and only 1 or 2 comments will solve the rest. In general your question will receive less attention if you mark an answer as accepted before the issue is solved.
KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Jan 2021
@Noman, Is the issue with same context or different one? Please be specific, of course, I will try to help if I can.
It's the same context. I was just talking about the first step. I have added a comment on @Rik's reply.
I am attaching it here too. See the process and think that you can help me or not. It's just some easy calculations.
clc;
clear all;
close all;
load('y_send.mat');
y_send;
bit = 4;
levels = 16;
Fs = 44100;
len = length(y_send);
t = 0:1/Fs:(len-1)/Fs;
max_x = 1;
min_x = -1;
step=(max_x-min_x)/levels;
c1 = [ 1 -1 1 -1 ];
demultiplex_data_y1 = bsxfun(@times, c1, y_send);
demultiplex_data_y1
adding_rows_y1 = sum(demultiplex_data_y1, 2);
adding_rows_y1
convert_binary_y1 = (sign(adding_rows_y1)+1)/2;
convert_binary_y1
reshape_binary_y1 = reshape(convert_binary_y1,4,[]).';
num_to_string_y1 = num2str(reshape_binary_y1);
binary_to_decimal_y1 = bin2dec(num_to_string_y1);
binary_to_decimal_y1
reconstructing_samples_y1 = min_x+(step*binary_to_decimal_y1)+step/2;
reconstructing_samples_y1
audiowrite('audiofile1 cdm.wav', reconstructing_samples_y1, Fs);
Ok. So here is my full code.
Now, I have got a data set from "y_send''.
  1. To get "demultiplex_data_y1" I have to multiply y_send*c1 row to row and element to element.
  2. To get "adding_rows_y1" we have to sum all the row values got from "demultiplex_data_y1".
  3. To get "convert_binary_y1" we have to convert all the values (values got from "adding_rows_y1") to binary values.
  4. To get "binary_to_decimal_y1" we have to take every 4 values got from "convert_binary_y1" and make it decimal. For example we got [0 0 1 0 0 0 1 1 and so on] from "convert_binary_y1" and we have to make first 4 values in a string then second 4 values in a string and so on (like "0010'', "0011") and lastly making those values into decimal as [2, 3].
  5. Then just use the equation to get "reconstructing_samples_y1".
  6. Lastly, you will get a hearable audio file from "audiowrite('audiofile1 cdm.wav', reconstructing_samples_y1, Fs);" section. If you can't hear the audio then calculations are not correct.
To ensure your calculation just check every step values that what values should I get and what values i am getting from MATLAB.
KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Jan 2021
Modifié(e) : KALYAN ACHARJYA le 5 Jan 2021
"To ensure your calculation just check every step values that what values should I get and what values i am getting from MATLAB"
Please note: If you want help, then you need to make it easy to be helped, We are volunteers here, not MATLAB employees (except staff badge people),
There is no issue till following statement, right?
demultiplex_data_y1 = bsxfun(@times, c1, y_send);
demultiplex_data_y1
Which line has the calculaton issue, as you think?
Noman Abir
Noman Abir le 5 Jan 2021
Every line has a calculation issue here except this one ;
convert_binary_y1 = (sign(adding_rows_y1)+1)/2;
convert_binary_y1;
Rik
Rik le 5 Jan 2021
Can you show an incorrect result? Can you point out values (i.e. specific locations) in demultiplex_data_y1 that are incorrect?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2014b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by