![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177029/image.jpeg)
How to Synthesize a Signal with many frequencies ?
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2014-12-6
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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177029/image.jpeg)
You can adapt it if you want of course, like if you want to show more or fewer cycles or whatever.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!