Effacer les filtres
Effacer les filtres

How do i get the y value for a given x value?

1 vue (au cours des 30 derniers jours)
nevin
nevin le 3 Oct 2014
Commenté : Stephen23 le 6 Oct 2014
I have plotted a frequency spectrum with the command "spect = fft(recording)" and "plot (abs(spect))" Is there a way that I can get matlab to give me the value of Y when the value of X is say 200Hz?

Réponse acceptée

Star Strider
Star Strider le 3 Oct 2014
You have to create a frequency vector as well to plot and interpret the fft correctly as a function of frequency, and for that you need the sampling frequency, (Fs) of ‘recording’. Then use interp1 to get the value at any specific frequency.
For example:
Fs = 1000; % Sampling Frequency
Ts = 1/Fs;
Tv = linspace(0,10*pi,505);
recording = sin(290*Tv).*cos(310*Tv)+rand(size(Tv));
spect = fft(recording);
specta = abs(spect);
Fn = Fs/2; % Nyquist Frequency
Fv = linspace(0, 1, length(spect)/2+1)*Fn;
Iv = 1:length(Fv); % Index vector
a200 = interp1(Fv, specta(Iv), 200); % Find Amplitude At 200 Hz
figure(1)
plot(Fv, specta(Iv), 200,a200,'pr') % Plot fft & Amplitude at 200 Hz
grid
  3 commentaires
Star Strider
Star Strider le 6 Oct 2014
My pleasure!
Stephen23
Stephen23 le 6 Oct 2014
Nice answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by