Generating signals

27 ビュー (過去 30 日間)
Al
Al 2011 年 9 月 1 日
I have been away from Matlab for awhile and will need to refresh myself. In the mean time I could use a little help getting restarted. I need analyze an output signal that consists of a binary signal that is added to a two tone interference signal.
The binary signal is; +1 for one unit of time starting a zero, -1 for two units of time then +1 for one unit of time, -1 for one unit of time and and finally +1 for one unit of time.
The interference signal is; .7cos(6pit)+.5cos(9pit+pi/4)
How would I go about generating these two signals, then adding them together? Thanks

回答 (3 件)

Arturo Moncada-Torres
Arturo Moncada-Torres 2011 年 9 月 1 日
I assume that your binary signal is periodic (+1, -1, +1, -1, ...). You would have to do something like this:
% Sampling characteristics.
fs = 1000; % [Hz]
Ts = 1/fs; % [s]
t = 0 : Ts : 10-Ts; % Time vector.
% Signals' amplitudes.
a1 = 0.7;
a2 = 0.5;
% Signals' frequencies [rad].
f1 = 6*pi;
f2 = 9*pi;
% Signals' phase [rad].
theta1 = 0;
theta2 = pi/4;
% Create the signals.
signal1 = a1 * cos((f1.* t) + theta1);
signal2 = a2 * cos((f2.* t) + theta2);
signal = signal1 + signal2;
% Create noise.
noise = zeros(1, numel(t));
for ii = 1:numel(noise)
if mod(ii, 2) == 0
noise(ii) = 1;
elseif mod(ii, 2) == 1
noise(ii) = -1;
end
end
% Pollute signal.
signalNoise = signal + noise;
% Plots
figure();
subplot(3,1,1);
plot(t, signal1);
ylim([-1.5 1.5]);
subplot(3,1,2);
plot(t, signal2);
ylim([-1.5 1.5]);
subplot(3,1,3);
plot(t, signal);
ylim([-1.5 1.5]);
figure();
subplot(3,1,1);
plot(t, noise);
ylim([-1.5 1.5]);
subplot(3,1,2);
plot(t, signal);
ylim([-1.5 1.5]);
subplot(3,1,3);
plot(t, signalNoise);
ylim([-1.5 1.5]);
Try it and let me know if it works.

Walter Roberson
Walter Roberson 2011 年 9 月 1 日
resolution = 20;
oneunit = ones(1,resolution);
binarysignal = [oneunit, -oneunit, -oneunit, oneunit, -oneunit, oneunit];
t = ((1 : length(binarysignal)) - 1) ./ resolution;
interference = 0.7*cos(6*pi*t) + 0.5 * cos(9*pi*t + pi/4);
totalsignal = binarysignal + interference;

Al
Al 2011 年 9 月 6 日
Thanks guys for the help, sorry I haven't got back sooner but got buried. I tired both scripts and they worked great. Really appreciate the help.

カテゴリ

Help Center および File ExchangeScopes and Data Logging についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by