code correction : subplot in for + length problem
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I was wondering if it was possible to write the code with subplots as I did. The idea of the program is to display a low-pass filter on the same window, with the index response at the top and the frequency response at the bottom. We vary N and display the curves in different colors on the same graph (the same subplot), whether for RF or stem.
Added to this is an error during program execution :
Error using stem (line 43)
X must be same length as Y.
Error in filtrage (line 11)
stem(axe,formula);
But when I test the length with length I get the same size. I'll let you be the judge:
-----------------------------------------------------------------------------------
% Passe-Bas
figure
for N = [10,40,100]
subplot(2,1,1);
axe,formula = passe_bas(N);
stem(axe,formula);
subplot(2,1,2);
RF = abs(freqz(formula));
f = linspace(0,0.5,length(RF));
plot(f,RF);
end
function [axe,formula] = passe_bas(N)
v0 = 0.2;
n=-round(N/2):1:round(N/2);
axe = 0:1:length(n)-1;
formula=2*v0*sinc(2*v0*n);
end
-------------------------------------------------------------------------------------
Thanks for your answers.
0 Commenti
Risposte (1)
Chunru
il 17 Ott 2023
figure
for N = [10,40,100]
subplot(2,1,1);
hold on
[axe,formula] = passe_bas(N);
% brackets above
stem(axe,formula);
subplot(2,1,2);
hold on
RF = abs(freqz(formula));
f = linspace(0,0.5,length(RF));
plot(f,RF);
end
function [axe,formula] = passe_bas(N)
v0 = 0.2;
n=-round(N/2):1:round(N/2);
axe = 0:1:length(n)-1;
formula=2*v0*sinc(2*v0*n);
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Subplots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!