sine wave plot
3,111 次查看(过去 30 天)
显示 更早的评论
Hi,
I am having some trouble plotting a sine wave and i'm not sure where i am going wrong.
i have
t = [0:0.1:2*pi]
a = sin(t);
plot(t,a)
this works by itself, but i want to be able to change the frequency. When i run the same code but make the change
a = sin(2*pi*60*t)
the code returns something bad. What am i doing wrong? How can i generate a sin wave with different frequencies?
6 个评论
Walter Roberson
2021-8-10
In order to solve that, you need some hardware to do analog to digital conversion between your 3V source and MATLAB.
3V is too large for audio work, so you are not going to be able to use microphone inputs to do this. You are going to need hardware such as a National Instruments ADC or at least an arduino (you might need to put in a resistor to lower the voltage range.)
The software programming needed on the MATLAB end depends a lot on which analog to digital convertor you use.
The appropriate analog to digital convertor to use is going to depend in part on what sampling frequency you need to use; you did not define that, so we cannot make any hardware recommendations yet.
Gokul Krishna N
2021-10-13
Just been reading the comments in this question. Hats off to you, sir @Walter Roberson
采纳的回答
Rick Rosson
2012-4-24
Please try:
%%Time specifications:
Fs = 8000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 60; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
figure;
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
HTH.
Rick
2 个评论
Nauman Hafeez
2018-12-28
How to calculate Fs for a particular frequency signal?
I am generating a stimulating signal using matlab for my impedance meter and it gives me different results on different Fs.
更多回答(7 个)
Junyoung Ahn
2020-6-16
clear;
clc;
close;
f=60; %frequency [Hz]
t=(0:1/(f*100):1);
a=1; %amplitude [V]
phi=0; %phase
y=a*sin(2*pi*f*t+phi);
plot(t,y)
xlabel('time(s)')
ylabel('amplitude(V)')
2 个评论
Robert
2017-11-28
aaa,
What goes wrong: by multiplying time vector t by 2*pi*60 your discrete step size becomes 0.1*2*pi*60=37.6991. But you need at least two samples per cycle (2*pi) to depict your sine wave. Otherwise you'll get an alias frequency, and in you special case the alias frequency is infinity as you produce a whole multiple of 2*pi as step size, thus your plot never gets its arse off (roundabout) zero.
Using Rick's code you'll be granted enough samples per period.
Best regs
Robert
0 个评论
shampa das
2020-12-26
编辑:Walter Roberson
2021-1-31
clc; t=0:0.01:1; f=1; x=sin(2*pi*f*t); figure(1); plot(t,x);
fs1=2*f; n=-1:0.1:1; y1=sin(2*pi*n*f/fs1); figure(2); stem(n,y1);
fs2=1.2*f; n=-1:0.1:1; y2=sin(2*pi*n*f/fs2); figure(3); stem(n,y2);
fs3=3*f; n=-1:0.1:1; y3=sin(2*pi*n*f/fs3); figure(4); stem(n,y3); figure (5);
subplot(2,2,1); plot(t,x); subplot(2,2,2); plot(n,y1); subplot(2,2,3); plot(n,y2); subplot(2,2,4); plot(n,y3);
0 个评论
sevde busra bayrak
2020-8-24
sampling_rate = 250;
time = 0:1/sampling_rate:2;
freq = 2;
%general formula : Amplitude*sin(2*pi*freq*time)
figure(1),clf
signal = sin(2*pi*time*freq);
plot(time,signal)
xlabel('time')
title('Sine Wave')
0 个评论
Ranjita
2024-9-30
clc
clear all
fs = 10000;
T=1/fs
f1 = 100;
f2= 50;
L= 10000;
t = (0:L-1)*T;
x1 =sin(2*pi*f1*t)+4*cos(2*pi*f2*t)
figure
subplot(2,2,1)
plot(t,x1)
axis([0 0.1 -1 6]);
title('SS Function');
xlabel('time');
ylabel('magnitude');
%frequency domain conversion and plotting
Y_x1=fftshift(fft(x1));
subplot(2,1,2)
plot (-(fs/2-fs/L)-1:(fs/L):(fs/2-fs/L),abs(Y_x1))
axis([-700 700 0 max(abs(Y_x1))+10000]);
title('Magnitude spectrum of S1 Function');
xlabel('Frequency(Hz)');
ylabel('magnitude');
sgtitle('Frequency Domain Representation of S1 Function');
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!