Advertisement
Stybyk

FSK-prelast

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