Advertisement
Stybyk

zaloha

Nov 12th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.65 KB | None | 0 0
  1. data1(1:100) = 0;
  2. data1(101:200) = 1;
  3. function keying(data ,fzero ,fone)
  4. if(fone >fzero)
  5.   fs = 4* fone
  6. else
  7.   fs = 4 * fzero
  8. endif
  9.  
  10. Ts = 1/fs;
  11.  
  12.  
  13. L = size(data,2) - Ts;
  14. t = 0:Ts:L;
  15.  
  16. for i = 1:size(data,2)
  17.  if(data(i) == 0)
  18.   f(i) = fzero;
  19.  
  20.   else
  21.    f(i) = fone;
  22.  
  23.  endif
  24.  endfor
  25.  
  26. signal = sin(2*pi*f.*t);
  27. N = length(signal);
  28.  
  29.  
  30. X_mags = abs(fftshift(fft(signal)));
  31. bin_vals = [0 : N-1];
  32. N_2 = ceil(N/2);
  33. fax_Hz = (bin_vals-N_2)*fs/N;
  34. subplot(2,1,1)
  35. plot(fax_Hz, X_mags)
  36. xlabel('Frequency (Hz)')
  37. ylabel('Magnitude');
  38. title('Double-sided Magnitude spectrum (Hertz)');
  39. axis tight
  40. subplot(2,1,2)
  41. plot(t,signal)
  42. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement