필터 지우기
필터 지우기

How to fix following error?

조회 수: 21 (최근 30일)
Yasir Ali
Yasir Ali 2019년 3월 27일
댓글: Walter Roberson 2019년 3월 29일
Hello Seniors, How to Solve following error I tried but failed to solve it.
t=0:0.300:0.050:0500; x=chirp (t,0,1,150); F=0:0.1:100; [y,f,t,p]=spectrogram(x,256,250,F,1E3,'yaxis');
Error using welchparse>segment_info (line 88)The length of the segment cannot be greater than the length of the input signal.
I will provide full code if anyone need actually my problem is to get voice frequency in miliseconds.
  댓글 수: 4
Adam Danz
Adam Danz 2019년 3월 27일
There is no picture. A screen shot isn't really useful (if that's what you were going to share). People can't copy/paste a screen shot into their matlab workspace.
Yasir Ali
Yasir Ali 2019년 3월 27일
편집: Stephen23 2019년 3월 27일
here is complete error and also see full code below ,in which I can get good result but when I do some variation in code it shows error.
>> t=0.400:0.050:0.500;
>> x=chirp(t,0,1,150);
>> F = 0:.1:100;
>> [y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis');
Error using welchparse>segment_info (line 188)
The length of the segments cannot be greater than the length of the input signal.
Error in welchparse (line 32)
[L,noverlap,win] = segment_info(M,win,noverlap);
Error in spectrogram (line 172)
[x,nx,~,~,~,win,~,~,noverlap,~,~,options] = welchparse(x,esttype,varargin{:});
full code which works for frequeency spectrum in miliseconds.
t=0:0.001:2; % 2 secs @ 1kHz sample rate
x=chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1sec
F = 0:.1:100;
[y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis');
% NOTE: This is the same as calling SPECTROGRAM with no outputs.
surf(t,f,10*log10(abs(p)),'EdgeColor','none');
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time');
ylabel('Frequency (Hz)');
[y,fs]=audioread('filename5sec'.wav);
NW = round(fs*0.025);
[S,F,T,P] = spectrogram(y(:,1),NW,[],[],fs);
% Then to plot:
subplot(2,1,1),pcolor(T,F,log10(P)),
shading flat,
caxis([-6 0]+max(caxis))
colorbar
subplot(2,1,2)
semilogy(F,P(:,23))
title(sprintf('PSD at time: %f',T(23)))
xlabel('Frequency (Hz)')

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 28일
You assign a vector to t before the code, but you name t as an output parameter in the spectrogram() call. If you then try to use t after that, it is now only 3 x 1 and you have a problem.
The problem is not the first run: the problem is overwriting t but still expecting t to have the same meaning.
  댓글 수: 9
Walter Roberson
Walter Roberson 2019년 3월 29일
2 kHz is increment 1/2000 which is 0.0005
Walter Roberson
Walter Roberson 2019년 3월 29일
The general formula is:
time = (0:number_of_samples-1) / sampling_frequency

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam Danz
Adam Danz 2019년 3월 27일
"Error: The length of the segments cannot be greater than the length of the input signal."
When you're using miliseconds, your x input contains 2001 samples and your window value of 256 breaks up the 2001 values into 256 segments. That works fine. The reason your code is breaking with the other set of parameters is that your x input only contains 3 samples but your window value is still 256. As the error message indicates, the number of segments can't be greater than the number of samples in x.
  댓글 수: 5
Adam Danz
Adam Danz 2019년 3월 28일
Walter is a senior in this forum. I'm a novice compared to him :D
INow I understand that your data have a duration of 5 seconds and that you want the time variable to be at ms resolution. One more bit of information is missing: the interval of your data or the number of samples.
For example
t = 0:0.001:5;
length(t) % = 5001
gives you 5 seconds at 1ms intervals while
t = 0:0.005:5;
length(t) % = 1001
gives you 5 seconds at 5 ms intervals.
Or maybe you want 501 samples between 0 and 5 sec. That would be
linspace(0,5,501)
For now don't worry about being new at Matlab. I think the more important step is to be able to explain what you're trying to do (without worrying how to do it, for now).
Yasir Ali
Yasir Ali 2019년 3월 29일
Dear@Adam thank u for your comment, My main object is to compare frequencies of male and female voices I want to find out difference between male and female voices through frequencies after than I will recognise particular male voice by assigning frequency.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by