I have a composition of 4 sinusoidal tones and would like to sample it at 50kHz. Here is my code:{t1=cos(2*pi*(0:.1:6)); t2=cos(2*pi*2*(0:.1:6)); t3=cos(2*pi*3.5*(0:.1:6)); t4=3*cos(2*pi*20*(linspace(2,2.1,length(t3)))); x=t1+t2+t3+t4;} Can anybody tell me how I can do it?Thanks.
MATLAB: Sampling
MATLABurgent
Related Solutions
MATLAB's symbolic toolbox is not perfect (perhaps it is impossible to make a perfect symbolic engine), and every year they make some improvements. This seems one such case. Also, "simplification" is not a well defined idea. The tips section of simplify() documentation mentions: "Simplification of mathematical expression is not a clearly defined subject. There is no universal idea as to which form of an expression is simplest. The form of a mathematical expression that is simplest for one problem might be complicated or even unsuitable for another problem."
Are you using an older release of MATLAB? In R2020b, it is simplified as you described in your comment
syms t1 t2 t3 t4 a1 a2 d3M = [cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), - cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) - sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), 0, a1*cos(t1) + a2*cos(t1)*cos(t2) - a2*sin(t1)*sin(t2)cos(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)) + sin(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)), cos(t4)*(cos(t1)*cos(t2) - sin(t1)*sin(t2)) - sin(t4)*(cos(t1)*sin(t2) + cos(t2)*sin(t1)), 0, a1*sin(t1) + a2*cos(t1)*sin(t2) + a2*cos(t2)*sin(t1) 0, 0, 1, d3 0, 0, 0, 1]; M_simplify = simplify(M)
Result
>> M_simplifyM_simplify =[cos(t1 + t2 + t4), -sin(t1 + t2 + t4), 0, a2*cos(t1 + t2) + a1*cos(t1)][sin(t1 + t2 + t4), cos(t1 + t2 + t4), 0, a2*sin(t1 + t2) + a1*sin(t1)][ 0, 0, 1, d3][ 0, 0, 0, 1]
You may experiment with following option if you are using an older release of MATLAB
M_simplify = simplify(M, 'Seconds', 10); % specify maximum number of seconds MATLAB spent on simplification
Here is the entire functionality in about twenty lines:
Fs = 8000;t = 0.25;N = 1:ceil(t*Fs);% define DTMF:
R = [697,770,852,941]; % Hz, rows
C = [1209,1336,1477]; % Hz, columns
[Ra,Ca] = meshgrid(R,C); % Hz, all
Rb = 2*pi*(Ra(:)/Fs);Cb = 2*pi*(Ca(:)/Fs);T = sin(Rb*N) + sin(Cb*N);% get user input:
J = '123456789*0#'; % subplot is by row
I = input('Enter keys/s [0:9*#]: ','s');assert(all(ismember(I,J)),'An invalid key was entered')% plot and play:
for k = 1:numel(I) X = strfind(J,I(k)); subplot(4,3,X); plot(T(X,:)); xlabel(sprintf('KEY%s',I(k))) sound(T(X,:)); pause(0.5);end
Best Answer