Blank plot on my computer

8 views (last 30 days)
Mihaela-Roxana
Mihaela-Roxana on 16 May 2024
Commented: Mathieu NOE on 16 May 2024
This is my code and I was wondering why is my figure 6 empty:
https://dontpad.com/labpdsmiki
  3 Comments
Mihaela-Roxana
Mihaela-Roxana on 16 May 2024
Edited: the cyclist on 16 May 2024
Here it is, I read that I am not allowed to post all of the code.
% a)
N = 64;
F1 = 1000;
F2 = 3500;
Fs = 20000;
n = 0:N-1;
x = sin(2*pi*n*F1/Fs) + sin(2*pi*n*F2/Fs);
figure(1), stem(n,x, 'r'), grid, title("Semnal Generat")
M1 = 2 ;
M2 = 4 ;
xd1 =x(1:M1:N); xd2 = x(1:M2:N);
% c)
Nfft = 256
Nfft = 256
X = fft(x,Nfft);
XD1 = fft(xd1,Nfft);
XD2 = fft(xd2,Nfft);
F = -Fs/2: Fs/Nfft :Fs/2-Fs/Nfft; % Frecvente nenormate
f = -1/2: 1/Nfft :1/2-1/Nfft; % Frecvente normate
figure(2), title("FFT Spectre in normed frequencies"), subplot(3,1,1), plot(f,fftshift(abs(X)), "g"), grid
subplot(3,1,2), plot(f/M1,fftshift(abs(XD1)), 'g'), grid
subplot(3,1,3), plot(f/M1,fftshift(abs(XD2)), 'g'), grid
axis([1/(10*10*10) 10 1000 100000])
figure(3),title("FFT Spectre"), subplot(3,1,1), plot(F,fftshift(abs(X)), 'g'), grid
subplot(3,1,2), plot(F/M2,fftshift(abs(XD1)), 'g'), grid
subplot(3,1,3), plot(F/M2,fftshift(abs(XD2)), 'g'), grid
% d)
wt1 = pi/M1;
wt2 = pi/M2;
Ot1 = wt1*Fs;
Ot2 = wt2*Fs;
d = 2*10^3 ;
[n1,Wt1] = buttord(Ot1,Ot1+d,1,30,'s');
[n2,Wt2] = buttord(Ot2,Ot2+d,1,30,'s');
[bs1,as1] = butter(n1,Wt1,'s');
[bs2,as2] = butter(n2,Wt2,'s');
[bd1,ad1]=impinvar(bs1,as1,Fs);
[bd2,ad2]=impinvar(bs2,as2,Fs);
Warning: The output is not correct/robust. Coeffs of B(s)/A(s) are real, but B(z)/A(z) has complex coeffs. Probable cause is rooting of high-order repeated poles in A(s).
B(z) and A(z) have been forced to be real using real(A(z)) and real(B(z)).
w = linspace (10^3, 10^5, 256);
figure(4), freqs(bs1,as1,w), title("IIR low-pass filter for wt = pi/2 "), grid; figure(5), freqs(bs2,as2,w), title("IIR low-pass filter for wt = pi/4 "), grid;
x_filter1 = filter(bd1,ad1,x); x_filter2 = filter(bd2,ad2,x);
% e)
xd3_1 = x_filter1(1:M1:N);
xd3_2 = x_filter1(1:M1:N);
xd4_1 = x_filter2(1:M1:N);
xd4_2 = x_filter2(1:M2:N);
X_filter1 = fft(x_filter1,Nfft);
X_filter2 = fft(x_filter2,Nfft);
XD3_1 = fft(xd3_1,Nfft);
XD3_2 = fft(xd3_2,Nfft);
XD4_1 = fft(xd4_1,Nfft);
XD4_2 = fft(xd4_2,Nfft);
figure(6), subplot(3,1,1), plot(F,fftshift(abs(X_filter1))), grid
subplot(3,1,2), plot(F/M1,fftshift(abs(XD3_1))), grid
subplot(3,1,3), plot(F/M1,fftshift(abs(XD3_2))), grid
figure(7), subplot(3,1,1), plot(F,fftshift(abs(X_filter2))), grid
subplot(3,1,2), plot(F/M2,fftshift(abs(XD4_1))), grid
subplot(3,1,3), plot(F/M2,fftshift(abs(XD4_2))), grid
Mathieu NOE
Mathieu NOE on 16 May 2024
you have a problem with your butterworth filters :
[bd1,ad1]=impinvar(bs1,as1,Fs);
bd1 is only NaN values , so everything you filter with this is going to be NaN and you end up with blank figure
Also , important information : you are designing very high order analog butterworth filters , to then transform them in digital form with impinvar (why not then directly use the digital butter way ?)
second info : you get NaN because your filters are unstable :
It is best not to use the transfer function implementation of discrete (digital) filters,because those are frequently unstable. Use zero-pole-gain and second-order-section implementation instead.
%Example :
fc = 50;
fs = 1e4;
[z,p,k] = butter(6,fc/(fs/2));
[sos1,g1] = zp2sos(z,p,k);
figure(1)
freqz(sos1,2^16,fs)

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!