converting a filter using c2d and the input vector resolution

6 ビュー (過去 30 日間)
Chengcheng Xu
Chengcheng Xu 2019 年 8 月 6 日
コメント済み: Star Strider 2019 年 8 月 7 日
I would like to have a better understanding of the workflow from filter creating -> converting filter to digital domain -> applying the filter to a vector
I created a 6th order analog butterworth filter with cutoff frequency at 2.841GHz and 2.861GHz. I have a sinusoidal signal at 2851MHz, with the x-axis resoluation at Ts = 1/(100e9). Based on the documentation of filter: https://www.mathworks.com/help/matlab/ref/filter.html#bt_vs4t-1-b, it is a 1D digital filter. Which makes me think I need to convert the analog filter to discrete using c2d. I am confused on what the Ts value for c2d should be. Should it be the resolution value of the input vector? Or it only needs to be 2x the passband frequency? If I use the Ts value of 1/(100e9), my bode result is completely unusable. I read about the article "Using the right model representation" https://www.mathworks.com/help/control/examples/using-the-right-model-representation.html. It shows that by using state-space, my c2d will be more accurate, but I still need to convert to tf for the final filter step, which defeats the purpose of going to ss.
So I have two questions:
  1. Is there an easier way to simulate this?
  2. How to pick a proper Ts value?
Thanks!
fc = 2851.3e6; % resonate freq
fs = 100e9; % x axis resolution
Ts = 1/fs;
t_start = 0; % x axis start time
t_stop = 10e-6; % x axis stop time
t = (t_start):(Ts):(t_stop); % x axis
rf = cos((2*pi*f_c*(t)) + (0));
% External BPF
lp_f = 2.841e9;
hp_f = 2.861e9;
lp_w = 2*pi*lp_f;
hp_w = 2*pi*hp_f;
ext_bpf_bw = [lp_w hp_w];
[ext_bpf_Num, ext_bpf_Den] = butter(6, ext_bpf_bw, 'bandpass','s'); % create a butterworth filter
ext_bpf = tf(ext_bpf_Num, ext_bpf_Den);
opt = c2dOptions('Method','matched','FractDelayApproxOrder', 3);
ext_bpfz = c2d(ext_bpf, (Ts), opt);
figure()
P = bodeoptions('cstprefs');
P.Xlim = [2.7, 3.0];
P.FreqUnits = 'GHz';
P.Title.String = 'Ext RF filter';
P.Grid = 'on';
bodeplot(ext_bpf, ext_bpfz, 'x',P);
ext_bpf_out = filter(ext_bpfz.Num{1}, ext_bpfz.Den{1}, rf);

採用された回答

Star Strider
Star Strider 2019 年 8 月 7 日
I would choose a Nyquist frequency comfortably above your highest passband frequency, so here arbitrarily:
Fn = 3E+9; % Nyquist Frequency
Fs = Fn*2; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
The sampling frequency you chose is likely not appropriate for a discrete filter. Mine is likely more appropriate.
Note however that the sampling interval using my values is , so that is going to strain the limits of floating-point computations. Note also that ‘Fs’ must be the sampling frequency of your signal, and that may strain your ADC.
It is probably better to let the Signal Processing Toolbox do the ‘heavy lifting’ in discrete filter design. (I prefer elliptic filters.) Since you want to design a Butterworth filter, begin with the buttord function, and go from there:
Fn = 3E+9; % Nyquist Frequency
Fs = Fn*2; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
lp_f = 2.841e9/Fn; % Normalised Passband Limit
hp_f = 2.861e9/Fn; % Normalised Passband Limit
Wp = [lp_f hp_f]; % Passband Vector
Ws = Wp.*[.99 1/.99]; % Stopband Vector
Rp = 1; % Passband Ripple (Irrelevant in Butterworth)
Rs = 50; % Stopband Attenuation
[n,Wn] = buttord(Wp,Ws,Rp,Rs); % Order Calculation
[z,p,k] = butter(n,Wn); % Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
See if that does what you want.
  2 件のコメント
Chengcheng Xu
Chengcheng Xu 2019 年 8 月 7 日
Thanks! This seems to be a much better approach. The reason why I chose such high Fn is because I am trying to simulate a real world cavity bandpass filter. With a downmixer, lowpass filter and ADC after it. I was hoping to add in the ADC clock jitter in this model, which is why I wanted to have such high resolution.
With the filter you created, how would you apply it to rf signal I created? Would you use filter()? This is where I am being hang up on. Filter function's description is 1-D digital filtering, but the butter filter you created didn't use the Ts for creating a digital filter. Or can the filter function also just filter continous system as well?
Thanks.
Star Strider
Star Strider 2019 年 8 月 7 日
My pleasure!
‘... the butter filter you created didn't use the Ts for creating a digital filter
Yes, it did. In the Signal Processing Toolbox, discrete filters are the default, and the passbands and stopbands are normalised on the interval [0,1], defined by dividing the frequencies (in units of 1/time unit) by the Nyquist frequency, normalising them to that interval. Specify 's' to create a continuous filter, as you did in your code.
Would you use filter()?
I would use filtfilt(), since it is a phase-neutral filter, and also solves for and uses the appropriate initial conditions.
Or can the filter function also just filter continous system as well?
Simulink can simulate continuous systems and filters (I remember that from using it long ago), however everything in the Signal Processing Toolbox deals with discrete signals. You can design continuous filters with it, however implementing them in hardware (as is absolutely necessary) requires circuit synthesis techniques that I have studied although not used in decades, and of course then actual implementation in hardware. Implementing them as discrete filters is relatively straightforward. If you want to use a continuous filter, a Bessel design (the besself function) is best, since it is inherently phase-neutral (although it is impossible to implement it effectively as a discrete filter).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnalog Filters についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by