Having trouble filtering with an analog filter in Matlab?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I've been trying to create a phase detector that I will eventually use in a phase-locked loop. The phase detector I am implementing is of a simple type consisting of a multipler and a lowpass filter. This project is being used to simulate an analog phase locked loop.
The trouble I am having is actually filtering the signal through the lowpass filter. I will attach my test code below, but in short, I have created an analog butterworth lowpass filter using Matlab's butter function with a cutoff frequency of 2MHz. I am inputting a sinusoid of two components, one of 1MHz and one of 3MHz. I expect to eliminate the 3MHz component.
I convert the zeros and poles from the butter function to transfer function form using zp2tf, and then use the filter function on these coefficients. However, there are 2 issues with the output signal:
1) I cannot explain the gain of the signal. The butter function returns a gain and that gain is used in the zp2tf function. However, when I divide the filtered output by this gain the resulting amplitudes are nowhere near the original amplitudes.
2) There is simply no output, or the scale is so skewed that there appears to be no output. If I zoom in on the output, I can occasional see some sinusoidal behavior growing as time moves forwards. Its as if gain increases as time increases causing the output to be nonsense. That is my best guess at the issue, although it could be something completely different.
My test code is:
%FILTERING TESTS
%GENERATE SINUSOID
fc = 1E6; %carrier freqyency, to be used in FM demodulator
fs = 100*fc; %fm sample rate, arbitrarily chosen for smoothness.
t = (0:1/fs:0.00001); %length of time to simulate
%create sinusoidal signals
x = sin(2*pi*1E6*t) + 2*sin(2*pi*3E6*t);
%generate butterworth analog lowpass filter
n = 2; %lpf order
cut = 2E6; %cutoff freq
[zeros, poles, gain] = butter(n,2*pi*cut, 's'); %generate LPF zeros, poles, and filter gain.
[b,a] = zp2tf(zeros, poles, gain); %convert to transfer function form of b, a coefficients
figure(1)
freqs(b,a,1000)
%attempt to filter
output = filter(poles,zeros,x);
%correct filter gain
output2 = output/gain;
%plots
figure(2)
plot(x)
figure(3)
plot(output2)
1 Kommentar
KALYAN ACHARJYA
am 3 Jun. 2018
This Question clarification is needed? There is always gain in the signal, whether -, 1 or +.
Antworten (1)
Star Strider
am 3 Jun. 2018
You cannot implement a continuous filter with a discrete signal. A continuous filter will only work if you implement it in hardware.
Discrete filter design begins with a continuous filter design, then transforming it to the discrete domain usually using the bilinear transform (with the bilinear function).
2 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!