Question

well first thanks in advance.

i am a machine learning person. for a project, i have created a matlab function which returns several features of a signal in frequency domain.

the function returns signal's energy, sum of fourier coefficients, entropy, pwr_at_DC, power at peak frequency, and peak freq/dominant frequency.

the error states 'two many output arguments'!

code is this...

%signal = [120 111 117 109 94 104 125 161]; %for example consider this discrete signal.

%the function returns Singal's energy, sum of fourier coefficients, entropy,
 %pwr_at_DC, power at peak frq, and peak freq.

function [signalFeatures] = SigFreqAnalysis(signal)
    NFFT = length(signal);              %leangth of the signal
    signal = signal - mean(signal);     %remove DC comp (avoid peak at 0Freq.

    FT = fft(signal,NFFT);              %fourier transform n point
    sEnergy = sum(abs(FT).^2)/NFFT;     %spectral energy
    SumCoeff = sum(abs(FT));            %total of all NFFT coefficients!

    %[P,F] = periodogram(signal,[],NFFT,'power');
    [P,F] = pwelch(signal,ones(NFFT,1),0,NFFT,'power');     %[P,F] - PSD of the signal

    %P1=real(P1);

    %Steps for Entropy: calc PSD ---> normalize p ---> entropy = ??(P)log2(P);
    Pn=P/norm(P);    log2Pn = log2(Pn + 1e-12);    
    Entropy = -sum(Pn.*log2Pn)/log2(length(Pn));

    PdBW = 10*log10(P);   pwr_at_DC = PdBW(F==0);   % power in dBW

    %the most important dominant frquency! ! !
    [pks_dBW,locs] = findpeaks(PdBW,'NPEAKS',1,'SORTSTR','descend');   %peak/dominant!
    %findpeak returns empty vector if no freq found!

    if isempty(pks_dBW)    
       pks_dBW=0; pkFrq = 0;   %if pks_dbs is 0 findpeak returns empty matrix; 
    else    
       pkFrq = F(locs);     %this is the dominant/peak frequency of X axes!!
    end

    signalFeatures = [sEnergy SumCoeff Entropy pwr_at_DC pks_dBW pkFrq]; 
    %return this vector.
end

error ---> 'too many output arguments' in findpeak function! can anyone help me resolve this error!

thanks, Adesh Shah

Was it helpful?

Solution

Your code that calls the function should look like this:

signal = [120 111 117 109 94 104 125 161] 

a = SigFreqAnalysis(signal)

but you are probably calling it this way

[a b] = SigFreqAnalysis(signal)

Hence, too many outputs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top