0

I have several cell arrays with probe data from .mat-file.

I need to find resonance frequencies and q-factors for each of the 1000 inputs, and then estimate (approximate) them. However, the code below provides only 1 value of fres instead of 1000, and no plot for (i, fres) is shown.

  • FStart - cell array (1000*1)
  • FEnd - cell array (1000*1)
  • Amp - multiarray (1000*100)

    for i = 1:1:1000
        f1 = FStart(i):10:FEnd(i);     
        grid on  
        y1 = plot(f1,Amp(i,:)); 
        [maxValue, maxIndex] = max(Amp(i,:));  %find maximum value of amplitude for each i
        [Q_Value, Q_Index] = max(0.5*Amp(i,:));  %also tried 0.5*max() and /2
        fres = f1(maxIndex);  %by index of max amplitude value find resonance frequency
        plot(i,fres)     %plot resonance frequency for each i
        hold on
    end
    

NB: the last FStart value is less than the first FreqEnd value

Futhermore, I try to esteem the Q factor as: Max(frequency on level = 1/2*MaxAmplitude)-Min(frequency on level = 1/2*MaxAmplitude)

fmin = min(f2(Q_Index))
fmax = max(f2(Q_Index))

But it shows fmin = fmax

Could you please tell, what's the problem here?

Lundin
  • 195,001
  • 40
  • 254
  • 396
TheDoctor
  • 105
  • 1
  • 9
  • `i` is a scalar, so `plot(i,fres)` is plotting a single point on a graph which won't show anything without a marker. To see something, try `plot(i,fres,' *')` to plot with a star marker. `Q_Index` is a single index that is reassigned each loop iterator so `f2(Q_Index)` is also a single number and it makes sense then that `fmin = fmax` – jodag Jul 12 '17 at 02:09

1 Answers1

1

Apart from the comment to your answer which clearly shows where the problem is, you may wan to remove the plot from the script by storing fres as a vector:

for i = 1:1000
    f1 = FStart(i):10:FEnd(i);     
    grid on  
    y1 = plot(f1,Amp(i,:)); 
    [maxValue, maxIndex] = max(Amp(i,:));  %find maximum value of amplitude for each i
    [Q_Value, Q_Index] = max(0.5*Amp(i,:));  %also tried 0.5*max() and /2
    fres(i) = f1(maxIndex);  %by index of max amplitude value find resonance frequency    
end
plot(1:1000,fres,'ko-','LineWidth',2)
Ivea
  • 83
  • 7