Azzera filtri
Azzera filtri

How can i fix the indices on the right to fit the indices on the left?

1 visualizzazione (ultimi 30 giorni)
This is the function where the error is indicated:
function AudioSections(app, signal, numSections)
signalLength = length(signal);
overlapFactor = 0.5;
%sectionLength = floor(signalLength / (numSections - overlapFactor));
sectionLength = floor(signalLength / numSections);
overlapLength = floor(sectionLength * overlapFactor);
%This part does the dividing into sections
for i = 1:numSections
startIndex = max((i-1) * sectionLength - floor((i-2) * overlapLength), 1);
endIndex = min(i * sectionLength + overlapFactor, signalLength);
sect = signal(startIndex:endIndex);
sectL = length(sect);
sectT = transpose(sect);
Blackman_window = blackman(sectL);
%Sect = transpose(sectT.* Blackman_window);
Sect = sectT.* Blackman_window;
app.Sections(i) = Sect; %Error is here
filename = strcat(app.File_Path, 'Section_', num2str(i), '.wav');
audiowrite(filename, app.Sections(i), app.Frequency);
end
This is how my variables are declared:
Sections = [];
Frequency = 44100;
Channels = 2;
Num_Bits = 16;
Data_Type_Audio = 'double';
This is the error:
"Error using Prac2/AudioSections
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
AudioSections(app, app.RecordedAudioData, 5);"

Risposte (1)

Walter Roberson
Walter Roberson il 22 Ott 2023
Channels = 2;
The recorded data will have 2 channels.
signalLength = length(signal);
length() should typically only be used for vectors. Audiodata is always one column vector per channel, so you should be asking about the height of the signal array, which you can do with size(signal,1) or with height(signal)
sect = signal(startIndex:endIndex);
You are indexing the signal as if it is only a vector. The result is going to be a column vector.
sectT = transpose(sect);
You transpose it into a row vector.
Blackman_window = blackman(sectL);
blackman() returns a column vector.
Sect = sectT.* Blackman_window;
You do element-by-element multiplication between a row vector and a column vector. The result is going to be a 2D array.
app.Sections(i) = Sect; %Error is here
You try to store the entire 2D numeric array into a single location. That can only work if app.Sections were a custom class that redefined indexing for storage purposes. You should be storing into a cell array
  5 Commenti
Walter Roberson
Walter Roberson il 23 Ott 2023
No, your function calculateFFT is not constructed to return any value. Instead it is setting properties of app such as setting app.Fw . Your could would have to have something that looks like an assignment between the function keyword and the function name in order to return anything. For example,
function fftdata = calculateFFT(app, Data)
but perhaps you should instead be changing from
FFTsect = calculateFFT(app, app.Sections{i}); %Error is here
to
calculateFFT(app, app.Sections{i});
FFTsect = app.Fw;

Accedi per commentare.

Categorie

Scopri di più su Variables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by