Design an Input Signal

17 views (last 30 days)
Heraldo Tello
Heraldo Tello on 8 Dec 2020
Commented: Image Analyst on 9 Dec 2020
Hello everyone,
I am tasked with creating a PRBS signal without using matlab shortcuts. Please see below. Once I create this PRBS signal I will run it through a p-code file and get an output. I am supposed to plot the system input vs time. It should look like the second picture.
Here is the code I have so far. I attempted to create a random signal and then run it through the transfer function.
My code is probably wrong so it is definitly not set in stone.
I do not know how to make the signal look almost digital. The example shows the input signal is either negative 1 or positive 1.
When I ran my code, I got two figures back. Please see below.
Any help or direction is greatly appreciated.
clear all
close all
clc
fs=300; % Sampling Frequency in Hz
t_final=1140; % Overall test duration in seconds
time=0:1/fs:t_final;
time=time';
fc=1000;
Wc=2*pi()*fc;
num=0.27;
den=[1 0.95*Wc 1.4*Wc^2 0.74*Wc^3 0.27*Wc^4];
G = tf(num,den)
x1=rand(length(time),1);
U = lsim(G,x1,time);
[Y]=MysterySystem(time,U);
figure
plot(time,Y,'linewidth',2)
xlabel('Time (seconds)')
ylabel('Output (dimensionless)')
title('Heraldo Tello - Experimental Testing of the Unknown System')
grid on
figure
plot(time,U)

Accepted Answer

Image Analyst
Image Analyst on 8 Dec 2020
You might look at fewer seconds so you can see the signal. Who told you to use that fs, fc, and t_final?
To get values of -1 or +1 only, you can do
signal = 2 * randi([0, 1], 1, numElements) - 1;
  2 Comments
Heraldo Tello
Heraldo Tello on 9 Dec 2020
I had to manipulate the code a bit to make it work for me to this
U = 2*randi([0 1], length(time), 1)-1;
nonetheless, it did work and produced an input signal that closely mimics the example I provided.
Thanks very much. Saved me a ton of time and headache on this problem.
Image Analyst
Image Analyst on 9 Dec 2020
You're welcome. Thanks for Accepting.
time() is a built-in function. Since you're not supposed to use built-in function names as variable names, I suggest you call it times instead of time.

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!