Error: The length of the segments cannot be greater than the length of the input signal.

45 views (last 30 days)
Hi, I'm using the time2psd function to run a script. however the command window gives me this error
("Input" is the script I am using, the below are to be read from bottom to top):
Error using signal.internal.spectral.welchparse>segment_info
The length of the segments cannot be greater than the length of the input signal.
Error in signal.internal.spectral.welchparse (line 34)
[L,noverlap,win] = segment_info(M,win1,noverlap1);
Error in welch (line 55)
signal.internal.spectral.welchparse(x,esttype,args{:});
Error in pwelch (line 170)
[welchOut{1:nargout}] = welch(x,funcName,inputArgs{:});
Error in time2psd (line 4)
[PSD,freq]=pwelch(sign,hann(fft_point),0,fft_point,maxfreq*2);
Error in input (line 47)
[freq_r PSD_r]=time2psd(fft_point,Rx,Fcamp/2)
This is the text of the time2psd function:
function [freq PSD]=time2psd(fft_point,sign,maxfreq)
% Analisi in frequenza (PSD) del segnale temporale
[PSD,freq]=pwelch(sign,hann(fft_point),0,fft_point,maxfreq*2);
% [A,B]=spectrum(sign,fft_point,fft_point/4,hanning(fft_point));
% freq=B(:,1)*maxfreq;
% PSD=A(:,1)/maxfreq;
% fft_point/4
this is the "input" script that I have to run (Rx and Fcamp I already know them)
fft_point = 4096;
[freq_r PSD_r]=time2psd(fft_point,Rx,Fcamp/2)
figure(6)
loglog(freq,PSDinp)
hold on
loglog(freq_r,PSD_r)
xlabel('Frequency [Hz]')
ylabel('Amplitude [N^2/Hz]')
legend('PSD target','PSD ricostruita')

Answers (1)

VBBV
VBBV on 25 Jul 2022
Edited: VBBV on 25 Jul 2022
fft_point = [2048 4096];
fft_point must have atleast 2 values as input argument for pwelch function
  2 Comments
Federico Paolucci
Federico Paolucci on 25 Jul 2022
ok perfect,i modified the fft as you told me, but now it gives me another error
Error using check_order
Expected N to be a scalar.
Error in check_order (line 22)
validateattributes(n_in,{'numeric'},{'scalar','finite','real','nonnegative'},'check_order','N');
Error in gencoswin (line 21)
[L,w,trivialwin] = check_order(N);
Error in hann (line 25)
w = gencoswin('hann',varargin{:});
Error in time2psd (line 4)
[PSD,freq]=pwelch(sign,hann(fft_point),0,fft_point,maxfreq*2);
Error in input (line 48)
[freq_r PSD_r]=time2psd(fft_point,Rx,Fcamp/2)
below is the complete input script, if needed
clear all;clc
%parametri mulattiera
xmax=7.5/100;
sx=xmax/4;
rms=sx;
%parametri scelti da noi strada
L=50;%lunghezza strada [m]
v=25;%velocità con cui la attraversiamo [m/s] circa 20 all'ora
%lunghezze d'onda
lmax=10; %lunghezza d'onda massima [m]
lmin=0.1; %lunghezza d'onda minima [m]
%
Fmax=4*(1/lmin); %frequenza d'onda massima osservabile [1/m] Nyquist
Fcamp=Fmax*2;%frequenza di campionamento;
fmin=1/lmax;
fmax=1/lmin;
df=1/Fcamp;
f=[df:df:Fmax];
ifi=round(fmin/df);%da ifi a ife sono gli intervalli che mi interassano dove ho il mio trapezio
ife=round(fmax/df);
psd=zeros(length(f),1);
h=(2*rms^2)/(fmax+fmin);
for i =ifi:ife;
psd(i,1)=(-9/10*((f(i)-fmin)*h)/(fmax-fmin))+h;
end
z=sqrt(trapz(f,psd));%verifica dell'rms tramite la psd
figure(1);%rifai anche il time2psd
plot(f,psd,'b','linewidth',2);
grid on;hold on;
xlabel('frequenza spaziale[1/m]');
ylabel('PSD spaziale[m^2/(1/m)]');
%genero il segnale della strada
dx=1/(Fcamp); %spazio di campionamento [m]
Rx=psd2time(psd,f,L,dx);
figure(2)
grid on;
plot(Rx(:,1),Rx(:,2));
xlabel('lunghezza strada [m]');
ylabel('profilo strada [m]');
fft_point = [2048 4096];
[freq_r PSD_r]=time2psd(fft_point,Rx,Fcamp/2)
figure(6)
loglog(freq,PSDinp)
hold on
loglog(freq_r,PSD_r)
xlabel('Frequency [Hz]')
ylabel('Amplitude [N^2/Hz]')
legend('PSD target','PSD ricostruita')
VBBV
VBBV on 7 Aug 2022
what does psd2time function code return?
Rx=psd2time(psd,f,L,dx);
it works without error when using time2psd function

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!