How to sweep a sinusoidal signal using the system transfer function?

I have a bandpass filter schematic. I also have the corresponding transfer function.
Is it possible to sweep a sinusoidal signal, say from 0.10 Hz to 100 Hz, using either the schematic or the transfer fucntion, or both?

Answers (1)

I am not certain what you want.
A Bode plot of a filter with those frequency limits is straightforward, with the freqs function (using an example from the documentation):
a = [1 0.4 1];
b = [0.2 0.3 1];
f = logspace(-3, 1, 150); % Define As Hz
w = f*2*pi; % Convert To rad/sec
h = freqs(b,a,w);
mag = abs(h);
phase = angle(h);
phasedeg = phase*180/pi;
figure
subplot(2,1,1)
loglog(w,mag)
grid on
xlabel('Frequency (rad/s)')
ylabel('Magnitude')
subplot(2,1,2)
semilogx(w,phasedeg)
grid on
xlabel('Frequency (rad/s)')
ylabel('Phase (degrees)')
To convert the frequency axis to Hz:
xt = get(subplot(2,1,1), 'XTick');
set(subplot(2,1,1), 'XTick',xt/(2*pi), 'XTickLabel', xt, 'XLim',[0.1 100]/(2*pi)) % Convert Frequency Axis To Hz
set(subplot(2,1,2), 'XTick',xt/(2*pi), 'XTickLabel', xt, 'XLim',[0.1 100]/(2*pi)) % Convert Frequency Axis To Hz
Use freqs for continuous-time filters, and freqz for discrete filters.

4 Comments

I mean that the attenaution bandwidth is 0.20 Hz to 10 Hz.
Here the transfer function.
0.2/(20.2 + 0.07 s^2)^2
I have absolutely no idea what you want to do.
Try this:
s = tf('s');
H = 0.2/(20.2 + 0.07*s^2)^2;
hbp = bodeplot(H);
bpo = getoptions(hbp);
bpo.FreqUnits = 'Hz';
bpo.FreqScale = 'log';
bpo.XLim = [0.2 10];
Alternatively:
w = linspace(0, 50, 500)*2*pi;
[mag,phase,wout] = bode(H,w);
Mag = squeeze(mag);
Phs = squeeze(phase);
figure
subplot(2,1,1)
plot(wout/(2*pi), 20*log10(Mag))
xlim([0.2 10])
grid
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
subplot(2,1,2)
plot(wout/(2*pi), Phs)
xlim([0.2 10])
grid
xlabel('Frequency (Hz)')
ylabel('Phase (°)')
YL = get(gca,'Ylim');
set(gca, 'YTick',[-360 -359])
Make appropriate changes to get the result you want.
Star Strider:
I really appreicate your help. Your are pretty close to what I am looking for as follows.
  1. I have the transfer feuction of a LC passive bandpass filter.
  2. Now, I need the response of the filter with input of a random signal, or noise, or sweeping a sinusoid signal or a chirp signal.
  3. This what I don't know how to do in Matlab.
Thankd a lot
I already did the equivalent of that. I am not certain what you want.
I would just do this:
a = [0.07 0 20.2];
b = 0.2;
freqz(b, a, 2^12, 100)
That is the equivalent of this:
t = linspace(0.0, 1, 2E+2);
L = numel(t);
Ts = t(2)-t(1);
Fs = 1/Ts;
Fn = Fs/2;
in = zeros(size(t));
in(fix(L/2)) = 1;
out = filter(b, a, in);
FTin = fft(in)/L;
FTout = fft(out)/L;
FTtf = FTout./FTin;
ref = max(abs(FTtf));
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
subplot(3,1,1)
plot(Fv, abs(FTin(Iv))*2)
grid
subplot(3,1,2)
plot(Fv, abs(FTout(Iv))*2)
grid
subplot(3,1,3)
plot(Fv, 20*log10(abs(FTtf(Iv))/ref))
grid
and produces the same result. The ‘in’ signal is a single pulse at t=L/2. The last subplot (transfer function) is in dB. The others are linear.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 4 Jan 2020

Commented:

on 10 Jan 2020

Community Treasure Hunt

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

Start Hunting!