Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Plot cosines.
- % Basic parameters for this problem
- f0 = 25;
- fs = 8000;
- dur =1/f0;
- N= [5, 10,15, 20, 25];
- sig= [];
- % Loop through elements of N
- for k=N
- % If k odd, use the first formula. Otherwise use the second.
- if (mod(k,2)==1)
- f_k = k * f0; A_k = 4/(k*pi); P_k = pi/2;
- else
- f_k=0; A_k=0; P_k = 0;
- end
- sig = [sig; sumcos(f_k,A_k,P_k,fs,dur)]; % Make each signal we produce the next row.
- %plot(sig); % I don't use hold on for plotting, because I want to use legend.
- %hold on;
- end
- t=0:1/fs:dur;
- % Now at this point I have a num_signals by length(t) (in this case, 5 x 321) matrix sig.
- % Let's plot and label each row of the matrix, since each row is a signal of interest.
- close all; % Close previously existing plots.
- plot(t, sig(1,:), t, sig(2,:),t, sig(3,:),t, sig(4,:),t, sig(5,:));
- legend('N=5','N=10','N=15','N=20','N=25')
- xlabel('time')
- ylabel('amplitude')
- title('5 different cosines')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement