COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### basic FIR filter question (normalization)

• Follow

```Can someone help me understand why the fvtool stop-band -80dB level is different than my manually calculated stopband (-185dB)? Not sure where I'm going wrong here.

% Here's an example filter:
% 500 MHz (20GS/s) FIR low-pass filter with flat passband & -80dB stopband
% Wn = 500MHz / ((20GS/s)/2) = 1/20 = 0.05

M = 1001; % number of points in filter impulse response (number of filter taps = M-1)
Wn= 0.05; % normalized cutoff frequency
Ft = fircls1(M-1, Wn, 0.0001, 0.0001)';
fvtool(Ft, 1, 'FrequencyScale', 'log');

% take FFT
fftpoints = 2^21;                       % total number of points in FFT
Ff = single( fft(Ft, fftpoints) );      % adds (fftpoints-M) zeros to Ft and takes FFT
Ff_mag = abs( Ff(1: fftpoints/2 + 1) ); % ??? normalization
Ff_dB = 20*log(Ff_mag);                 % convert to dB

% create FFT spectrum x-axis
samplerate = 20e9;  % 20 Gsamples/sec
fft_xaxis = single(0 : 1 : fftpoints/2)';
fft_xaxis = fft_xaxis * single(samplerate/fftpoints);

figure(2)
semilogx(fft_xaxis, Ff_dB, 'g-')
xlabel('Frequency (Hz)');
ylabel('FFT Magnitude (dBm, dB)');
title('Spectrums of Filter (Green) vs Frequency (Hz)');
xlim([1e4 1e10]);
grid on;
```
 0

```"gkk gkk" <gkkmath@comcast.net> wrote in message <iafqkp\$ou3\$1@fred.mathworks.com>...
> Can someone help me understand why the fvtool stop-band -80dB level is different than my manually calculated stopband (-185dB)? Not sure where I'm going wrong here.
>
>
> % Here's an example filter:
> % 500 MHz (20GS/s) FIR low-pass filter with flat passband & -80dB stopband
> % Wn = 500MHz / ((20GS/s)/2) = 1/20 = 0.05
>
> M = 1001; % number of points in filter impulse response (number of filter taps = M-1)
> Wn= 0.05; % normalized cutoff frequency
> Ft = fircls1(M-1, Wn, 0.0001, 0.0001)';
> fvtool(Ft, 1, 'FrequencyScale', 'log');
>
> % take FFT
> fftpoints = 2^21;                       % total number of points in FFT
> Ff = single( fft(Ft, fftpoints) );      % adds (fftpoints-M) zeros to Ft and takes FFT
> Ff_mag = abs( Ff(1: fftpoints/2 + 1) ); % ??? normalization
> Ff_dB = 20*log(Ff_mag);                 % convert to dB
>
> % create FFT spectrum x-axis
> samplerate = 20e9;  % 20 Gsamples/sec
> fft_xaxis = single(0 : 1 : fftpoints/2)';
> fft_xaxis = fft_xaxis * single(samplerate/fftpoints);
>
> figure(2)
> semilogx(fft_xaxis, Ff_dB, 'g-')
> xlabel('Frequency (Hz)');
> ylabel('FFT Magnitude (dBm, dB)');
> title('Spectrums of Filter (Green) vs Frequency (Hz)');
> xlim([1e4 1e10]);
> grid on;

Hi, what I get agrees with fvtool. I'll use normalized frequency as you have done.

Ftdft = fft(Ft,2048);
Ftdft = Ftdft(1:1025);
freq = linspace(0,pi,1025);
freq = freq./pi;
plot(freq,20*log10(abs(Ftdft)));

BTW, why are you casting things into single precision?

Hope that helps,
Wayne
```
 0

```"Wayne King" <wmkingty@gmail.com> wrote in message <iagurf\$cn9\$1@fred.mathworks.com>...
> "gkk gkk" <gkkmath@comcast.net> wrote in message <iafqkp\$ou3\$1@fred.mathworks.com>...
> > Can someone help me understand why the fvtool stop-band -80dB level is different than my manually calculated stopband (-185dB)? Not sure where I'm going wrong here.
> >
> >
> > % Here's an example filter:
> > % 500 MHz (20GS/s) FIR low-pass filter with flat passband & -80dB stopband
> > % Wn = 500MHz / ((20GS/s)/2) = 1/20 = 0.05
> >
> > M = 1001; % number of points in filter impulse response (number of filter taps = M-1)
> > Wn= 0.05; % normalized cutoff frequency
> > Ft = fircls1(M-1, Wn, 0.0001, 0.0001)';
> > fvtool(Ft, 1, 'FrequencyScale', 'log');
> >
> > % take FFT
> > fftpoints = 2^21;                       % total number of points in FFT
> > Ff = single( fft(Ft, fftpoints) );      % adds (fftpoints-M) zeros to Ft and takes FFT
> > Ff_mag = abs( Ff(1: fftpoints/2 + 1) ); % ??? normalization
> > Ff_dB = 20*log(Ff_mag);                 % convert to dB
> >
> > % create FFT spectrum x-axis
> > samplerate = 20e9;  % 20 Gsamples/sec
> > fft_xaxis = single(0 : 1 : fftpoints/2)';
> > fft_xaxis = fft_xaxis * single(samplerate/fftpoints);
> >
> > figure(2)
> > semilogx(fft_xaxis, Ff_dB, 'g-')
> > xlabel('Frequency (Hz)');
> > ylabel('FFT Magnitude (dBm, dB)');
> > title('Spectrums of Filter (Green) vs Frequency (Hz)');
> > xlim([1e4 1e10]);
> > grid on;
>
> Hi, what I get agrees with fvtool. I'll use normalized frequency as you have done.
>
> Ftdft = fft(Ft,2048);
> Ftdft = Ftdft(1:1025);
> freq = linspace(0,pi,1025);
> freq = freq./pi;
> plot(freq,20*log10(abs(Ftdft)));
>
>
> BTW, why are you casting things into single precision?
>
> Hope that helps,
> Wayne

Yes, helps a lot, thanks! I can see the difference is I was using log (natural log) whereas you used log10 (base10 log). I thought log was base10 log, but I see now that's my problem! thanks. I use single precision because the arrays are very large, can't fit into my computer memory unless I use single.
```
 0

2 Replies
329 Views

5/30/2013 10:13:41 PM