Combining 2 signals into 1

9 ビュー (過去 30 日間)
Dick Rusell
Dick Rusell 2014 年 9 月 20 日
編集済み: Rick Rosson 2014 年 9 月 20 日
I'm trying to combine these signals but I'm not sure how.
n = [0:1023];
omega = 0.25*pi;
xn = sin(omega*n);
ns = sqrt(0.2)*randn(1,n);
  2 件のコメント
Rick Rosson
Rick Rosson 2014 年 9 月 20 日
What specifically do you mean by "combine"?
Dick Rusell
Dick Rusell 2014 年 9 月 20 日
編集済み: Dick Rusell 2014 年 9 月 20 日
Put them on top of each other on the same graph.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2014 年 9 月 20 日
After seeing your clarification, I offer these two possibilities. Perhaps one of them is what you want:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Setup
n = 100;
x=1:n;
omega = 0.25*pi;
xn = sin(omega*x);
ns = sqrt(0.2)*randn(1,n);
% Plot different scenarios, depending on what "combine" means.
% Plot both on same plot
% Plot with common y axis on left side
subplot(2,1,1);
plot(x, ns, 'r-', 'LineWidth', 2);
hold on
plot(x, xn, 'b-', 'LineWidth', 2);
xlabel('x', 'FontSize', fontSize);
ylabel('xn, ns', 'FontSize', fontSize);
title('xn and ns vs. x, one y axis', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Plot each with separate y axis.
subplot(2,1,2);
plot(x, ns, 'r-', 'LineWidth', 2);
hold on
hPlots = plotyy(x, xn, x, ns);
xlabel('x', 'FontSize', fontSize);
ylabel(hPlots(1), 'xn', 'FontSize', fontSize);
ylabel(hPlots(2), 'ns', 'FontSize', fontSize);
title('xn and ns vs. x, separate y axes', 'FontSize', fontSize);
grid on;
If neither of these is what you want, then please clarify again -- there are other possibilities. See MATLAB Gallery for some of them.
  1 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 20 日
"other possibilities" -- such as the way Rick did it, which I just saw and is slightly different than my two ways.

サインインしてコメントする。

その他の回答 (1 件)

Rick Rosson
Rick Rosson 2014 年 9 月 20 日
編集済み: Rick Rosson 2014 年 9 月 20 日
Please try:
plot(n,xn,n,ns);
For more info:
>> doc plot

カテゴリ

Help Center および File ExchangeLog Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by