How to Synthesize a Signal with many frequencies ?
21 views (last 30 days)
Show older comments
Hi,
A question says:
Synthesize a sampled signal which consists of 4 sine waves with the following frequencies:
0.08fs, 0.2fs, 0.32fs and 0.4fs
Where fs is the sampling frequency and assume it is normalized to 1. Assume that magnitude of each sine wave is 1.
------- My solutions ------ (not sure about it) plus I kinda ignored the normalization because i do not know how to do it.
Does this do the job?
input = frest.Sinestream('Frequency',[0.08*fs 0.2*fs 0.32*fs 0.4*fs],'Amplitude',1,'FreqUnits', 'Hz');
or this?
x = sin(0.08*fs) + sin(0.2*fs) + sin(0.32*fs) + sin(0.4*fs);
Your help is appreciated
0 Comments
Accepted Answer
Image Analyst
on 6 Dec 2014
I'd use your second one but with slight modifications. The formula for a sine wave is y = sin(2*pi*omega*x) where omega is the frequency. Now let's say that you will have 500 elements, so that you can plot it nicely across your screen. So we have to make an "x" that goes from 0 to some max X value, and has 500 sample points over that range. Then we just plug in that x into your formula (instead of fs, which was your mistake) and plot it:
% Initialization steps
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.
format long g;
format compact;
fontSize = 20;
% Let's print out the periods so we know what to expect.
% The period is just 1 over the frequency.
periods = 1 ./ [.08, .2, .32, .4]
% Let's have the max value of x be large enough to contain 4 cycles of the lowest frequency.
xMax = 4 * periods(1);
% Let's have, say, 500 samples over that range [0, xMax].
x = linspace(0, xMax, 500);
% Now we have x, so compute y using the formula.
y = sin(2*pi*0.08*x) + sin(2*pi*0.2*x) + sin(2*pi*0.32*x) + sin(2*pi*0.4*x);
% Now we're done and we can plot y.
plot(x, y, 'b-', 'LineWidth', 3);
% Fancy up the plot.
grid on;
title('Four Frequencies', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
You can adapt it if you want of course, like if you want to show more or fewer cycles or whatever.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!