HFCC, Hello I have problem with code below
Mostrar comentarios más antiguos
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 comentarios
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
el 22 de Jul. de 2020
(Answers Dev) Restored edit
Rena Berman
el 12 de Oct. de 2020
(Answers Dev) Restored edit
Respuestas (1)
Walter Roberson
el 19 de Mayo de 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 comentarios
Walter Roberson
el 20 de Mayo de 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??
Rik
el 1 de Jul. de 2020
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
el 1 de Jul. de 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 :/
Categorías
Más información sobre Video Formats and Interfaces en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!