How can I solve this problem?

2 Ansichten (letzte 30 Tage)
Noman Abir
Noman Abir am 5 Jan. 2021
Kommentiert: Rik am 5 Jan. 2021
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 Kommentare
Noman Abir
Noman Abir am 5 Jan. 2021
Bearbeitet: Rik am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 5 Jan. 2021
Bearbeitet: KALYAN ACHARJYA am 5 Jan. 2021
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 Kommentare
Noman Abir
Noman Abir am 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 am 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by