HFCC, Hello I have problem with code below

My topic of project is: Analysis of HFCC parameter variability as a function of time for a given signal
I have problem with fft of z(n,t)
Subscripted assignment dimension mismatch.
Error in projekthfcc (line 57)
widmo(t,:) = fft(z(t,:),Nfft);
close all;
clear all;
[s,fp]=audioread('sygnal.wav');
N=length(s);
x=decimate(s,4);
Nx = length(x);
tx = (0:Nx-1)/fp;
%Preemfaza
N = length(x);
y=x(1);
for i=2:N
y(i)=x(i)-0.95*x(i-1);
end
fpr = fp/4;
figure(1)
plot(tx,x);
Ny = length(y);
ty = (0:Ny-1)/fpr;
%t = 0:1/fpr:(length(x)-1)/fpr;
figure(2)
plot(y);
ylabel('Badany sygnal po 4 krotnej decymacji');
xlabel('Czas[s]');
Nr = 25; %frame [ms]
Ns = 10; %step frame [ms]
nr = (Nr*0.001)*fpr; %rame [sample]
ns = (Ns*0.001)*fpr; %step frame [sample]
T = floor((Ny - nr - 1)/ns); %number of frames
Nfft = 2^nextpow2(nr);
N21 = Nfft/2+1;
z1 = zeros(length(0:T-1), length(0:nr-1));
z = zeros(length(0:T-1), length(0:nr-1));
for n = 1:nr
for t = 1:T
z1(t,n) = y(t*ns+n); % framing
z(t,n) = y(t*ns+n) * w(n,nr);% z1 * hamming windows
end
end
widmo = zeros(length(0:T-1), length(0:nr-1));
for t = 1:T
widmo(t,:) = fft(z(t,:),Nfft);
widmo1(t,:) = pow(abs(fft(widmo(t,:),2)));
end
function [ out ] = w( n, Nr )
if n < 1 || n > Nr
out = 0;
return;
end
out = 0.54 - 0.46*cos(2*pi*(n-1)/Nr-1);
end

4 commentaires

Rik
Rik le 1 Juil 2020
Modifié(e) : Rik le 1 Juil 2020
Question recovered from Google cache (thanks Michalina Stocka for changing the question title, that makes this easier):
HFCC, Hello I have problem with code below
My topic of project is: Analysis of HFCC parameter variability as a function of time for a given signal
I have problem with fft of z(n,t)
Subscripted assignment dimension mismatch.
Error in projekthfcc (line 57)
widmo(t,:) = fft(z(t,:),Nfft);
close all;
clear all;
[s,fp]=audioread('sygnal.wav');
N=length(s);
x=decimate(s,4);
Nx = length(x);
tx = (0:Nx-1)/fp;
%Preemfaza
N = length(x);
y=x(1);
for i=2:N
y(i)=x(i)-0.95*x(i-1);
end
fpr = fp/4;
figure(1)
plot(tx,x);
Ny = length(y);
ty = (0:Ny-1)/fpr;
%t = 0:1/fpr:(length(x)-1)/fpr;
figure(2)
plot(y);
ylabel('Badany sygnal po 4 krotnej decymacji');
xlabel('Czas[s]');
Nr = 25; %frame [ms]
Ns = 10; %step frame [ms]
nr = (Nr*0.001)*fpr; %rame [sample]
ns = (Ns*0.001)*fpr; %step frame [sample]
T = floor((Ny - nr - 1)/ns); %number of frames
Nfft = 2^nextpow2(nr);
N21 = Nfft/2+1;
z1 = zeros(length(0:T-1), length(0:nr-1));
z = zeros(length(0:T-1), length(0:nr-1));
for n = 1:nr
for t = 1:T
z1(t,n) = y(t*ns+n); % framing
z(t,n) = y(t*ns+n) * w(n,nr);% z1 * hamming windows
end
end
widmo = zeros(length(0:T-1), length(0:nr-1));
for t = 1:T
widmo(t,:) = fft(z(t,:),Nfft);
widmo1(t,:) = pow(abs(fft(widmo(t,:),2)));
end
function [ out ] = w( n, Nr )
if n < 1 || n > Nr
out = 0;
return;
end
out = 0.54 - 0.46*cos(2*pi*(n-1)/Nr-1);
end
Rena Berman
Rena Berman le 22 Juil 2020
(Answers Dev) Restored edit
Rik
Rik le 27 Août 2020
Modifié(e) : Rik le 27 Août 2020
Why did you edit away your question? That is really rude. And pointless, as it can be restored again, as you could already see.
Rena Berman
Rena Berman le 12 Oct 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 19 Mai 2020
Nfft = 2^nextpow2(nr);
So Nfft will be at least as large as nr, and often larger.
widmo = zeros(length(0:T-1), length(0:nr-1));
length(0:nr-1) is (nr-1) plus 1 for the 0, for a total of nr . So widmo has nr columns.
widmo(t,:) = fft(z(t,:),Nfft);
fft() with Nfft specified tells fft to use Nfft points. We established that Nfft is typically larger than nr, so the fft() would typically produce a vector larger than nr. But you are trying to store it in a row vector that has exactly nr columns.

3 commentaires

Walter Roberson
Walter Roberson le 20 Mai 2020
I do not understand the point of using length(0:NFFT-1) when that is always going to be the same as NFFT for any non-negative NFFT??
Deleted comment recovered from Google cache:
Thank you for your answer.
I change this part of code:
widmo = zeros(length(0:T-1), length(0:Nfft-1));
for t = 1:T
widmo(t,:) = power(abs(fft(z(t,:),Nfft)),2);
end
and there is no error now, but I'm not sure if this is the correct version. The formula for fft is pictured below.
l - frequency indicator
L - number of spectrum bands
Rik
Rik le 1 Juil 2020
Deleted comment recovered from Google cache:
so "widmo" should be a matrix of what dimensions? and how can I determine the value of "L"? Sorry, maybe there are simple things, but I am a beginner in this ground :/

Connectez-vous pour commenter.

Produits

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by