How to get the fundamental frequency magnitude ?

Hi,
I have an array of a pseudo-sin signal.
I want to get the fundamental magnitude of it knowing the fundamental frequency.
My approach is (about 4-5 command lines)...,
a) fft the signal; b) search for the magnitude of the fundamental frequency; c) show the magnitude.
There is no command to get the fundamental magnitude easily ?
Thanks.
Andre

 Accepted Answer

If you have the Signal Processing Toolbox, use the findpeaks function.

12 Comments

Hi,
my code goes like this:
y=ySignal(m,:);
ydft = fft(y,NFFT);
freq=Fs/2*linspace(0,1,NFFT/2+1);
data = 2*abs(ydft(1:NFFT/2+1)/size(y,2));
index60=find(freq(:)==60);
YAAPreFaltaMagnitude60=abs(data(index60));
For example, the fundamental frequency of ySignal is on ~60Hz.
The problem is that, I can´t get the correct Amplitude of ySignal.
Thanks.
Andre
You need to attach (use the ‘paperclip’ icon) the ‘m’ row for Signal, so we can run your code to see what the problem is.
Hi,
its attached as a csv file.
Work like this, (1:400, 6)
for col 6, first 400 rows.
Almost 60Hz fundamental frequency signal.
Thank you.
Forgot the attached file.
What is the sampling frequency?
Sorry,
Fs=15360; NFFT=512;
This is what I used to find the frequency and amplitude of the first 100 ms ( 1537 samples ) of the signal. The fprintf statement at the end writes the maximum amplitude and its frequency to the Command Window. This is the only way I know of to do what you want:
filedat = which('Andre_signal.csv');
x = csvread(filedat);
ad = x(:,6);
lendat = size(x,1);
Fs=15360; NFFT=512;
Ts = 1/Fs;
Tv = linspace(0,length(ad)/Fs,length(ad));
Pls1 = find(Tv > 0.1, 1, 'first'); % Initial ‘pulse’ about 100 ms long
Fv = [0:length(ad)/2-1]*Fs/length(ad);
ad2 = ad(1:Pls1);
Tv2 = linspace(0,length(ad2)/Fs,length(ad2)); % Time vector
Fv2 = [0:length(ad2)/2-1]*Fs/length(ad2); % Frequency vector
fftad2 = fft(ad2);
afftad2 = abs(fftad2(1:fix(length(ad2)/2)));
figure(1)
plot(Tv2, ad2)
grid
maxix2 = find(afftad2 == max(afftad2)); % Find index of maximum fft amplitude
FVmax2 = [2*afftad2(maxix2)/length(ad2) Fv2(maxix2)]
figure(2)
plot(Fv2, 2*afftad2/length(ad2))
axis([0 350 ylim])
grid
fprintf(1,'\n\tMaximum amplitude = %13.5E at %.2f Hz\n\n', FVmax2)
Thank you. Gotta 2 questions:
1) Why can´t I: ad = x( 1:400 ,6); ?
2) What is Pls1 ?
Andre
My pleasure!
  1. You probably can. I used the entire column in one part of my code because I didn’t get sufficiently detailed FFT results with only 400 samples ( 26 ms ) of a 60 Hz signal. That was only about 1.56 cycles, not enough for a reliable analysis, and gave a peak frequency of about 75 Hz, obviously wrong in the context of a longer and more reliable signal, and an inaccurate amplitude.
  2. Your signal had three components, an initial 100 ms = 1537 sample segment (that I used as Pls1), a second smaller-amplitude segment with the same frequency about as long, and a third segment that seemed to repeat the first 100 ms. (There also appeared to be switching transients. They appeared in the analysis of the entire signal, but I did not include them in Pls1. I ignored all but the first 100 ms in my analysis that I posted here.) That was a longer version of the first 400 samples you wanted to use, and gave better results. I called it ‘Pulse#1’ for lack of a better term, and abbreviated it to Pls1. The FFT of Pls1 gave good results. The FFT of the first 400 samples did not.
Thank you very much.
Andre

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!