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
|
|
|
|
Reply
|
gkk
|
10/30/2010 12:59:05 AM |
|
"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
|
|
|
|
Reply
|
Wayne
|
10/30/2010 11:17:03 AM
|
|
"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
|
|
|
|
Reply
|
gkk
|
10/30/2010 6:07:04 PM
|
|
|
2 Replies
329 Views
(page loaded in 0.097 seconds)
|