Advertisement
Guest User

NL code

a guest
Oct 26th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.95 KB | None | 0 0
  1. % Plot cosines.
  2.  
  3. % Basic parameters for this problem
  4. f0 = 25;
  5. fs = 8000;
  6. dur =1/f0;
  7. N= [5, 10,15, 20, 25];
  8.  
  9. sig= [];
  10.  
  11. % Loop through elements of N
  12. for k=N
  13.     % If k odd, use the first formula. Otherwise use the second.
  14.     if (mod(k,2)==1)
  15.         f_k = k * f0; A_k = 4/(k*pi); P_k = pi/2;
  16.     else
  17.         f_k=0; A_k=0; P_k = 0;
  18.     end
  19.     sig = [sig; sumcos(f_k,A_k,P_k,fs,dur)]; % Make each signal we produce the next row.
  20.     %plot(sig); % I don't use hold on for plotting, because I want to use legend.
  21.     %hold on;
  22. end
  23.  
  24. t=0:1/fs:dur;
  25.  
  26. % Now at this point I have a num_signals by length(t) (in this case, 5 x 321) matrix sig.
  27. % Let's plot and label each row of the matrix, since each row is a signal of interest.
  28.  
  29. close all; % Close previously existing plots.
  30. plot(t, sig(1,:), t, sig(2,:),t, sig(3,:),t, sig(4,:),t, sig(5,:));
  31. legend('N=5','N=10','N=15','N=20','N=25')
  32.  
  33. xlabel('time')
  34. ylabel('amplitude')
  35. title('5 different cosines')
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement