필터 지우기
필터 지우기

Why doesn't magnitude plot from simulated output match my transfer function's expected bode plot?

조회 수: 2 (최근 30일)
Hi all,
I have a transfer function. I can create its bode plot. I should be able to reproduce this plot by averaging the frequency-converted time-response from many simulations of the system. However, when I do so, the results don't match up.
My code is given below. I create transfer function object, get its bode plot, and then run simulations with random input data in an attempt to reproduce the bode plot. Any idea why this isn't working?
Thanks!
Code:
sys=tf([.073 0 0 0], [1 357/250 259899/250000 71393/2500000 39993/100000000 1407/500000000 1/100000000]);
% Bode Plot (Magnitude)
figure(1);
bodemag(sys);
axis([.001 10 -140 20])
% Simulation parameters
fs = 100; % Sampling frequency (Hz)
L = fs*1000; % Number of samples
t = 0: 1/fs : 1000-1/fs; % time vector
f = 0 : fs/L : fs/2; % frequency range
avg_out = zeros(L/2+1,1); % intialize avg output
avg_in = zeros(L/2+1,1); % intialize avg input
% Run 1000 simulations and take the average results
for i = 1:100
% Simulation
input = randn(L, 1); % random input
[y,t] = lsim(sys, input, t); % time-response
% Output
Y = abs(fft(y))/L; % FFT and scale
avg_out = avg_out + mag2db(4*Y(1:end/2+1)); % convert to dB, accumulate
end
avg_in = avg_in / i; % compute average input
avg_out = avg_out / i; % compute average output
% Plot avg output
figure(4); semilogx(f,avg_out);
axis([.001 10 -140 20])
title('Average Frequency Response')
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
  댓글 수: 2
Arkadiy Turevskiy
Arkadiy Turevskiy 2014년 3월 21일
Can you explain what you are trying to do, or, to be more precise, why are you doing this? Is this for checking the bode command in MATLAB works correctly, or are you just trying to learn how to compute frequency response using FFTs? Is there any practical purpose for this, or is this a purely academic exercise?
Edward
Edward 2014년 3월 25일
편집: Edward 2014년 3월 25일
This is an exercise in verification. I have noise parameters that I'm modeling with a transfer function that I derived. The bode plot looks correct - but that's not enough. I need to be sure that the generated noise reflects what I intended when I designed my model.

댓글을 달려면 로그인하십시오.

채택된 답변

Arkadiy Turevskiy
Arkadiy Turevskiy 2014년 3월 25일
I don't think you can expect to match bode plot magnitude by taking ffts of random signals like that. Bode plot magnitude represents a gain at a particular frequency if you feed a sine wave in. You are feeding in random signals where nothing is at "steady-state".
  댓글 수: 2
Edward
Edward 2014년 3월 25일
I had thought about this as well - that my input is not what the bode plot uses for input. So perhaps if I plotted average magnitude of sinusoid-response, I might get a better match?
Arkadiy Turevskiy
Arkadiy Turevskiy 2014년 3월 25일
if you feed through a bunch of sine waves at various frequencies, you should be able to match the bode plot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Control System Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by