## Revised: find the frequency corresponding to max. magnitude in spectrum (FFT)

on 4 Oct 2012

### Wayne King (view profile)

the spectrum of a message is shown as follows

where magnitude plot of the Fourier transform for message versus frequency in Hz is seen.

how can i find the dominant frequency with the use of the command max and command freqz?

## Products

No products are associated with this question.

### Wayne King (view profile)

on 4 Oct 2012
Edited by Wayne King

### Wayne King (view profile)

on 4 Oct 2012

Why are you calling freqz() on the frequency response???

```    [freq_resp,freq]=freqz(message,1,100000,22000);
[maxval,index] = max(abs(freq_resp));
freq(index)```

I also question whether you should be using freqz(), That is really intended for filters where the inputs are the filter numerator and denominator coefficients.

Why not use the PSD

```[Pxx,Fxx] = periodogram(message,rectwin(length(message)),length(message),22000);
[maxval,index] = max(Pxx);
Fxx(index)
```

#### 1 Comment

Passband Modulation

### Passband Modulation (view profile)

on 4 Oct 2012

my course notes advise that freqz() might help but is not necessary. this is mentioned so because the question raised is actually related to "least squares filter" used for interference cancelling which is what i am working on now.

ur suggestion of PSD does help. it turns out the right result as the plot indicates. thx!!

### Wayne King (view profile)

on 4 Oct 2012
Edited by Wayne King

### Wayne King (view profile)

on 4 Oct 2012

If you are using freqz(), freqz() returns the frequency vector, so just query the max value of the absolute value of the frequency response and then use that index to find the frequency.

```   h = [1/sqrt(2) 1/sqrt(2)];
[H,F] = freqz(h,1);
[maxval,index] = max(abs(H));
F(index)```

This example gives 0, because h is a lowpass filter with the maximum at 0 radians/sample.

freqz() takes the sampling frequency as an input argument so that you can get the frequencies in Hz.

#### 1 Comment

Passband Modulation

### Passband Modulation (view profile)

on 4 Oct 2012

``` [freq_resp,freq_index]=freqz(message,1,100000,22000);
plot(freq_index,abs(freq_resp))```

so i wonder how to commbine urs with the code shown above? will it be the following?

```[freq_resp,freq_index]=freqz(message,1,100000,22000);
plot(freq_index,abs(freq_resp))
```
```   [H,F] = freqz(freq_index,freq_resp));
[maxval,index] = max(abs(H));
F(index)```

i didnt make it right, however. result turns out to be zero. so could u plz modify?

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi