matlab fft bode
Hi aarr,
see this example: to estimate the PSD using Welch's method (see matlab help).
t=0:0.001::1;
y=sin(2*pi*10*t);
subplot(211);
plot(t,y),grid;
subplot(212);
pwelch
;
------------------------------------------------------------------
example:
Fs=40e3; % sampling frequency
W=[8e3, 12e3]/(Fs/2); % passband spec
[b,a]=butter(4,W,'z'); % design Butterworth
% note the order is 2*4=8
[d,c]=cheby1(4,1,W,'z'); % design Chebyshev
figure(1) % make Bode plots
freqz(b,a,60,Fs) % Butterworth in 60 points
hold on % both in the same diagram
freqz(d,c,60,Fs) % Chebyshev
figure(2) % make pole/zero plot
pzmap(b,a) % for Butterworth
figure(3) % make pole/zero plot
pzmap(d,c) % for Chebyshev
----------------------------------------------------------------
example:
% Generate the sine wave sequence
fs = 8000; T=1/fs; % Sampling rate and sampling period
x = 2*sin(2000*pi*[0:1:50]*T); %Generate the 51 2000-Hz samples
% Apply the FFT algorithm
N = length(x);
index_t=[0:1:N-1];
f = [0:1:50]*8000/N; %Map the frequency bin to the frequency (Hz)
length(f)
xf=abs(fft(x))/N; %Calculate the amplitude spectrum
length(xf)
figure(1)
%Using the Bartlett window
x_b=x.*bartlett(N)'; %Apply the triangular window function
xf_b=abs(fft(x_b))/N; %Calculate the amplitude spectrum
subplot(2,2,1);plot(index_t,x);grid
xlabel('Time index n'); ylabel('x
');
subplot(2,2,3); plot(index_t,x_b);grid
xlabel('Time index n'); ylabel('Triangular windowed x
');
subplot(2,2,2);plot(f,xf);grid;axis([0 8000 0 1]);
xlabel('Frequency (Hz)'); ylabel('Ak (no window)');
subplot(2,2,4); plot(f,xf_b);grid; axis([0 8000 0 1]);
xlabel('Frequency (Hz)'); ylabel('Triangular windowed Ak');
enjoy