HFCC, Hello I have problem with code below

4 次查看(过去 30 天)
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 个评论
Rik
Rik 2020-8-27
编辑:Rik 2020-8-27
Why did you edit away your question? That is really rude. And pointless, as it can be restored again, as you could already see.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2020-5-19
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 个评论
Rik
Rik 2020-7-1
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 2020-7-1
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 :/

请先登录,再进行评论。

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by