f



MATLAB algorithm to MATLAB function code or C code

hallo firends,
       
       Can any body help me write this below code into MATLAB object oriented code or C code form please?

M=50; % total number of periods. (choose for 1s duration)
f0 = 50; % fundamental AC frequency
T0 = 1/f0; %fundamental AC period
T = M*T0; %Time for M periods (integer M)
N=30; % sample points per period.
dt = T0/N; % Sample at N points per period (integer N > 20)
t = dt*[1:M*N-1]; % Sampling time array
A0=120/2; % amplitude of AC signal. Divide by 2 or maybe sqrt (2) ?
AC=A0*sin(f0*t*2*pi); % create AC signal.
DC0=50; % DC amplitude
DC=DC0*ones(1,length(t)); % create a DC signal that is constant of length t
S=AC+DC; % total signal is AC signal + DC signal
figure(1);
plot(t,S); % plot signal.
xlabel('time');ylabel('Signal');
title('Total Signal');
% filter components
fAC=S-mean(S); % here is the AC component
fDC=mean(S); % here is the DC component

figure(2);
plot(t,fAC,'r',t,fDC,'b'); % plot AC and DC signals
legend('AC','DC');
xlabel('time');ylabel('Signal');
title('Signal with only AC component');

figure(3);
plot(t,fDC,'b'); % plot DC signal
legend('DC');
xlabel('time');ylabel('Signal');
title('Signal with only DC component');

figure(4);
% best to plot in Fourier domain
u=abs(fftshift(fft(S)));
NumPoints=length(t);
freq=(1/dt)*[1:NumPoints]/NumPoints; % create frequency axis
freq=freq-max(freq)/2; % center about 0
plot(freq,u);
xlabel('frequency');ylabel('signal');
title('Fourier transform');

with best regards,
Gopal 
0
Gopal
11/18/2009 7:08:06 AM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
2402 Views

Similar Articles

[PageSpeed] 11

Reply:

Similar Artilces:

converting c++ code to Matlab code using Matlab 9
im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these codes in my project rather than writing them from scratch. is there some way or a chunk of code that might convert C++ code to matlab code or a ".c" file to ".m" file. please if anyone knows do let me know at the earliest.thanks "fatima " <fatima_naseem2002@yahoo.com> wrote in message <i8ugqn$e9p$1@fred.mathworks.com>... > im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these c...

MATLAB code to C code
Hi all I read a similar question posted by someone else but my situation is slightly different. I am porting some MATLAB code to C code. I need to find a way to read jpeg images in C just as imread does in MATLAB. The problem is that I have tried a number of C libraries, but they do not serve my purpose completely. I want to read simple grayscale jpeg images into unsigned interger arrays. Can someone pls shed some light. Thanks Qaseem ...

C code from MATLAB code
Hi I have a complex algorithm that eventually will be encoded in C to run on a DSP or Controller (e.g. Hitachi SH4). The present MATLAB implementation under WINDOWS calls advanced standard MATLAB routines such as fft, matrix factorizations, eigenvalue solvers, fmincon (for nonlinear optimization subject to nonlinear constraints), and some number theoretic functions. I figure that the transcription to an optimized C code requires many months of hard labor. Before I embark on this adventure, I would like to generate from my MATLAB code (as easily as possible, i.e. as automatically as possible) ...

Matlab code to C-code
If I want to generate C-code from m-file not specifically for embedded target, which tool can I use? As of I know emlc converts embedded MATALAB code to C-code. Does the Real-Time Workshop uses emlc? Please any one tell me how can I convert my m-file (not only embedded m-file) to C- code. Hi Naveen, i don't think you can do this. if you could, TMW would be giving away the store! you can, however, use the MATLAB Compiler to generate a DLL that you can call from C. MCC will generate a little stub that you call. That stub will call into the MCR (MATLAB Component Runtim...

calling Matlab code from C/C++ code
Hi, I am learning to call Matlab code from C/C++ code. Here are my questions (1)are using Matlab engine and converting Matlab code into a C or C++ shared library the only two ways? (2) what's the difference between these two methods? Advantages and disadvantages? In what case use which method is better? Thanks and regards! On Mon, 03 Aug 2009 10:33:00 -0400, Tim <timlee126@yahoo.com> wrote: > Hi, > I am learning to call Matlab code from C/C++ code. Here are my > questions > > (1)are using Matlab engine and converting Matlab code into a C or C++ > shared library...

M code into programming C code or MATLAB programming code
hallo firends, Can any body help me write this below code into MATLAB object oriented or C code form please? M=50; % total number of periods. (choose for 1s duration) f0 = 50; % fundamental AC frequency T0 = 1/f0; %fundamental AC period T = M*T0; %Time for M periods (integer M) N=30; % sample points per period. dt = T0/N; % Sample at N points per period (integer N > 20) t = dt*[1:M*N-1]; % Sampling time array A0=120/2; % amplitude of AC signal. Divide by 2 or maybe sqrt (2) ? AC=A0*sin(f0*t*2*pi); % create AC signal. DC0=50; % DC amplitude DC=DC0*ones(1,length...

How to transfer matlab codes into visual c++ or c codes?
Hi, Folks I have written some matlab functions (Matlab 6.5), and I want to change them into visual c++ or c codes then create a visual c++ project to use the generated c++ or c codes.(visual c++ 6.0). Could anyone give me the full instructions on how to deal with it because I have met some unresolved external symbol problems when linking (use visual c++ 6.0). Have I missed to include some lib files? Thanks. Hi, Suppose you have an M-file mySquare.m: function y = mySquare(x) y = x*x ; You'll create a dll file by using the command: mcc -t -L C -W lib:mySquarelib -T link:lib mySquare.m...

Call C code from Matlab -> Matlab crash
Hello, I have a problem calling C code from Matlab. The mex file compilation is ok. When I run the program Matlab (7.3) crashes. Below is the mexFunction code. Any idea is welcome. (I think the main part of the code (middle part) is not useful for the crash problem, but I put it anyway). //########################################################### #include "math.h" #include "mex.h" void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Standard variables int p,r,h,i,j,f,w; // Indices for loop int MAX_NBM = 1000; int MAX_DIM = 10; in...

Converting Matlab code to C using Matlab Compiler
Hello All, Please can I get some guidance on how to Convert a structure from Matlab code to C code using Matlab Compiler. Kind regards Sammy ...

Matlab face detection code to c/c++ code
hello guys... I am in urgent need of something which can change my MATLAb code to C or C++ code. I have to run this C, c++ code in Code composer studio and feed the program into DSP emulator EVDM642. Code composer studio does not support MATLAB... So, its important to convert the code into C or C++.. This is my semester project and I have to give the presentation on 18th november...or else I will be failed.. Please help me guys....Tell e something which changes MATLAb to C/C++. Thanx in advance. On 16 Nov., 05:42, "Tarun " <tarunsa...@gmail.com> wrote: > hello guys... >...

EngSim: All Matlab features and functions. 2 to 20 Times Faster than MATLAB. Use the same programming syntax as MATLAB, ANSI C/C++, /C++. Good Graphics.
ENGSIM is an Engineering Simulation & Graphics Library for Microsoft Visual C++. It has all Matlab features and functions. 2 to 20 Times Faster than MATLAB. Very Easy to program. Use the same programming syntax as MATLAB, ANSI C/C++. Graphics Support is Very Good. Support Negative Indexing for Array/Matrix, Complex Array and Complex Matrix. Support Fix-point/Floating-point Communications Engineering and Signal Processing Simulation. Support Statistical Analysis. Support User- Defined Classes. Support User-Graphics Development ...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

Replacing a MATLAB code with a C++ code
I made a program which consists of tens of .m files and I found some parts of this program are making the whole program slow. I want to replace those time-wasting parts with C++ codes. I think C++ codes are a bit faster than MATLAB codes. :) Is this possible? If possible, can anybody teach me how to do this? (Or, If there's other way to improve the speed, please let me know.) Thank you. Kevin. Kevin Kim wrote: > I made a program which consists of tens of .m files and I found some > parts of this program are making the whole program slow. > > I want to replace those time-w...

matlab codes to visual C# code
Hi all, I am just wondering if it is possible to convert a matlab code to C#? ...

c-code to matlab m code
hi am kaushik i would like to know if this code can be directly converted to matlab. if not what can is to be done to run it matlab. ma posting the code here. please reply as soon as possible code here /*program used for acousto ultrasonic signal processing*/ #include<graphics.h> #include<stdio.h> #include<conio.h> main() { int i= 0, x,j, a,b,max1=0,sum1=0,lpeak=0,ccount=0,threshold; int cpeaktime,rabn,cfthtime,cduration,clthtime,crisetime,th1,th2,n1=0,n2=0; float hindex; float cenergy=0,cenergy1; FILE *fp;char dataf1[8]; char wd[8]; int a1,b...

How to convert matlab codes into C codes?
Hi, anyone knows if matlab offers such a function? Thanks. ...

Call C code from Matlab -> Matlab crash #2
Hello, I have a problem calling C code from Matlab. The mex file compilation is ok. When I run the program Matlab (7.3) crashes. Below is the mexFunction code. Any idea is welcome. (I think the main part of the code (middle part) is not useful for the crash problem, but I put it anyway). //########################################################### #include "math.h" #include "mex.h" void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Standard variables int p,r,h,i,j,f,w; // Indices for loop int MAX_NBM = 1000; int MAX_DIM = 10; in...

Matlab code to C code converter
Hi, Is there any method avilable to convert MATLAB code into C code for perticular application of ANN. Regards, Manoj Manoj wrote: > Is there any method avilable to convert MATLAB code into C code for > perticular application of ANN. Yes: use one or more humans to rewrite the code. If you are looking for automated methods, then it depends upon which Matlab version you are using, but chances are that if you are using a Matlab version old enough to be compilable to C then it probably doesn't support the Neural Network toolbox. Are you sure you need to convert...

'Matlab Code' to 'Embedded Matlab fun code'
Dear friends, I have a Matlab code to process a pure analog signal 'u'. Now I want to implement it in Simulink and I want to use it in 'Embedded Matlab fun block' so i need to transform 'Matlab code' to 'Embedded Matlab fun code' to perform the task. The Matlab code is as follows: %%%%%%%%%%%%%%%%%%%%% u_abs = abs(u); major_th = 1.5e-1; minor_th = 1.8e-2; major_peak_value = []; minor_peak_value = []; pos = 1; pos_max = 1; while ~isempty(pos) [m pos_max(end+1)] = max( u_abs( pos : pos + 10) ); pos...

MathWorks Webinar: MATLAB to C Code Generation with Embedded MATLAB
Join Houman Zarrinkoub, PhD on March 11th for two Live Webinar sessions: 9am U.S. EST- http://bit.ly/bxcQuw 2pm U.S. EST- http://bit.ly/9g7Oqe In this webinar we will showcase new capabilities of MathWorks products enabling you to automatically generate C code from MATLAB functions. This capability is available for a subset of MATLAB language called the Embedded MATLAB. This subset consists of over 300 MATLAB operators and functions and more than 110 Fixed-Point Toolbox and 40 Signal Processing Toolbox functions and new system objects from Signal Processing and Video and Image Processin...

converting matlab code to C code
when i tried to convert the matlab code into c code using matlab coder i got below mentioned error, I am using R2011b(7.13.0.534) my program uses image as an input parameter. ERROR: >> coder -build len.prj ??? This text contains non-empty top-level expressions. It appears to be a script. Error in ==> length_of_line Line: 1 Column: 1 Code generation failed: Open error report. CODE: I=imread('pic29rkey.jpg'); imshow(I);pause hold on [x,y] = ginput(2); line(x,y,'color','r','LineWidth',5); Ired_length = sqrt ((x(2)-x(1))^2 + (y(2)-y(1))^2); ...

how to transform this C code to MATLAB code
Hi,Firends A C++ code like this: char evfile[16]; fread(&evfile, sizeof(evfile), 1, fp); fp is a file name; I want to transform it to MATLAB code, what should I do? Thanks for you help! "lee rose" <blusunrui@gmail.com> wrote in message <grnaae$lnn$1@fred.mathworks.com>... > Hi,Firends > > A C++ code like this: > > char evfile[16]; > fread(&evfile, sizeof(evfile), 1, fp); > > fp is a file name; > I want to transform it to MATLAB code, what should I do? > > Thanks for you help! Modern ML has equivalents to fopen, fread ...

How to convert Matlab code into C code
Hi I want to convert my matlab code into C code. Please let me know how to do this? I am also watching for any help manual regarding this. Regards Shailesh Patel ...

how to convert Matlab code to C code
Hi everyone, Can any one tell me how to convert matlab to c?? Regards. On 5/8/2012 4:36 PM, WMS wrote: > Hi everyone, > Can any one tell me how to convert matlab to c?? > > Regards. http://www.mathworks.com/products/matlab-coder/ "MATLAB Coder™ generates standalone C and C++ code from MATLAB code" ...

Web resources about - MATLAB algorithm to MATLAB function code or C code - comp.soft-sys.matlab

Algorithm - Wikipedia
Flow chart of an algorithm (Euclid's algorithm) for calculating the greatest common divisor (g.c.d.) of two numbers a and b in locations named ...

Twitter introducing algorithm-based timeline changes after all
Twitter has announced a change to its timeline that will elevate the &quot;most important&quot; tweets to the top of users' timeline, confirming ...

#RIPTwitter: CEO Dorsey responds after backlash to algorithm reports
Twitter has faced a huge user backlash over suggestions it will rearrange the order of tweets based on importance rather than in a strict chronologically ...

The Top CMOs of 2015, as Chosen by an Algorithm
Who were the best CMOs and marketing executives of 2015? The algorithm says Kelly Bennett of Netflix. Continue reading at AdAge.

Twitter is just mimicking Facebook with its timeline algorithm
... worse, the social media giant seems to forget mypreference for that, defaulting back to their method of showing updates based on some algorithm ...

Smart car algorithm sees pedestrians as well as you can
Filed under: Videos , Safety , Technology , Autonomous , Future UC San Diego researchers have crafted a pedestrian detection algorithm for self-driving ...

What Twitter’s algorithm change means for marketers
... suddenly become ineffective or counterproductive overnight. Why do things turn on a dime in digital marketing? Unlike human-based mental algorithms, ...

Computer Algorithm Predicts Batman V. Superman Only Has 32% Chance Of Being Profitable
Researchers at the University of Iowa have a glum predication for Warner Bros. Using an [...]

Game algorithm could help win elections
There's a particular strain of game theory, Colonel Blotto, that many believe could predict the outcomes of everything from elections to sports ...

Forget The Algorithm! 5 Key Focus Areas For Your Brand's Twitter Program
Yesterday's broadcast of the earnings calllive through Periscopeviewed by many as an upside down broadcastwas an ironic representation of the ...

Resources last updated: 2/18/2016 4:36:16 AM