1

For example we have a sinusoidal function and we want to find frequency of this function/ For those we use Discrete Fourier Transform. Code:

fB = 1.0;
Data1 = Table[Sin[2 Pi fB x], {x, 0, 5, 1/10}];
sra = 10./1;
inco = sra/Length[Data1];
fresa = Table[f, {f, 0, sra - inco, inco}];
ListPlot[Transpose[{fresa, Flatten[Abs[Fourier[Data1]]]}], 
 PlotRange -> {Full, Full}, Joined -> True, Frame -> True, 
 FrameLabel -> {Row[{Style["Frequency", FontSlant -> Italic, 
      FontSize -> 15]}], 
   Row[{Style["Amplitude", FontSlant -> Italic, FontSize -> 15]}]}, 
 LabelStyle -> Blue
 , FrameTicksStyle -> Directive[Orange, 15], ImageSize -> 900, 
 PlotStyle -> {Red}, Joined -> True, AspectRatio -> 0.5, 
 Epilog -> {PointSize[0.003], 
   Point[Transpose[{fresa, Flatten[Abs[Fourier[Data1]]]}]]}]

From Fourier spectrum we can see that value of ours frequency is 1. Question is about How we can find frequency automatically, i want to see value, not finding it by "Get Cordinates" Fourier spectrum

To @andre mistakes

John
  • 573
  • 2
  • 9

1 Answers1

1

By calculating the frequency data first, you can use FindPeaks to obtain the peak positions and values:

fB=1.0;
Data1=Table[Sin[2 Pi fB x],{x,0,5,1/10}];
sra=10./1;
inco=sra/Length[Data1];
fresa=Table[f,{f,0,sra-inco,inco}];
fData=Transpose[{fresa,Flatten[Abs[Fourier[Data1]]]}];
peaks=fData[[FindPeaks[fData[[All,2]]][[All,1]]]];
ListPlot[fData,PlotRange->{Full,Full},Joined->True,Frame->True,FrameLabel->{Row[{Style["Frequency",FontSlant->Italic,FontSize->15]}],Row[{Style["Amplitude",FontSlant->Italic,FontSize->15]}]},LabelStyle->Blue,FrameTicksStyle->Directive[Orange,15],ImageSize->900,PlotStyle->{Red},Joined->True,AspectRatio->0.5,Epilog->{PointSize[0.003],Point[fData],Black,PointSize[.01],Point[peaks]},PlotLabel->"Peaks: "<>ToString[peaks]]

enter image description here

David Keith
  • 4,340
  • 1
  • 12
  • 28