0
$\begingroup$

Thanks to previous question, I got some clues to resolve this one. But, I still get some problems here.

Ts = .001;
N = 1000;
t = (0:999)*Ts;
 make_an_array = [2 10 15 20 30 40 50 60 80 90 100 150 200 300 400];
 f = make_an_array;
for i=1:length(t)                              
input(i)=sin(2*pi*f(1)*t(i));     
end  
[b,a] = butter(4,.02,'High');
[b1,a1] = butter(2,0.12);
input = filter(b1,a1,input);
output = filter(b,a,input);
for i=1:length(output)                              
G(i) = 20*log(output/f(1));  
end 
semilogx(f,G,'x')
xlabel('frequency in Hz')
ylabel('Gain dB')
A = max(output);
grid on
disp(A)

This is a brief explaination about what I am trying to find:

1. Amplitude of the output with max operator (variable A)
2. Sine wives using input frequencies in an array (variable f) and use a for-loop (input (i))
3. Plot the 20 log of the output values against the frequency array using the semilogx.
4. I dont know about how to 'store the maximum values of the flter’s output in an array for plotting'. 
5. And then, I got error message "Subscripted assignment dimension mismatch."
6. Part of codes is already on the book:
   [b,a] = butter(4,.02,'High');
   [b1,a1] = butter(2,0.12);
   input = filter(b1,a1,input);
   output = filter(b,a,input);

I think I got wrong on trying to find the value of G, how to operate value with array function (like in input(i) and G(i)).

$\endgroup$

closed as off-topic by Matt L., MBaz, jojek Aug 17 '18 at 22:44

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions requesting working code written to a specification are off-topic as they are unlikely to benefit anyone else. Instead, describe the problem you're solving and where you're stuck." – jojek
  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – Matt L., MBaz
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ It would help if you describe first what you are trying to do. The code seems strange, but it's hard to tell unless you first explain your goal. $\endgroup$ – Hilmar Aug 17 '18 at 13:33
2
$\begingroup$

I really don't like doing someone's homework so I'll drop the loops and make a few other modifications and leave it up to you figure it out.

I don't really understand why you filtered the input but I kept it in:

clc
clear all
close all
%%
Ts = .001;
N = 1000;
t = (0:999)*Ts;
%f = [2 10 15 20 30 40 50 60 80 90 100 150 200 300 400];
% f = make_an_array;
f=logspace(log10(2),log10(400),50);
%%                             
input=exp(1j*2*pi*f'*t);      
[b,a] = butter(4,.02,'High');
[b1,a1] = butter(2,0.12);
input = filter(b1,a1,input);
output = filter(b,a,input);
G=output./input;
figure(1)
semilogx(f,20*log10(max(abs(G'))))
xlabel('frequency in Hz')
ylabel('Gain dB')
%A = max(output);
grid on
%disp(A) 
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.