4

suppose that we have following code

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 plot(x)
end

i have generated signal using following command

y=generate1(3,500,1);

and i have got 501 length sample,now i want to use music method to detect frequencies,namely 100 and 200,assume that number of parameter is 2,so i have tried

pmusic(y,4)

enter image description here

how determine actually frequencies from this picture?i think that i need to convert a from normalized frequency to actual frequency,as i know normalized frequency is same as $f/f_s$ where $f_s$ is sampling frequency,but in this case what i should do?

1 Answers1

4

You need to multiply by half the sampling rate. I.e., the normalized frequency "1.0" is Fsample/2.

For a simple example, here's a 200 Hz signal sampled at 4KHz:

x=sin(2*pi*200/4000*[0:1000])

Running pmusic(x, 2) gives a pronounced peak at the normalized frequency 0.1. Converted to Hz, this is 0.1*4000/2 = 200 Hz.

I have modified your function to make it easier to analyze (just one sine function and no randomness):

 function x = gen(N,m)
    f1 = 100;
    T  = 1/f1;
    dt = N*T/m;

    x = sin(2*pi*f1*dt*[0:num_of_samples]);
 end

 x = gen(3,500,1e3);

To get better resolution use pmusic(x,2,[0:.01:0.2]).

nimrodm
  • 23,081
  • 7
  • 58
  • 59
  • thanks very much,in my case what i should do?let us assume that N=3 and m=500 –  Feb 16 '14 at 14:57
  • but why 0.1?in my case sampling frequency is 16666.66666666667,so i should have 0.1*16666.66666666667/2 ? –  Feb 16 '14 at 15:04
  • are you here?i can't continue –  Feb 16 '14 at 15:16
  • in my picture peak it not indicated at exact normalized frequency,should i guess? –  Feb 16 '14 at 15:17
  • In your case the estimated frequency will be Fs/2*0.116 = 1.666e3/2 * 0.116 = 96 Hz. If you take more samples you can get better accuracy. You expect peaks at 100 Hz and 200 Hz (f1 and f2) – nimrodm Feb 16 '14 at 15:24
  • how much do i need to increase sample?what is recomended? –  Feb 16 '14 at 15:26
  • how did you get 0.116 by the way? –  Feb 16 '14 at 15:27
  • i have sampled at exactly at 400 sample rate and get exact peaks,so what does it means? –  Feb 16 '14 at 15:37
  • what if i dont know sampled frequency?can i calculate frequencies? –  Feb 16 '14 at 15:38
  • @datodatuashvili added a simpler example – nimrodm Feb 16 '14 at 16:26
  • thanks for help,i am interested now if i dont know sampling frequency and actual frequency,can i calculate from normalized frequency? –  Feb 16 '14 at 16:30
  • 1
    You must know the sampling frequency to get an estimate of the true frequency. – nimrodm Feb 16 '14 at 17:19