Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data1(1:100) = 0;
- data1(101:200) = 1;
- function keying(data ,fzero ,fone)
- if(fone >fzero)
- fs = 4* fone
- else
- fs = 4 * fzero
- endif
- Ts = 1/fs;
- L = size(data,2) - Ts;
- t = 0:Ts:L;
- for i = 1:size(data,2)
- if(data(i) == 0)
- f(i) = fzero;
- else
- f(i) = fone;
- endif
- endfor
- signal = sin(2*pi*f.*t);
- N = length(signal);
- X_mags = abs(fftshift(fft(signal)));
- bin_vals = [0 : N-1];
- N_2 = ceil(N/2);
- fax_Hz = (bin_vals-N_2)*fs/N;
- subplot(2,1,1)
- plot(fax_Hz, X_mags)
- xlabel('Frequency (Hz)')
- ylabel('Magnitude');
- title('Double-sided Magnitude spectrum (Hertz)');
- axis tight
- subplot(2,1,2)
- plot(t,signal)
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement